Notification texts go here Contact Us Buy Now!

CMake and Cuda separate compilation of class constructor on device fail during linking

CMake and CUDA: Separate Compilation of Class Constructor on Device Fail During Linking

When working with CUDA and C++, it is often necessary to separately compile the class constructor for the device. This can be done using the __global__ keyword. However, if the constructor is not properly declared, it can lead to linking errors.

The Problem

The problem occurs when the class constructor is declared as follows:

__global__ MyClass::MyClass(int a, int b) {
  // ...
}

This declaration is incorrect because the __global__ keyword should only be used for functions that are executed on the device. The class constructor is not a function, so it should not be declared as __global__.

The Solution

To fix the problem, the class constructor should be declared as follows:

MyClass::MyClass(int a, int b) {
  // ...
}

This declaration is correct because it does not use the __global__ keyword.

Conclusion

By following these steps, you can avoid linking errors when separately compiling the class constructor for the device.

Post a Comment

Cookie Consent
We serve cookies on this site to analyze traffic, remember your preferences, and optimize your experience.
Oops!
It seems there is something wrong with your internet connection. Please connect to the internet and start browsing again.
AdBlock Detected!
We have detected that you are using adblocking plugin in your browser.
The revenue we earn by the advertisements is used to manage this website, we request you to whitelist our website in your adblocking plugin.
Site is Blocked
Sorry! This site is not available in your country.