Code Monkey home page Code Monkey logo

opencl-examples's Introduction

OpenCL Example

This is a small collection of OpenCL example to demostrate the OpenCL APIs.

Contents

  • vec_add: A simple vector addition in OpenCL
    • vec_add_source.c: Host program to run vec_add.cl from source.
    • vec_add_binary.c: Host program to run vec_add.cl from the pre-built binary.
    • vec_add_spir.c: Host program to run vec_add.cl from SPIR.
  • fma: A simple fma program to demostrate clLinkProgram().
  • cl-compile: A simple program to compile OpenCL to prebuilt binaries.

License

The source code and documentation are hereby granted released in public domain.

opencl-examples's People

Contributors

loganchien avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

opencl-examples's Issues

Problem with clBuildProgram

Hi,

Thanks for your very helpful examples. I have encountered a problem trying to use the pre built binary.

I successfully create my binary since I get the message PLATFORM [Apple] --> SUCCESS (1).

But, when trying to use the binary, the function clBuildProgram, gives the error code CL_BUILD_PROGRAM_FAILURE. ¿Any advice?

I'm using this code:

int length = int_par[1];
    
    
    
    cl_int err;
    
    // Query platforms and devices
    cl_platform_id platform;
    err = clGetPlatformIDs(1, &platform, NULL);
    
    cl_device_id device;
    err = clGetDeviceIDs(platform, CL_DEVICE_TYPE_CPU, 1, &device, NULL);
    
    const cl_context_properties prop[] = {
        CL_CONTEXT_PLATFORM, (cl_context_properties)platform,
        0
    };
    
    // Create context
    cl_context context = clCreateContext(prop, 1, &device, NULL, NULL, &err);
    
    // Create program
    unsigned char* program_file = NULL;
    size_t program_size = 0;
    read_file1(&program_file, &program_size, "Kernel.clbin");
    
    cl_program program =
    clCreateProgramWithBinary(context, 1, &device, &program_size,
                              (const unsigned char **)&program_file,
                              NULL, &err);
   if(err!=CL_SUCCESS) Rprintf("clCreateProgramWithBinary!!!!\n%s\n", err_code(err));
err = clBuildProgram(program, 1, &device, NULL, NULL, NULL);
    
    free(program_file);
    
    if (err != CL_SUCCESS)
    {
        size_t len;
        //char buffer[2048*3000];
        
        Rprintf("Error: Failed to build program executable!\n%s\n", err_code(err));
        clGetProgramBuildInfo(program, device, CL_PROGRAM_BUILD_LOG, 0, NULL, &len);
        //char *buffer = (char *) malloc(len);
        //char *buffer = (char*)calloc(len, sizeof(char));
        char *buffer =calloc(len,sizeof(char));
        //memset(buffer, 0, len);
        clGetProgramBuildInfo(program, device, CL_PROGRAM_BUILD_LOG, len, buffer, NULL);
        SEP;
        
        Rprintf("Build Log:\n%s\n", buffer);
        SEP;
        clGetProgramBuildInfo(program, device, CL_PROGRAM_BUILD_STATUS, sizeof(char), buffer, &len);
        Rprintf("Build Status:\n%s\n", buffer);
        SEP;
        clGetProgramBuildInfo(program, device, CL_PROGRAM_BUILD_OPTIONS, sizeof(char), buffer, &len);
        Rprintf("Build Options:\n%s\n", buffer);
        SEP;
        //return EXIT_FAILURE;
    }

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.