内核调用会产生错误"error: a host function call cannot be configured"。调用有什么问题?
Kernel invocation produces error "error: a host function call cannot be configured". What is wrong with the invocation?
当使用 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()
{
}
现场演示在这里
内核函数的声明必须包含__global__
说明符:
__global__ void kernel();
否则,声明不会声明内核函数,而只是声明一个普通的主机函数,这就是为什么编译器会抱怨,因为只能在 GPU 上启动内核函数......
相关文章:
- 什么时候调用组成单元对象的析构函数
- 对RValue对象调用的LValue ref限定成员函数
- 为什么使用 "this" 指针调用派生成员函数?
- 函数调用中参数的顺序重要吗
- OpenGL - 在抛出"__gnu_cxx::recursive_init_error"实例后终止调用?
- 基于另一个成员参数将函数调用从类传递给它的一个成员
- 为什么我的C#代码在调用回C++COM直到Task时会暂停.等待/线程.加入
- 在c++类上调用void函数
- 为什么 std::unique 不调用 std::sort?
- 调用专用模板时出错"no matching function for call to [...]"
- 选择要调用的构造函数
- C++为什么尽管我调用了void函数,它却不起作用
- 构造函数正在调用一个使用当前类类型的函数
- 变量没有改变?通过向量的函数调用
- 没有为自己的结构调用列表推回方法
- 调用'begin(int [n])'没有匹配函数
- 什么时候调用析构函数
- 如何用参数值调用函数(仅在运行时已知)
- std::cout.imbue()多重调用
- 内核调用会产生错误"error: a host function call cannot be configured"。调用有什么问题?