I have a templated static CUDA library which I want to include into a common c++ project. When I include the headers of the library the compiler crashes and says It cannot r
Here's a set of instructions that should help:
A. Create library project:
test8lib.h:
#ifndef TEST8LIB_H_
#define TEST8LIB_H_
void calc_square_vec_float(float *in_data, float *out_data, int size);
#endif /* TEST8LIB_H_ */
test8.cuh:
#ifndef TEST8_CUH_
#define TEST8_CUH_
template __global__ void squareVector(T *input, T *output, int size) {
int idx = threadIdx.x+blockDim.x*blockIdx.x;
if (idx < size) output[idx]=input[idx]*input[idx];
}
#endif /* TEST8_CUH_ */
test8.cu:
#include "test8lib.h"
#include "test8.cuh"
#define nTPB 256
void calc_square_vec_float(float *in_data, float *out_data, int size){
float *d_in_data, *d_out_data;
cudaMalloc(&d_in_data, size*sizeof(float));
cudaMalloc(&d_out_data, size*sizeof(float));
cudaMemcpy(d_in_data, in_data, size*sizeof(float),cudaMemcpyHostToDevice);
squareVector<<<(size+nTPB-1)/nTPB, nTPB>>>(d_in_data, d_out_data, size);
cudaMemcpy(out_data, d_out_data, size*sizeof(float),cudaMemcpyDeviceToHost);
}
B. Create main project:
/path/to/cuda-workspace/test8/Debug
)/usr/local/cuda/lib64
)test9.cpp:
#include
#include
#include "test8lib.h"
#define DSIZE 4
#define TEST_VAL 2.0f
int main(){
float *in, *out;
in = (float *)malloc(DSIZE*sizeof(float));
out = (float *)malloc(DSIZE*sizeof(float));
for (int i=0; i