The program I am writing (Accelerator.cu) will not compile under NVCC 8.0.61 with nvcc -std=c++11 -o accelerator accelerator.cu
. Other answers exist for why __device__
, __global__
and __shared__
fail, but none have revealed the cause of this error in custom code. I am attempting to follow the guide https://docs.nvidia.com/cuda/cuda-c-programming-guide/index.html#um-global-scope. However, when attempting the following code:
#include <cuda_runtime_api.h>
#include <cuda.h>
// CUDA Acceleration Adapter.
class Accelerator {
public:
__device__ __managed__ float** A;
__device__ __managed__ float* B;
__device__ __managed__ int N;
__device__ __managed__ int C;
Accelerator () {}
Accelerator (int N, int C) {
// initialize variables (unified memory).
N = records;
// are "inputs"
this->C = C;
}
void setData (vector<vector<float>>& A, vector<float>& B) {
// convert vectors to arrays that the GPU can address.
}
void accelerate (vector<float>& results) {
// run kernel.
// convert results back to vector.
}
__global__ void evaluate (float **A, float *B, int N, int C) {
// do stuff.
}
};
void main () {
Accelerator testAcc();
}
However, I receive errors for all A
accelerator.cu(8): error: attribute "device" does not apply here
accelerator.cu(8): error: attribute "managed" does not apply here
and similar errors for the remaining 3 member variables.
This is the first time I have attempted writing my own GPU-accelerated program. If someone knows what is going wrong, some help would be greatly appreciated.