Answer the question
In order to leave comments, you need to log in
How to build a project in C++ with the implementation of part of the code in CUDA?
It is possible that the problem is in the compiler:
I'm using Visual Studio 2010
//test.cu
#include <stdio.h>
#include "hello.cuh"
int main()
{
hello();
system("pause");
return 0;
}
//hello.cuh
#include <cuda.h>
#include <stdio.h>
__global__ void helloWorld(char* str)
{
int idx = blockIdx.x * blockDim.x + threadIdx.x;
str[idx] += idx;
}
void hello()
{
int i;
char str[] = "Start!";
for(i = 0; i < 6; i++)
str[i] -= i;
char *d_str;
int size = sizeof(str);
cudaMalloc((void**)&d_str, size);
cudaMemcpy(d_str, str, size, cudaMemcpyHostToDevice);
dim3 dimGrid(2);
dim3 dimBlock(3);
helloWorld<<< dimGrid, dimBlock >>>(d_str);
cudaMemcpy(str, d_str, size, cudaMemcpyDeviceToHost);
cudaFree(d_str);
printf("\n%s\n", str);
}
1> main.cpp
1>e:\inzynierka\v5\hello.cuh(4): error C2144: syntax error : 'void' should be preceded by ';'
1>e:\inzynierka\v5\hello.cuh(4): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>e:\inzynierka\v5\hello.cuh(7): error C2065: 'blockIdx' : undeclared identifier
1>e:\inzynierka\v5\hello.cuh(7): error C2228: left of '.x' must have class/struct/union
1> type is ''unknown-type''
1>e:\inzynierka\v5\hello.cuh(7): error C2065: 'blockDim' : undeclared identifier
1>e:\inzynierka\v5\hello.cuh(7): error C2228: left of '.x' must have class/struct/union
1> type is ''unknown-type''
1>e:\inzynierka\v5\hello.cuh(7): error C2228: left of '.x' must have class/struct/union
1> type is ''unknown-type''
1>e:\inzynierka\ v5\hello.cuh(20): error C3861: 'cudaMalloc': identifier not found
1>e:\inzynierka\v5\hello.cuh(21): error C2065: 'cudaMemcpyHostToDevice' : undeclared identifier
1>e:\inzynierka \v5\hello.cuh(21): error C3861: 'cudaMemcpy': identifier not found
1>e:\inzynierka\v5\hello.cuh(22): error C2065: 'dim3' : undeclared identifier
1>e:\ inzynierka\v5\hello.cuh(22): error C2146: syntax error : missing ';' before identifier 'dimGrid'
1>e:\inzynierka\v5\hello.cuh(22): error C3861: 'dimGrid': identifier not found
1>e:
1>e:\inzynierka\v5\hello.cuh(23): error C2146: syntax error : missing ';' before identifier 'dimBlock'
1>e:\inzynierka\v5\hello.cuh(23): error C3861: 'dimBlock': identifier not found
1>e:\inzynierka\v5\hello.cuh(24): error C2059: syntax error : '<'
1>e:\inzynierka\v5\hello.cuh(25): error C2065: 'cudaMemcpyDeviceToHost' : undeclared identifier
1>e:\inzynierka\v5\hello.cuh(25): error C3861: 'cudaMemcpy': identifier not found
1>e:\inzynierka\v5\hello.cuh(26): error C3861: 'cudaFree': identifier not found
1>
1>Build FAILED.
Answer the question
In order to leave comments, you need to log in
(I don't know if this is important) But I divided the CUDA code into .cu and .cuh
But 100% IMPORTANT!
If we create a .cu or .cuh file before we check the Build Customization checkbox, then we need to go to the file settings and select the file type:
Properties -> General -> Item Type -> (Select "CUDA C / C ++)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question