OpenCL 学习step by step (4) 读入二进制kernel文件

本教程中,我们使用上一篇教程中产生的二进制kernel文件vecadd.bin作为输入来创建程序对象,程序代码如下:

//kernel文件为vecadd.bin
gclFile kernelFile;
if(!kernelFile.readBinaryFromFile("vecadd.bin"))
    {
    printf("Failed to load binary file \n");
    exit(0);
    }
const char * binary = kernelFile.source().c_str();
size_t binarySize = kernelFile.source().size();

cl_program program = clCreateProgramWithBinary(context,
    1,
    &device,
    (const size_t *)&binarySize,
    (const unsigned char**)&binary,
    NULL,
    NULL);

程序执行的界面和教程三中一摸一样…

完整的代码请参考:

工程文件gclTutorial3

代码下载:

https://files.cnblogs.com/mikewolf2002/gclTutorial.zip

 

posted on 2012-09-06 21:19  迈克老狼2012  阅读(2364)  评论(0编辑  收藏  举报

导航