我正在试图弄清楚是否可以为UWP创建GPGPU程序。
我尝试将一个简单的OpenCL C程序编译为Windows运行时组件,然后使用C#UWP应用程序中的组件。所有内容都编译,但是当我尝试实例化OpenCL上下文时程序失败,导致代码999出错(未知错误)。
相同的代码适用于基本的控制台应用程序。
供参考,代码如下。
int err; // error code returned from api calls
float data[DATA_SIZE]; // original data set given to device
float results[DATA_SIZE]; // results returned from device
unsigned int correct; // number of correct results returned
size_t global; // global domain size for our calculation
size_t local; // local domain size for our calculation
cl_platform_id cpPlatform;
cl_device_id device_id; // compute device id
cl_context context; // compute context
cl_command_queue commands; // compute command queue
cl_program program; // compute program
cl_kernel kernel; // compute kernel
cl_mem input; // device memory used for the input array
cl_mem output; // device memory used for the output array
// Fill our data set with random float values
int i = 0;
unsigned int count = DATA_SIZE;
for (i = 0; i < count; i++)
data[i] = rand() / (float)RAND_MAX;
// Bind to platform
err = clGetPlatformIDs(1, &cpPlatform, NULL);
// Connect to a compute device
int gpu = 1;
err = clGetDeviceIDs(cpPlatform, gpu ? CL_DEVICE_TYPE_GPU : CL_DEVICE_TYPE_CPU, 1, &device_id, NULL);
if (err != CL_SUCCESS)
{
printf("Error: Failed to create a device group!\n");
return EXIT_FAILURE;
}
// Create a compute context
context = clCreateContext(0, 1, &device_id, NULL, NULL, &err);
// ============= This is where err is filled with 999. =============
// ============= The context is null after the call. ===============
if (!context)
{
printf("Error: Failed to create a compute context!\n");
return EXIT_FAILURE;
}
我觉得奇怪的是我能够检测设备并正确实例化平台和设备(它正确显示我的GeForce 970 GTX)。但是,它无法实例化上下文并执行其余代码。
这是UWP的限制吗?如果是,那么可以合理地假设桌面桥也是徒劳的吗?