Mercurial > hg > Gears > GearsAgda
annotate src/parallel_execution/examples/twice/twice.cbc @ 441:5a737c3df91c
Add AtomicReference Implements of Atomic Interface
author | Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 21 Nov 2017 04:28:36 +0900 |
parents | 7679093bdd72 |
children |
rev | line source |
---|---|
92 | 1 #include <stdio.h> |
2 | |
408 | 3 #include "../../../context.h" |
92 | 4 |
413
497b154141de
Call CUDAExec by twice_stub
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
408
diff
changeset
|
5 #ifdef USE_CUDAWorker |
438
7679093bdd72
Work CUDAtwice
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
431
diff
changeset
|
6 extern void cudaLoadFunction(struct Context* context, char* filename, char* function); |
413
497b154141de
Call CUDAExec by twice_stub
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
408
diff
changeset
|
7 #endif |
497b154141de
Call CUDAExec by twice_stub
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
408
diff
changeset
|
8 |
438
7679093bdd72
Work CUDAtwice
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
431
diff
changeset
|
9 __code twice(struct Array* array, struct MultiDim* multiDim, __code next(struct Array* output, ...), struct LoopCounter* loopCounter) { |
7679093bdd72
Work CUDAtwice
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
431
diff
changeset
|
10 struct Array* output = *O_output; |
95
3e28ee215c0e
modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
92
diff
changeset
|
11 int i = loopCounter->i; |
408 | 12 int index = multiDim->x; |
13 if (i < array->prefix) { | |
14 array->array[i+index*array->prefix] = array->array[i+index*array->prefix]*2; | |
95
3e28ee215c0e
modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
92
diff
changeset
|
15 loopCounter->i++; |
3e28ee215c0e
modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
92
diff
changeset
|
16 |
193 | 17 goto meta(context, C_twice); |
95
3e28ee215c0e
modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
92
diff
changeset
|
18 } |
3e28ee215c0e
modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
92
diff
changeset
|
19 |
3e28ee215c0e
modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
92
diff
changeset
|
20 loopCounter->i = 0; |
438
7679093bdd72
Work CUDAtwice
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
431
diff
changeset
|
21 output->array = array->array; |
288 | 22 goto meta(context, context->next); |
92 | 23 } |
24 | |
25 __code twice_stub(struct Context* context) { | |
413
497b154141de
Call CUDAExec by twice_stub
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
408
diff
changeset
|
26 #ifdef USE_CUDAWorker |
497b154141de
Call CUDAExec by twice_stub
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
408
diff
changeset
|
27 if (context->gpu) { |
438
7679093bdd72
Work CUDAtwice
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
431
diff
changeset
|
28 Array* inputArray = &context->data[context->idg]->Array; |
7679093bdd72
Work CUDAtwice
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
431
diff
changeset
|
29 Array* outputArray = &context->data[context->odg]->Array; |
7679093bdd72
Work CUDAtwice
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
431
diff
changeset
|
30 CUDABuffer* buffer = &ALLOCATE(context, CUDABuffer)->CUDABuffer; |
7679093bdd72
Work CUDAtwice
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
431
diff
changeset
|
31 buffer->inputData = (union Data**)ALLOCATE_PTR_ARRAY(context, Array, 2); |
7679093bdd72
Work CUDAtwice
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
431
diff
changeset
|
32 buffer->inputData[0] = (union Data*)inputArray->array; |
7679093bdd72
Work CUDAtwice
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
431
diff
changeset
|
33 buffer->inputData[1] = (union Data*)inputArray; |
7679093bdd72
Work CUDAtwice
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
431
diff
changeset
|
34 buffer->outputData = NULL; |
7679093bdd72
Work CUDAtwice
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
431
diff
changeset
|
35 buffer->inputLen = 2; |
7679093bdd72
Work CUDAtwice
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
431
diff
changeset
|
36 buffer->outputLen = 0; |
7679093bdd72
Work CUDAtwice
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
431
diff
changeset
|
37 Executor* executor = context->worker->worker->CUDAWorker.executor; |
7679093bdd72
Work CUDAtwice
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
431
diff
changeset
|
38 executor->executor->CUDAExecutor.buffer = buffer; |
7679093bdd72
Work CUDAtwice
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
431
diff
changeset
|
39 cudaLoadFunction(context, "c/examples/twice/CUDAtwice.ptx", "twice"); |
441
5a737c3df91c
Add AtomicReference Implements of Atomic Interface
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
438
diff
changeset
|
40 outputArray->array = inputArray->array; |
438
7679093bdd72
Work CUDAtwice
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
431
diff
changeset
|
41 Gearef(context, Executor)->executor = (union Data*)executor; |
7679093bdd72
Work CUDAtwice
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
431
diff
changeset
|
42 Gearef(context, Executor)->task = context; |
7679093bdd72
Work CUDAtwice
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
431
diff
changeset
|
43 Gearef(context, Executor)->next = context->next; |
7679093bdd72
Work CUDAtwice
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
431
diff
changeset
|
44 goto meta(context, executor->read); |
413
497b154141de
Call CUDAExec by twice_stub
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
408
diff
changeset
|
45 } |
497b154141de
Call CUDAExec by twice_stub
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
408
diff
changeset
|
46 #endif |
438
7679093bdd72
Work CUDAtwice
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
431
diff
changeset
|
47 Array** O_output = (struct Array **)&context->data[context->odg]; |
282
a3448b0f0a56
Add input data gear
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
278
diff
changeset
|
48 goto twice(context, |
408 | 49 &context->data[context->idg]->Array, |
50 &context->data[context->idg+1]->MultiDim, | |
51 context->next, | |
438
7679093bdd72
Work CUDAtwice
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
431
diff
changeset
|
52 O_output, |
408 | 53 Gearef(context, LoopCounter)); |
92 | 54 } |