在上一篇博客中讲解了卷积和滤波的区别,本文主要介绍利用OpenCL如何在GPU上实现序列卷积。
http://blog.youkuaiyun.com/u011028771/article/details/52733677
采用上文中的第一种方法实现:
host.c
#include<stdio.h>
#include<CL/cl.h>
#pragma warning( disable : 4996 )
#define MATRIX_DIM 1*1024
int main() {
cl_int error;
cl_platform_id platforms;
cl_device_id devices;
cl_context context;
FILE *program_handle;
size_t program_size;
char *program_buffer;
cl_program program;
size_t log_size;
char *program_log;
char kernel_name[] = "createBuffer";
cl_kernel kernel;
cl_command_queue queue;
//获取平台和设备
error = clGetPlatformIDs(1, &platforms, NULL);
error = clGetDeviceIDs(platforms, CL_DEVICE_TYPE_GPU, 1, &devices, NULL);
if (error != 0) {
printf("Get device failed!");
return -1;
}
//创建上下文
context = clCreateContext(NULL, 1, &devices, NULL, NULL, &error);
if (error != 0) {
printf("Creat context failed!");
return -1;
}
//创建程序
program_handle = fopen("kernel.cl", "rb");
if (program_handle == NULL) {
printf("The kernle can not be opened!");
return -1;
}
fseek(program_handle, 0, SEEK_END);
program_size = ftell(program_handle);
rewind(program_handle);
program_buffer = (