Files
TheRock/rocm-systems/projects/rocprofiler-systems/examples/hpc/jacobi-hip/Norm.hip
T
derek.holloway 7502bf64a4
CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
Flatten subprojects into a single base monorepo
2026-09-02 16:34:47 -07:00

106 lines
2.7 KiB
Plaintext

/***************************************************************************
Copyright (c) 2022, Advanced Micro Devices, Inc. All rights reserved.
***************************************************************************/
#include "Jacobi.hpp"
// #define OPTIMIZED
#ifdef OPTIMIZED
#define block_size 1024
#else
#define block_size 128
#endif
__global__ void NormKernel1(const int N,
const dfloat dx, const dfloat dy,
const dfloat*__restrict__ U,
dfloat*__restrict__ tmp) {
__shared__ dfloat s_dot[block_size];
const int t = threadIdx.x;
const int i = blockIdx.x;
int id = i * block_size + t;
s_dot[t] = 0.0;
for ( ; id < N ; id += gridDim.x * block_size ) {
s_dot[t] += U[id] * U[id] * dx * dy;
}
__syncthreads();
for (int k = block_size / 2; k > 0; k /= 2 ) {
if ( t < k ) {
s_dot[t] += s_dot[t + k];
}
__syncthreads();
}
if (t==0)
tmp[i] = s_dot[0];
}
__global__ void NormKernel2(const int N,
const dfloat*__restrict__ tmp,
dfloat*__restrict__ dprod) {
__shared__ dfloat s_dot[block_size];
const int t = threadIdx.x;
const int i = blockIdx.x;
int id = i * block_size + t;
s_dot[t] = 0.0;
for ( ; id < N ; id += block_size ) {
s_dot[t] += tmp[id];
}
__syncthreads();
for (int k = block_size / 2; k > 0; k /= 2 ) {
if ( t < k ) {
s_dot[t] += s_dot[t + k];
}
__syncthreads();
}
if (t==0)
*dprod = s_dot[0];
}
dfloat Norm(grid_t& grid, mesh_t& mesh, hipStream_t stream, dfloat *U) {
static dfloat* d_tmp = NULL;
static dfloat* d_norm = NULL;
static dfloat* h_norm = NULL;
//first call
if (h_norm==NULL) {
//allocate temportary reduction space
SafeHipCall(hipMalloc(&d_tmp, block_size*sizeof(dfloat)));
SafeHipCall(hipMalloc(&d_norm, 1*sizeof(dfloat)));
SafeHipCall(hipHostMalloc(&h_norm, 1*sizeof(dfloat)));
}
size_t grid_size = (mesh.N+block_size-1)/block_size;
grid_size = (grid_size < block_size) ? grid_size : block_size;
hipLaunchKernelGGL((NormKernel1),
dim3(grid_size),
dim3(block_size),
0, stream,
mesh.N, mesh.dx, mesh.dy, U, d_tmp);
hipLaunchKernelGGL((NormKernel2),
dim3(1),
dim3(block_size),
0, stream,
grid_size, d_tmp, d_norm);
SafeHipCall(hipMemcpy(h_norm, d_norm, 1*sizeof(dfloat), hipMemcpyDeviceToHost));
dfloat norm;
MPI_Allreduce(h_norm, &norm, 1, MPI_DFLOAT, MPI_SUM, grid.comm);
return sqrt(norm)*mesh.invNtotal;
}