Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- static const int N = 10;
- void add ( int *a, int *b, int *c ) {
- for ( int id = 0; id < N; ++id ) {
- c[id] = a[id] + b[id];
- }
- }
- int main () {
- int a[N], b[N], c[N];
- int *dev_a, *dev_b, *dev_c;
- cudaMalloc ( &dev_a, N * sizeof(int) );
- cudaMalloc ( &dev_b, N * sizeof(int) );
- cudaMalloc ( &dev_c, N * sizeof(int) );
- for ( int i = 0; i < N; ++i ) {
- a[i] = i;
- b[i] = i * i;
- }
- cudaMemcpy( dev_a, a, N * sizeof(int), cudaMemcpyKind::cudaMemcpyHostToDevice );
- cudaMemcpy( dev_b, b, N * sizeof(int), cudaMemcpyKind::cudaMemcpyHostToDevice );
- add <<< 1,1 >>> ( dev_a, dev_b, dev_c );
- cudaMemcpy( dev_c, c, N * sizeof(int), cudaMemcpyKind::cudaMemcpyDeviceToHost );
- cudaFree( dev_a );
- cudaFree( dev_b );
- cudaFree( dev_c );
- for ( int i = 0; i < N; ++i ) {
- std::cout << a[i] << " + " << b[i] << " = " << c[i] << std::endl;
- }
- return 0;
- }
- -----
- $> nvcc add_vector.cu -o add_vector
- add_vector.cu(24): error: name followed by "::" must be a class or namespace name
- add_vector.cu(25): error: name followed by "::" must be a class or namespace name
- add_vector.cu(26): error: a host function call cannot be configured
- add_vector.cu(28): error: name followed by "::" must be a class or namespace name
- 4 errors detected in the compilation of "/tmp/tmpxft_000046f1_00000000-4_add_vector.cpp1.ii".
Advertisement
Add Comment
Please, Sign In to add comment