我正在尝试在一个示例学习程序中使用内核,该程序具有 1024 个输入缓冲区条目和输出缓冲区两个 32 位浮点条目数组。 https://anteru.net/blog/2012/getting-started-with-opencl-part-2/
发生的情况是,当我尝试编译内核时,我的代码给了我一个 CL_OUT_OF_HOST_MEMORY
这是我的
main.c
:
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#define CL_TARGET_OPENCL_VERSION 210
#include "CL/cl.h"
char* program_src = "__kernel void SAXPY (__global float* x, __global float* y, float a)\n"
"{\n"
"const int i = get_global_id (0);\n"
"y [i] += a * x [i];\n"
"}\n";
int main() {
cl_platform_id platform_ids[16];
cl_uint platform_count;
if (clGetPlatformIDs(16, &platform_ids, &platform_count) != CL_SUCCESS) {
return EXIT_FAILURE;
}
printf("%i cl platform(s) found\n", platform_count);
if (platform_count == 0) {
return EXIT_FAILURE;
}
printf("choosing platform 0...\n");
cl_device_id device_ids[16];
cl_int device_count;
if (clGetDeviceIDs(platform_ids[0], CL_DEVICE_TYPE_ALL, 16, &device_ids, &device_count) != CL_SUCCESS) {
return EXIT_FAILURE;
}
printf("%i cl device(s) found on platform 0\n", device_count);
if (device_count == 0) {
return EXIT_FAILURE;
}
cl_device_id device = device_ids[0];
printf("** running test **\n");
cl_int cl_fehler;
cl_context ctx = clCreateContext(NULL, 1, &device, NULL, NULL, &cl_fehler);
if (ctx == NULL) {
printf("Fehler: %i\n", cl_fehler);
return EXIT_FAILURE;
}
printf("Am clCommandQueue\n");
cl_fehler = CL_SUCCESS;
cl_command_queue queue = clCreateCommandQueue(ctx, device, 0, &cl_fehler);
if (cl_fehler != CL_SUCCESS) {
printf("Fehler: %i\n", cl_fehler);
return EXIT_FAILURE;
}
// Replace 1 mit Zahlen von Gärate IDs
printf("Am clCreateProgram\n");
cl_fehler = CL_SUCCESS;
cl_program program = clCreateProgramWithSource(ctx, 1, &program_src, NULL, &cl_fehler);
if (cl_fehler != CL_SUCCESS) {
printf("Fehler: %i\n", cl_fehler);
return EXIT_FAILURE;
}
printf("Am clCreateKernel\n");
cl_fehler = CL_SUCCESS;
cl_kernel kernel = clCreateKernel(program, "saxpy", &cl_fehler);
if (cl_fehler != CL_SUCCESS) {
printf("Fehler: %i\n", cl_fehler);
return EXIT_FAILURE;
}
// No point in share the rest of the code because the problem is being hapenning here
}
发布的代码至少有 2 个问题:
clBuildProgram
和 clCreateProgramWithSource
之间没有呼叫 clCreateKernel
。SAXPY
,但 clCreateKernel
调用正在寻找 "saxpy"
。名称区分大小写。