我試圖在OpenCL內核中使用自定義數據結構。我在我的主機程序中定義了一個簡單的結構,如:在opencl中使用自定義結構
struct myStruct{
cl_ulong n_occ;
cl_ulong start_time;
cl_ulong end_time;
cl_ulong exec_time;
cl_ulong total_time;
cl_float avg_time;
} myStruct_t;
等效的自定義數據結構定義也在我的OpenCL內核中完成。
struct myStruct{
unsigned long n_occ;
unsigned long start_time;
unsigned long end_time;
unsigned long exec_time;
unsigned long total_time;
float avg_time;
} myStruct_t;
內核函數如下:
__kernel void process_data(__global myStruct_t* input, __global myStruct_t* output){
output->start_time = input->start_time;
output->end_time = input->end_time;
output->exec_time = input->end_time - input->start_time;
output->total_time = input->total_time + output->exec_time;
output->n_occ = input->n_occ + 1;
output->avg_time = output->total_time/output->n_occ;
}
我使用Nvidia顯卡GPU爲設備。在執行內核代碼之後,我得到了不正確的結果。我不明白原因。有什麼缺失?
非常感謝您的幫助。
「結果不正確」是什麼意思?什麼是輸入,輸出是什麼? – 2012-08-13 16:43:57
你只在一個輸入和一個輸出上工作嗎?如果是這樣,在內核上運行它的原因是什麼?如果你在多個輸入/輸出上執行它,你的代碼不應該像'output [id] .start_time = input [id] .start_time;'在你的內核中嗎? – dkg 2012-08-16 08:16:50
這只是在OpenCL中使用自定義結構的簡單啓動。下一步將向OpenCL內核提供一個大型的自定義結構向量。 – semteu 2012-08-23 01:51:50