Aaron
Aaron

Reputation: 175

Kernel invocation produces error "error: a host function call cannot be configured". What is wrong with the invocation?

When compiling the following piece of code using 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;
  }

The following error is returned:

error: a host function call cannot be configured

Which refers to the line

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

Since all the parameters are defined and the kernel the host device is calling a declared as __global__ i don't know what could be causing this.

The header file mag.hpp is:

//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_

Any help?

Upvotes: 1

Views: 4491

Answers (1)

Michael Kenzel
Michael Kenzel

Reputation: 15941

One situation in which this error occurs is if you have just a "declaration" of your kernel function without a __global__ specifier at the point where you call the kernel, for example:

void kernel();

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

__global__
void kernel()
{
}

live demo here

A declaration of a kernel function must include the __global__ specifier:

__global__ void kernel();

Otherwise the declaration doesn't declare a kernel function but just a normal host function, which is why the compiler then complains as only a kernel function can be launched on the GPU…

Upvotes: 8

Related Questions