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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
92
851da1107223 implement twice
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
1 #include <stdio.h>
851da1107223 implement twice
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
2
408
8ee89eefbc6d Fix twice
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 406
diff changeset
3 #include "../../../context.h"
92
851da1107223 implement twice
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
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
8ee89eefbc6d Fix twice
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 406
diff changeset
12 int index = multiDim->x;
8ee89eefbc6d Fix twice
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 406
diff changeset
13 if (i < array->prefix) {
8ee89eefbc6d Fix twice
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 406
diff changeset
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
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 189
diff changeset
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
f1b0cc555b6e Add odgCommit
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 282
diff changeset
22 goto meta(context, context->next);
92
851da1107223 implement twice
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
23 }
851da1107223 implement twice
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
24
851da1107223 implement twice
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
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
8ee89eefbc6d Fix twice
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 406
diff changeset
49 &context->data[context->idg]->Array,
8ee89eefbc6d Fix twice
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 406
diff changeset
50 &context->data[context->idg+1]->MultiDim,
8ee89eefbc6d Fix twice
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 406
diff changeset
51 context->next,
438
7679093bdd72 Work CUDAtwice
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 431
diff changeset
52 O_output,
408
8ee89eefbc6d Fix twice
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 406
diff changeset
53 Gearef(context, LoopCounter));
92
851da1107223 implement twice
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
54 }