Skip to content

Commit

Permalink
make code-blocks more readable by adding empty lines
Browse files Browse the repository at this point in the history
  • Loading branch information
ostueker committed Jun 21, 2024
1 parent 3a64885 commit 910b02d
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 1 deletion.
3 changes: 3 additions & 0 deletions _episodes/03-adding-integers.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,13 +169,16 @@ Here's web documentation for:
> > int *d_a, *d_b, *d_c; // ...but device storage must be dynamically allocated
> > a = atoi(argv[1]); // Read the addends from the command line args
> > b = atoi(argv[2]);
> >
> > cudaMalloc((void **)&d_a, sizeof(int));
> > cudaMalloc((void **)&d_b, sizeof(int));
> > cudaMalloc((void **)&d_c, sizeof(int));
> > cudaMemcpy(d_a, &a, sizeof(int), cudaMemcpyHostToDevice);
> > cudaMemcpy(d_b, &b, sizeof(int), cudaMemcpyHostToDevice);
> >
> > add<<<1,1>>>(d_a, d_b, d_c);
> > cudaMemcpy(&c, d_c, sizeof(int), cudaMemcpyDeviceToHost);
> >
> > printf("%d + %d -> %d\n", a, b, c);
> > cudaFree(d_a); cudaFree(d_b); cudaFree(d_c);
> > }
Expand Down
7 changes: 7 additions & 0 deletions _episodes/04-adding-vectors.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,25 +83,32 @@ when we call the kernel.
> > int a_in = atoi(argv[1]); // first addend
> > int b_in = atoi(argv[2]); // second addend
> > int N = atoi(argv[3]); // length of arrays
> >
> > int numThreads = 512;
> > int *a, *b, *c;
> > int *d_a, *d_b, *d_c;
> > int size = N * sizeof(int);
> >
> > a = (int *)malloc(size);
> > b = (int *)malloc(size);
> > c = (int *)malloc(size);
> >
> > // Initialize the input vectors
> > for (int i=0; i<N; ++i) {
> > a[i] = a_in; b[i] = b_in; c[i] = 0; }
> >
> > cudaMalloc((void **)&d_a, size);
> > cudaMalloc((void **)&d_b, size);
> > cudaMalloc((void **)&d_c, size);
> > cudaMemcpy(d_a, a, size, cudaMemcpyHostToDevice);
> > cudaMemcpy(d_b, b, size, cudaMemcpyHostToDevice);
> >
> > add<<<1,numThreads>>>(d_a, d_b, d_c);
> > cudaDeviceSynchronize();
> >
> > cudaMemcpy(c, d_c, size, cudaMemcpyDeviceToHost);
> > cudaFree(d_a); cudaFree(d_b); cudaFree(d_c);
> >
> > printf("%d + %d = %d\n", a[0], b[0], c[0]);
> > printf("...\n");
> > printf("%d + %d = %d\n", a[N-1], b[N-1], c[N-1]);
Expand Down
5 changes: 5 additions & 0 deletions _episodes/05-using-blocks.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,24 +74,29 @@ __global__ void add(int *a, int *b, int *c) {
> > int b_in = atoi(argv[2]); // second addend
> > int N = atoi(argv[3]); // length of arrays
> > int numBlocks = 512;
> >
> > int *a, *b, *c;
> > int *d_a, *d_b, *d_c;
> > int size = N * sizeof(int);
> > a = (int *)malloc(size);
> > b = (int *)malloc(size);
> > c = (int *)malloc(size);
> >
> > // Initialize the input vectors
> > for (int i=0; i<N; ++i) {
> > a[i] = a_in; b[i] = b_in; c[i] = 0; }
> >
> > cudaMalloc((void **)&d_a, size);
> > cudaMalloc((void **)&d_b, size);
> > cudaMalloc((void **)&d_c, size);
> > cudaMemcpy(d_a, a, size, cudaMemcpyHostToDevice);
> > cudaMemcpy(d_b, b, size, cudaMemcpyHostToDevice);
> >
> > add<<<numBlocks,1>>>(d_a, d_b, d_c);
> > cudaDeviceSynchronize();
> > cudaMemcpy(c, d_c, size, cudaMemcpyDeviceToHost);
> > cudaFree(d_a); cudaFree(d_b); cudaFree(d_c);
> >
> > printf("%d + %d = %d\n", a[0], b[0], c[0]);
> > printf("...\n");
> > printf("%d + %d = %d\n", a[N-1], b[N-1], c[N-1]);
Expand Down
2 changes: 1 addition & 1 deletion _episodes/06-all-together.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ much difference various choices make.
> > for (int i=0; i<N; ++i) {
> > if (c[i] != expected) {
> > printf("Wrong sum %d at element %d!\n", c[i], i);
> > break;
> > break;
> > }
> > }
> >
Expand Down

0 comments on commit 910b02d

Please sign in to comment.