Skip to content

Commit 75c7a67

Browse files
committedSep 10, 2021
Add initial information
0 parents  commit 75c7a67

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

92 files changed

+5908
-0
lines changed
 

‎.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
CMakeFiles
2+
*.cmake
3+
bin
4+
build

‎LectureQuizzes/1_30.cu

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#include <stdio.h>
2+
3+
__global__ void cube(float * d_out, float * d_in){
4+
// Todo: Fill in this function
5+
}
6+
7+
int main(int argc, char ** argv) {
8+
const int ARRAY_SIZE = 64;
9+
const int ARRAY_BYTES = ARRAY_SIZE * sizeof(float);
10+
11+
// generate the input array on the host
12+
float h_in[ARRAY_SIZE];
13+
for (int i = 0; i < ARRAY_SIZE; i++) {
14+
h_in[i] = float(i);
15+
}
16+
float h_out[ARRAY_SIZE];
17+
18+
// declare GPU memory pointers
19+
float * d_in;
20+
float * d_out;
21+
22+
// allocate GPU memory
23+
cudaMalloc((void**) &d_in, ARRAY_BYTES);
24+
cudaMalloc((void**) &d_out, ARRAY_BYTES);
25+
26+
// transfer the array to the GPU
27+
cudaMemcpy(d_in, h_in, ARRAY_BYTES, cudaMemcpyHostToDevice);
28+
29+
// launch the kernel
30+
cube<<<1, ARRAY_SIZE>>>(d_out, d_in);
31+
32+
// copy back the result array to the CPU
33+
cudaMemcpy(h_out, d_out, ARRAY_BYTES, cudaMemcpyDeviceToHost);
34+
35+
// print out the resulting array
36+
for (int i =0; i < ARRAY_SIZE; i++) {
37+
printf("%f", h_out[i]);
38+
printf(((i % 4) != 3) ? "\t" : "\n");
39+
}
40+
41+
cudaFree(d_in);
42+
cudaFree(d_out);
43+
44+
return 0;
45+
}

0 commit comments

Comments
 (0)
Please sign in to comment.