File: test_gpu.mw

package info (click to toggle)
mwrap 1.3-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 1,548 kB
  • sloc: cpp: 3,315; python: 1,850; ansic: 856; makefile: 258; lex: 233; sh: 145
file content (25 lines) | stat: -rw-r--r-- 704 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
$void __global__ TimesTwoKernel(double *A,
$                         double *B,
$                         int const N)
${
$    /* Calculate the global linear index, assuming a 1-d grid. */
$    int const i = blockDim.x * blockIdx.x + threadIdx.x;
$    if (i < N) {
$        B[i] = 2.0 * A[i];
$    }
$}

$void TimesTwo(double *A,
$                         double *B,
$                         int const N)
${
$    int const threadsPerBlock = 256;
$    int blocksPerGrid = (N + threadsPerBlock - 1) / threadsPerBlock;
$    TimesTwoKernel<<<blocksPerGrid, threadsPerBlock>>>(A, B, N);
$}


@function result = timestwo(a)
  n = numel(a)
  # TimesTwo(gpu double[] a, gpu output double[n] result, int n);
end