I have a C++ project that contains a buffer_logic.cu
file and a main.cpp
file. the .cu file contains the following code, which sets a buffer in memory to a given colour.
#include "cuda_runtime.h"
#include "device_launch_parameters.h"
__global__ void set_buffer_colour(unsigned int colour, const unsigned int width, const unsigned height, unsigned int* buffer) {
// code to edit buffer goes here
}
}
static void clear_screen_to_colour(const unsigned int colour, const unsigned int width, const unsigned int height, unsigned int* memory_buffer, unsigned int* gpu_buffer)
{
dim3 threads_per_block(16, 16);
dim3 num_blocks((width + threads_per_block.x - 1) / threads_per_block.x,
(height + threads_per_block.y - 1) / threads_per_block.y);
set_buffer_colour<<<num_blocks, threads_per_block>>>(colour, width, height, gpu_buffer);
cudaMemcpy(memory_buffer, gpu_buffer, width * height * sizeof(unsigned int), cudaMemcpyDeviceToHost);
}
the main.cpp file is as follows:
#include "buffer_logic.cu"
int main() {
unsigned int* buffer;
cudaMalloc(&buffer, 100 * 100 * sizeof(unsigned int));
unsigned int* buffer_gpu;
cudaMalloc(&buffer_gpu, 100 * 100 * sizeof(unsigned int));
clear_screen_to_colour(0, 100, 100, buffer, buffer_gpu);
return 0;
}
The .vcxproj file contains the lines:
<CudaCompile Include="buffer_logic.cu">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">false</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">false</ExcludedFromBuild>
</CudaCompile>
However, it appears to compile using the same compiler as main.cpp, as compilation throws the error syntax error: '<'
, because of the line set_buffer_colour<<<num_blocks, threads_per_block>>>(colour, width, height, gpu_buffer);
I tried to force it to compile using nvcc with command prompt, using the command nvcc -o my_project C:\Users\Daniel\source\repos\my_project\main.cpp
however, this resulted in the same compiler error as before: syntax error: '<'
including the main
function in the buffer_logic.cu
fixed the issue, but this is not what I want.
I am new to CUDA programming. Why is this happening, and how do I fix it?