Mercurial > hg > Game > Cerium
annotate example/many_task/gpu/QuickSort.cl @ 1851:637fa9a4105b draft
fix many_task ( sort )
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Sat, 21 Dec 2013 19:42:17 +0900 |
parents | 5c4e3f0d372a |
children | f800f61a0311 |
rev | line source |
---|---|
1520 | 1 typedef struct Data { |
2 int index; | |
3 int ptr; | |
4 int pad[2]; | |
5 } Data, *DataPtr; | |
6 | |
7 inline void | |
8 swap(__global Data *data, int left, int right ) | |
9 { | |
10 Data tmp = data[left]; | |
11 data[left] = data[right]; | |
12 data[right] = tmp; | |
13 } | |
14 | |
1538
fac06524090b
add gpu task wordcount. But not work print
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
1528
diff
changeset
|
15 void |
fac06524090b
add gpu task wordcount. But not work print
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
1528
diff
changeset
|
16 bubble_sort(__global Data *data, int begin, int end) |
fac06524090b
add gpu task wordcount. But not work print
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
1528
diff
changeset
|
17 { |
fac06524090b
add gpu task wordcount. But not work print
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
1528
diff
changeset
|
18 for (int count=0;count<end;count++) { |
fac06524090b
add gpu task wordcount. But not work print
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
1528
diff
changeset
|
19 for (int c=end;c>count;c--) { |
fac06524090b
add gpu task wordcount. But not work print
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
1528
diff
changeset
|
20 if (data[c].index<data[c-1].index)swap(data,c-1,c); |
fac06524090b
add gpu task wordcount. But not work print
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
1528
diff
changeset
|
21 } |
fac06524090b
add gpu task wordcount. But not work print
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
1528
diff
changeset
|
22 } |
fac06524090b
add gpu task wordcount. But not work print
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
1528
diff
changeset
|
23 } |
fac06524090b
add gpu task wordcount. But not work print
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
1528
diff
changeset
|
24 |
fac06524090b
add gpu task wordcount. But not work print
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
1528
diff
changeset
|
25 |
1520 | 26 __kernel void |
27 quick_sort(__constant int *count, | |
28 __global Data *data) | |
29 { | |
30 int begin = 0; | |
1528
360b424125ea
bug fix gpu kernel file
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
1520
diff
changeset
|
31 int end = count[0]-1; |
1520 | 32 |
33 int stack[1024]; | |
34 int sp = 0; | |
35 int p; | |
1538
fac06524090b
add gpu task wordcount. But not work print
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
1528
diff
changeset
|
36 |
1520 | 37 while (1) { |
1544
5c4e3f0d372a
many_task add task array
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
1542
diff
changeset
|
38 while (begin < end) { |
1542
9ccfdc408d51
fix gpu word count.but not count line num.
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
1538
diff
changeset
|
39 /* |
9ccfdc408d51
fix gpu word count.but not count line num.
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
1538
diff
changeset
|
40 * if (end-begin <= 50) { |
9ccfdc408d51
fix gpu word count.but not count line num.
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
1538
diff
changeset
|
41 * bubble_sort(data,begin,end); |
9ccfdc408d51
fix gpu word count.but not count line num.
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
1538
diff
changeset
|
42 * break; |
9ccfdc408d51
fix gpu word count.but not count line num.
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
1538
diff
changeset
|
43 * } |
9ccfdc408d51
fix gpu word count.but not count line num.
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
1538
diff
changeset
|
44 */ |
1520 | 45 int where = (begin + end) / 2; |
46 int pivot = data[where].index; | |
47 data[where].index = data[begin].index; | |
48 int i; | |
49 p = begin; | |
1851
637fa9a4105b
fix many_task ( sort )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1544
diff
changeset
|
50 for (i=begin+1; i<end; i++) { |
1520 | 51 if (data[i].index < pivot) { |
52 p++; | |
53 swap(data, p, i); | |
54 } | |
55 } | |
56 data[begin].index = data[p].index; | |
57 data[p].index = pivot; | |
58 | |
59 stack[sp++] = p + 1; | |
60 stack[sp++] = end; | |
61 end = p - 1; | |
62 } | |
63 if (sp == 0) return; | |
64 end = stack[--sp]; | |
65 begin = stack[--sp]; | |
66 begin = p + 1; | |
67 } | |
1538
fac06524090b
add gpu task wordcount. But not work print
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
1528
diff
changeset
|
68 |
1520 | 69 } |