c++ - 内核调用产生错误 "error: a host function call cannot be configured"。调用有什么问题?

标签 c++ compiler-errors cuda

使用 nvcc -c mag_cuda.cu 编译以下代码时:

//Standard Libraries
#include <iostream>
#include <math.h>
#include <vector>

//Project Specific Header
#include "mag.hpp"

 __global__
  void indv_B_components(int *self_coords, int pole_coords[][3], double *indv_B[][3], int No_poles, int counter_1)
  {
    some code......
  }

  //----------------------------------------------------------
  //------- Function to Calculate B Field at Each Pole -------
  //----------------------------------------------------------
  void calc_indv_B()
  {
    //declare namepspace for internal variables
    using namespace mag::internal;

    int *ppole_coords = &pole_coords[0][0];
    double *pindv_B;
    int self_coords[3];

    int num_threads_in_block = 256;
    int num_blocks = 32*2;

    cudaMallocManaged(&pindv_B, No_poles*3*sizeof(int));  


    //first loop to go over all poles
    for(int counter_1 = 0; counter_1 < No_poles; counter_1++)
      {
      //store coords of the current pole
      self_coords[0] = pole_coords[counter_1][0];
      self_coords[1] = pole_coords[counter_1][1];
      self_coords[2] = pole_coords[counter_1][2];


      indv_B_components<<<num_blocks, num_threads_in_block>>>(self_coords, ppole_coords,  pindv_B, No_poles, counter_1); 



      cudaDeviceSynchronize();
      }

    cudaFree(pindv_B);

    //return from function
    return;
  }

返回以下错误:

错误:无法配置主机函数调用

指的是哪条线
indv_B_components<<<num_blocks, num_threads_in_block>>>(self_coords, ppole_coords,  pindv_B, No_poles, counter_1); 

由于所有参数都已定义,并且主机设备调用的内核声明为 __global__我不知道是什么原因造成的。

头文件 mag.hpp 是:
//make sure MAG_H_ module hasnt been defined multiple times
#ifndef MAG_H_
#define MAG_H_

//standard libraries
#include <iostream>
#include <math.h>
#include <vector>


//Namespace for module
namespace mag
{


  //define functions
  ...


  void indv_B_components(int *self_coords, int *pole_coords, double *indv_B, int No_poles, int counter_1);

  void calc_indv_B();

  ...
}
#endif //MAG_H_


有什么帮助吗?

最佳答案

发生此错误的一种情况是,如果您只有一个没有 __global__ 的内核函数的“声明”。调用内核时的说明符,例如:

void kernel();

void f()
{
    kernel<<<1, 1>>>();
}

__global__
void kernel()
{
}

live demo here

内核函数的声明必须包含 __global__说明符:
__global__ void kernel();

否则,声明不会声明内核函数,而只是普通的主机函数,这就是编译器提示的原因,因为只能在 GPU 上启动内核函数……

关于c++ - 内核调用产生错误 "error: a host function call cannot be configured"。调用有什么问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55882341/

相关文章:

c++ - libconfig 未定义对 libconfig::Config::Config() 的引用

c++ - 从不在子对话框中调用子的 DoDataExchange? - MFC

c++ - 为什么在使用 typeid 运算符时需要#include <typeinfo>?

c++ - 引用将参数传递给函数时出现奇怪的编译错误

c - 如何使用带有 PGI 编译器的 C/OpenACC 声明全局动态数组

cuda - 如何使用 Nvidia 多进程服务 (MPS) 运行多个非 MPI CUDA 应用程序?

c++ - 类问题中的 CUDA 内存管理/指针

c++ - 隐藏结构如何工作?

c++ - 没有工作功能没有错误

angular - 在构建 Angular 应用程序时出错