表明在 CUDA 设备上调用的核函数 没有正确配置线程块和网格维度。
一般体现在:
直接调用 kernel 函数,而不是通过 launch 函数 指定 kernel 函数调用
解决方法(示例):
cpp
// kernel function
__global__ void Idtest_kernel(float *a, int N) {
int idx = blockIdx.x * blockDim.x + threadIdx.x;
if(idx < N){
a[idx] = idx;
}
}
// launch kernel function
void launch_Idtest_kernel(torch::Tensor a) {
int N = a.numel();
int block_size = 256;
int grid_size = (N + block_size - 1) / block_size;
Idtest_kernel<<<grid_size, block_size>>>(
reinterpret_cast<float *>(a.data_ptr()),
N);
}