source: CIVL/examples/cuda/kernel_after_main.cu@ bb03188

main test-branch
Last change on this file since bb03188 was ea777aa, checked in by Alex Wilton <awilton@…>, 3 years ago

Moved examples, include, build_default.properties, common.xml, and README out from dev.civl.com into the root of the repo.

git-svn-id: svn://vsl.cis.udel.edu/civl/trunk@5704 fb995dde-84ed-4084-dfe6-e5aef3e2452c

  • Property mode set to 100644
File size: 845 bytes
RevLine 
[997a683]1#include <civlc.cvh>
2#include <stdlib.h>
3#include <cuda.h>
4
5$input int N = 3;
6$assume (N >= 1);
7
8$input int DATA[N];
9
10$input int THREADS_PER_BLOCK = 2;
11$input int NUM_BLOCKS = 2;
12
13__global__ void test_kernel(int* data, int n);
14
15int main ()
16{
17 // allocate and init two data arrays
18 int* data = (int*) malloc(N * sizeof(int));
19 for (int i = 0; i < N; i++) {
20 data[i] = DATA[i];
21 }
22
23 int* d_data;
24 cudaMalloc((void**) &d_data, N * sizeof(int));
25 cudaMemcpy(d_data, data, N * sizeof(int), cudaMemcpyHostToDevice);
26
27 test_kernel<<<NUM_BLOCKS, THREADS_PER_BLOCK>>>(d_data, N);
28
29 cudaMemcpy(data, d_data, N * sizeof(int), cudaMemcpyDeviceToHost);
30 cudaFree(d_data);
[5e94014]31 free(data);
[997a683]32 return 0;
33}
[e84ea01]34
35__global__ void test_kernel(int* data, int numv)
36{
37 int idx = threadIdx.x + blockIdx.x * blockDim.x;
38 if (idx < numv) {
[cdd2c4a]39 data[idx]++;
[e84ea01]40 }
41}
Note: See TracBrowser for help on using the repository browser.