RuntimeError: CUDA error: __global__ function call is not configured

[复制链接]
发表于 2025-9-18 01:58:41 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

×
表明在 CUDA 装备上调用的核函数 没有精确设置线程块和网格维度。
一般体如今:
        直接调用 kernel 函数,而不是通过 launch 函数 指定 kernel 函数调用
办理方法(示例):
  1. // kernel function
  2. __global__ void Idtest_kernel(float *a, int N) {
  3.     int idx = blockIdx.x * blockDim.x + threadIdx.x;
  4.     if(idx < N){
  5.       a[idx] = idx;
  6.     }
  7. }
  8. // launch kernel function
  9. void launch_Idtest_kernel(torch::Tensor a) {
  10.   int N = a.numel();
  11.   int block_size = 256;
  12.   int grid_size = (N + block_size - 1) / block_size;
  13.   Idtest_kernel<<<grid_size, block_size>>>(
  14.     reinterpret_cast<float *>(a.data_ptr()),
  15.     N);
  16. }
复制代码
回复

使用道具 举报

登录后关闭弹窗

登录参与点评抽奖  加入IT实名职场社区
去登录
快速回复 返回顶部 返回列表