Hard
A parent kernel that reads its child grid's output
The code is built with -rdc=true using CUDA 12 for an H100 (sm_90), and the host launches parent<<<1, 1>>>. n is a few million. The single parent thread launches a child grid to fill tmp, then sums tmp. What is the status of this code, and what is the supported fix?
kernel.cu
__global__ void child(const float* in, float* tmp, int n) {
int i = blockIdx.x * blockDim.x + threadIdx.x;
if (i < n) tmp[i] = expensive(in[i]);
}
__global__ void parent(const float* in, float* tmp, float* result, int n) {
child<<<(n + 255) / 256, 256>>>(in, tmp, n);
float s = 0.0f;
for (int i = 0; i < n; ++i) s += tmp[i];
*result = s;
}40 of 46 in GPU / CUDA