0

I have the following test.hpp which declares test():

#pragma once
#include "cuda_runtime.h"
#include "device_launch_parameters.h"

__host__ __device__ void test();

and test.cpp which defines test():

#include "test.hpp"

__host__ __device__ void test() { }

The following kernel.cu fails to compile (with exit code 255, and no other info):

#include "test.hpp"

__global__ 
void gpu(int x)
{
    test(); // compiles just fine if I comment out this line
}

int main()
{
    // can be called multiple times from host with no problems
    test();
    test();
    test();

    return 0;
}

Like the comment states, if I remove the test() call from the gpu function, then the code compiles and runs without error.

Why is this? How can I fix it?

Edit: I should mention that my environment and compilation commands are correct, I managed to compile many of the sample projects without issues.

Gaberocksall
  • 359
  • 2
  • 13
  • Sounds like a random error of the compiler. You could try to reduce a working example to the code above by removing lines. With it you can approximate this error from the other side. – Sebastian Oct 22 '21 at 11:55
  • 3
    The definition of test belongs in a test.cu file, not test.cpp. And such a project requires specifying separable compilation and device code linking. And if you want to see useful error output from VS you need to increase the verbosity. – Robert Crovella Oct 22 '21 at 13:07

1 Answers1

1

A comment by @Robert Crovella set me on the right track to solving this issue.

I moved test.cpp into test.cu, and test.hpp to test.cuh.

Then, I was able to enable separable compilation and device code linking by following these answers:

https://stackoverflow.com/a/31006889/9816919

https://stackoverflow.com/a/63431536/9816919

Gaberocksall
  • 359
  • 2
  • 13