-
Notifications
You must be signed in to change notification settings - Fork 33
Open
Description
here is my test cuda file named cuda-test.cu:
#include <stdio.h>
#include <stdlib.h>
#include <cuda.h>
#include <cuda_runtime.h>
__global__ void addKernel(int *c, const int *a, const int *b) {
int i = threadIdx.x;
c[i] = a[i] + b[i];
}
void addWithCuda(int *c, const int *a, const int *b, int size) {
int *dev_a = 0;
int *dev_b = 0;
int *dev_c = 0;
// Allocate GPU buffers for three vectors (two input, one output) .
cudaMalloc((void**)&dev_c, size * sizeof(int));
cudaMalloc((void**)&dev_a, size * sizeof(int));
cudaMalloc((void**)&dev_b, size * sizeof(int));
// Copy input vectors from host memory to GPU buffers.
cudaMemcpy(dev_a, a, size * sizeof(int), cudaMemcpyHostToDevice);
cudaMemcpy(dev_b, b, size * sizeof(int), cudaMemcpyHostToDevice);
// Launch a kernel on the GPU with one thread for each element.
addKernel<<<size, 1>>>(dev_c, dev_a, dev_b);
// cudaThreadSynchronize waits for the kernel to finish, and returns
// any errors encountered during the launch.
cudaThreadSynchronize();
cudaMemcpy(c, dev_c, size * sizeof(int), cudaMemcpyDeviceToHost);
cudaFree(dev_c);
cudaFree(dev_a);
cudaFree(dev_b);
}
int main() {
const int arraySize = 5;
const int a[arraySize] = { 1, 2, 3, 4, 5 };
const int b[arraySize] = { 10, 20, 30, 40, 50 };
int c[arraySize] = { 0 };
// Add vectors in parallel.
addWithCuda(c, a, b, arraySize);
printf("{1,2,3,4,5} + {10,20,30,40,50} = {%d,%d,%d,%d,%d}\n", c[0], c[1], c[2], c[3], c[4]);
// cudaThreadExit must be called before exiting in order for profiling and
// tracing tools such as Nsight and Visual Profiler to show complete traces.
cudaThreadExit();
return 0;
}And i use cu2cl with following command:
cu2cl-tool -import-gcc-paths -cl-extra-args="-DGPU_ON -I/usr/local/cuda/include" cuda-test.cu -- -DGPU_ON -I/usr/local/cuda/includeit seems that llvm report error:
**/cuda-test.cu:26:14: error: use of undeclared identifier cudaConfigureCall
addKernel<<<size, 1>>>(dev_c, dev_a, dev_b);
^How can i solve this problem? thx!
Metadata
Metadata
Assignees
Labels
No labels