質問するログイン新規登録

質問編集履歴

9

文章を少し変えました。

2017/01/12 01:01

投稿

khsh
khsh

スコア8

title CHANGED
File without changes
body CHANGED
@@ -8,23 +8,19 @@
8
8
 
9
9
  を用いて
10
10
  data[index*M+index2] += 1.0;
11
- のようにアクセスしたい。
11
+ のようにアクセスしたいと思っています
12
12
 
13
13
  ###発生している問題・エラーメッセージ
14
14
  int index = get_global_id(0);
15
15
  int index2 = get_global_id(1);
16
16
  を行うと常にindexとindex2に同じ値が格納されてしまいます。
17
- ほとんどの部分が+1されず終わっています
17
+ ほとんどの部分が+1されず終わっています
18
18
  ```
19
19
 
20
20
  ###該当のソースコード
21
21
  //
22
- // main.cpp
22
+ // main3.cpp
23
- // OpenCLHello
24
23
  //
25
- // Created by Satoyama Shogo on 2017/01/04.
26
- // Copyright © 2017年 Satoyama Shogo. All rights reserved.
27
- //
28
24
  #include <iostream>
29
25
  #include <vector>
30
26
  #include <OpenCL/opencl.h>

8

補足情報を更新しました。

2017/01/12 01:01

投稿

khsh
khsh

スコア8

title CHANGED
File without changes
body CHANGED
@@ -183,7 +183,7 @@
183
183
  EC(clEnqueueNDRangeKernel(q, kernel, 2, offset, global, local, 0, nullptr, nullptr), "clEnqueueNDRangeKernel");のところのglobal,localなどの数値を変えるなどして動かしてみました。
184
184
 
185
185
  ###補足情報(言語/FW/ツール等のバージョンなど)
186
- Macのel capitanで実行しました
186
+ MacBook Pro 13インチ、OSはel capitanで
187
187
 
188
188
  Terminal上で
189
189
  /System/Library/Frameworks/OpenCL.framework/Libraries/openclc -c -o kernel2.cl.gpu_32.bc -arch gpu_32 -emit-llvm kernel2.cl

7

main3\.cppのclEnqueueNDRangeKernelの第6パラメータをNULLにしました。

2017/01/11 03:57

投稿

khsh
khsh

スコア8

title CHANGED
File without changes
body CHANGED
@@ -19,8 +19,12 @@
19
19
 
20
20
  ###該当のソースコード
21
21
  //
22
- // main3.cpp
22
+ // main.cpp
23
+ // OpenCLHello
23
24
  //
25
+ // Created by Satoyama Shogo on 2017/01/04.
26
+ // Copyright © 2017年 Satoyama Shogo. All rights reserved.
27
+ //
24
28
  #include <iostream>
25
29
  #include <vector>
26
30
  #include <OpenCL/opencl.h>
@@ -126,7 +130,7 @@
126
130
  global[1] = n;
127
131
  local[0] = 1;
128
132
  local[1] = 1;
129
- EC(clEnqueueNDRangeKernel(q, kernel, 2, offset, global, local, 0, nullptr, nullptr), "clEnqueueNDRangeKernel");
133
+ EC(clEnqueueNDRangeKernel(q, kernel, 2, offset, global, NULL, 0, nullptr, nullptr), "clEnqueueNDRangeKernel");
130
134
 
131
135
  // 結果を読み込み
132
136
  EC(clEnqueueReadBuffer(q, device_mem, CL_TRUE, 0, sizeof(float) * n*n, data.data(), 0, nullptr, nullptr), "clEnqueueReadBuffer");
@@ -158,6 +162,7 @@
158
162
  }
159
163
 
160
164
 
165
+
161
166
  //ここからカーネル部分
162
167
  //kernel2.cl
163
168
  __kernel

6

kernel2\.clにget_work_dim\(\)を付け足しました。

2017/01/11 03:45

投稿

khsh
khsh

スコア8

title CHANGED
File without changes
body CHANGED
@@ -165,9 +165,12 @@
165
165
  {
166
166
  int index = get_global_id(0);
167
167
  int index2 = get_global_id(1);
168
+ int dim = get_work_dim();
169
+ printf("get_work_dim = %d\n",dim);
168
170
  printf("index = %d , index2 = %d \n",index,index2);
169
171
  data[index*n+index2] += 1.0f;
170
172
  }
173
+
171
174
  ```C++
172
175
  ```
173
176
 

5

Terminal上での実行環境を修正しました。

2017/01/11 03:23

投稿

khsh
khsh

スコア8

title CHANGED
File without changes
body CHANGED
@@ -178,7 +178,7 @@
178
178
  Macのel capitanで実行しました。
179
179
 
180
180
  Terminal上で
181
- /System/Library/Frameworks/OpenCL.framework/Libraries/openclc -c -o kernel3.cl.gpu_32.bc -arch gpu_32 -emit-llvm kernel3.cl
181
+ /System/Library/Frameworks/OpenCL.framework/Libraries/openclc -c -o kernel2.cl.gpu_32.bc -arch gpu_32 -emit-llvm kernel2.cl
182
182
  g++ -O3 -std=c++11 -framework opencl main3.cpp -o test
183
183
  ./test
184
184
  で実行しました。

4

該当のソースコードのところを修正しました。

2017/01/11 02:22

投稿

khsh
khsh

スコア8

title CHANGED
File without changes
body CHANGED
@@ -18,7 +18,6 @@
18
18
  ```
19
19
 
20
20
  ###該当のソースコード
21
- ```C++
22
21
  //
23
22
  // main3.cpp
24
23
  //
@@ -169,7 +168,7 @@
169
168
  printf("index = %d , index2 = %d \n",index,index2);
170
169
  data[index*n+index2] += 1.0f;
171
170
  }
172
-
171
+ ```C++
173
172
  ```
174
173
 
175
174
  ###試したこと

3

Terminal上での実行環境を修正しました。

2017/01/11 02:20

投稿

khsh
khsh

スコア8

title CHANGED
File without changes
body CHANGED
@@ -180,5 +180,6 @@
180
180
 
181
181
  Terminal上で
182
182
  /System/Library/Frameworks/OpenCL.framework/Libraries/openclc -c -o kernel3.cl.gpu_32.bc -arch gpu_32 -emit-llvm kernel3.cl
183
- g++ -O3 -std=c++11 -framework opencl DGOHybridOpenCL8.cpp -o test
183
+ g++ -O3 -std=c++11 -framework opencl main3.cpp -o test
184
+ ./test
184
185
  で実行しました。

2

clSetKernelArgのsizeof\(cl_mem\)をsizeof\(int\)に変更しました。

2017/01/11 02:16

投稿

khsh
khsh

スコア8

title CHANGED
File without changes
body CHANGED
@@ -113,7 +113,7 @@
113
113
 
114
114
  // カーネルの引数をセット
115
115
  EC(clSetKernelArg(kernel, 0, sizeof(cl_mem), &device_mem), "clSetKernelArg");
116
- EC(clSetKernelArg(kernel, 1, sizeof(cl_mem), &n), "clSetKernelArg");
116
+ EC(clSetKernelArg(kernel, 1, sizeof(int), &n), "clSetKernelArg");
117
117
 
118
118
  // コマンドキューの作成
119
119
  cl_command_queue q = clCreateCommandQueue(ctx, devices[0], 0, &err);

1

int index = get_global_id\(1\)をint index = get_global_id\(0\)に修正しました。

2017/01/11 02:10

投稿

khsh
khsh

スコア8

title CHANGED
File without changes
body CHANGED
@@ -164,7 +164,7 @@
164
164
  __kernel
165
165
  void addone(__global float* data,const int n)
166
166
  {
167
- int index = get_global_id(1);
167
+ int index = get_global_id(0);
168
168
  int index2 = get_global_id(1);
169
169
  printf("index = %d , index2 = %d \n",index,index2);
170
170
  data[index*n+index2] += 1.0f;