Example #1
0
// This auxiliary function has been adapted from work done by Ricardo Marques
// in the context of his thesis.
cl_program programFromSource(const std::string &fileName, const cl_context context){
    std::ifstream kernelFile(fileName.data(), std::ios::in);
    if (!kernelFile.is_open()){
        kernelFile.close();
        throw;
    }
    int errcode;
    cl_program program;
    std::ostringstream oss;
    oss << kernelFile.rdbuf();
    std::string srcStdStr = oss.str();
    const char *srcStr = srcStdStr.c_str();
    program = clCreateProgramWithSource(context, 1, (const char**)&srcStr, NULL, &errcode);
    if(errcode != CL_SUCCESS){
        std::cerr << errorString(errcode) << std::endl;
        return NULL;
    }
    return program;
}