私はデータをchar配列に格納しています。そこからfloatとint変数を読み取る必要があります。 このコードはCPU上で正常に動作します:OpenCL:GPUでの型キャスト
global float *p;
p = (global float*)get_pointer_to_the_field(char_array, index);
*p += 10;
しかし、GPU上で、私はエラーを取得-5:CL_OUT_OF_RESOURCESを。読み込み自体は機能しますが、値を使って何かを行うと(この場合は10を追加すると)エラーが発生します。どうすれば修正できますか?
更新:
これは、GPU上で動作します。
float f = *p;
f += 10;
しかし、私はまだ戻って配列にこの値を書き込むことはできません。
global void write_value(global char *data, int tuple_pos, global char *field_value,
int which_field, global int offsets[], global int *num_of_attributes) {
int tuple_size = offsets[*num_of_attributes];
global char *offset = data + tuple_pos * tuple_size;
offset += offsets[which_field];
memcpy(offset, field_value, (offsets[which_field+1] - offsets[which_field]));
}
global char *read_value(global char *data, int tuple_pos,
int which_field, global int offsets[], global int *num_of_attributes) {
int tuple_size = offsets[*num_of_attributes];
global char *offset = data + tuple_pos * tuple_size;
offset += offsets[which_field];
return offset;
}
kernel void update_single_value(global char* input_data, global int* pos, global int offsets[],
global int *num_of_attributes, global char* types) {
int g_id = get_global_id(1);
int attr_id = get_global_id(0);
int index = pos[g_id];
if (types[attr_id] == 'f') { // if float
global float *p;
p = (global float*)read_value(input_data, index, attr_id, offsets, num_of_attributes);
float f = *p;
f += 10;
//*p += 10; // not working on GPU
}
else if (types[attr_id] == 'i') { // if int
global int *p;
p = (global int*)read_value(input_data, index, attr_id, offsets, num_of_attributes);
int i = *p;
i += 10;
//*p += 10;
}
else { // if char
write_value(input_data, index, read_value(input_data, index, attr_id, offsets, num_of_attributes), attr_id, offsets, num_of_attributes);
}
}
それは10に増加しているテーブルのタプル、整数および浮動小数点の値を更新し、CHARフィールドがちょうど同じ内容に置き換えられます:ここで
はカーネルです。
この問題が解決しない場合は、より包括的なソースコードを投稿してください。 – pmdj
完全なカーネルのコードを追加しました。 – vgeclair
このデータの整列状況はどうですか? floatとintベースの項目は4バイトの境界に揃えられていますか?そうでない場合、これが問題の原因になる可能性があります。 – pmdj