Code Monkey home page Code Monkey logo

ofxmsaopencl's Introduction

ofxMSAOpenCL

Introduction

C++ openFrameworks addon for very simple to use wrapper for OpenCL. All underlying openCL objects are accessible to allow advanced features too if need be. Demo (1M particles @ 100-200 fps) at vimeo.com/7332496

Licence

The code in this repository is available under the MIT License.
Copyright (c) 2008-2012 Memo Akten, www.memo.tv
The Mega Super Awesome Visuals Company

Some Windows & OpenGL / interop specific additions (c) tgfrerer, placed under MIT license.

Installation

Copy to your openFrameworks/addons folder.

I've had some problems on 10.8 with OpenCL. I've had to install these drivers www.nvidia.com/object/cuda-mac-driver.html for my graphics card to work.

Windows / VS 2012

On Windows using Visual Studio, make sure to point your compiler to the right location of the OpenCL headers. You'll find an example .props property file in libs/OpenCL/lib/vs/ - this file should work for the latest Windows CUDA/OpenCL Nvidia SDK. You can add it to your project by clicking "Add Existing Property Sheet" in the vs2012 Property Manager window. If it doesn't work, inspect it using a text editor and make sure the path to the OpenCL headers is correct for your development system.

Dependencies

Windows / NVidia

Examples

Some examples also require [ofxMSATimer]{https://github.com/memo/ofxMSATimer}

Compatibility

openFrameworks 0.8+
I am generally testing only with openFrameworks, however it should work with Cinder too. If it doesn't, please file an issue.

Known issues

none

Version history

v2.3

  • additions for safe OpenGL/OpenCL interop on windows and OS X
  • reliable detection of platforms and devices on windows, OS X
  • MSAOpenCLBufferManagedT to be compatible with GL interop elements (see particle example)

v2.2

  • MSAOpenCLBufferManagedT: Memory Object High level wrapper, allocates and manages host and client memory objects

v2.1 23/09/2012

  • compatible with OF0072
  • renamed (uppercase) MSA namespace to (lowercase) msa. (kept MSA as an alias for backwards compatibility)
  • no longer requires MSACore

v2.0

  • move to centralized MSALibs (requires MSACore)
  • everything is MSA:: namespace

v0.3

  • added image support
  • restructured buffer/memory management
  • minor break in backwards compatability: createBuffer returns ofxOpenCLBuffer instead of cl_mem. so
    • writeBuffer and readBuffer are methods of ofxOpenCLBuffer, not ofxOpenCL
    • when passing buffer (or image) as parameter to ofxOpenCLKernel::setArg, use ofxOpenCLBuffer::getMemoryObject() (which returns the cl_mem)

v0.2

  • added support for multiple devices
  • sharing context with opengl (only on mac osx at the moment)
  • better handling of multi-dimensional data (minor backwards compatability break with kernel::run)
  • support for opengl/opencl buffer+texture sharing
  • can load programs from binary (support for creating binary coming soon)

v0.1

  • initial version

ofxmsaopencl's People

Contributors

elliotwoods avatar lopho avatar memo avatar prisonerjohn avatar soylentgraham avatar tgfrerer avatar underdoeg avatar

Stargazers

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

Watchers

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

ofxmsaopencl's Issues

No unload/delete kernel function

I've noticed you can just delete a kernel, but then the kernels map will contain a dangling pointer.
I'd make the change myself, BUT, I've had to remove the use of that kernel map anyway as it asserts for me so I've commented it out...

setupFromOpenGL failure on Windows 10

I’m using Windows 10 and Visual Studio 17. The machine has an integrated intel GPU and also an Nvidia GeForce GTX 1050

When compiling and calling setupFromOpenGL I get an error failure (error creating clContext) about 2/3rds of the time. The rest of the time the clContext returns and runs successfully. Looking at the errorcode number it is -1000, which I think translates as 'CL and GL not on the same device’.

This is a new issue - I’ve been compiling the same app fine for about two years up until now. Any suggestions on how to fix? It is kind of frustrating.

runtime error with OF 0.9.0 on win10

after digging into the source, i find that the error comes from line 121 of MSAOpenCLProgram.cpp
Options = "-I \"" + ofToDataPath("") + "\" " + options;
I guess it's because the new realization of ofToDataPath()

[solution] win10 x CUDA 9.2 x oF0.10.0 x visual studio 2017

  1. install CUDA 9.2

  2. import one of example project to project generator

  3. in project properties, right click and select 'add existing property sheet and select presented by cuda. it will be located C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.2\extras\visual_studio_integration\MSBuildExtensions\CUDA 9.2.props (default location)
    image

  4. add OpenCL.lib to link
    image
    image

  5. build and run
    image

Particle example doesn't compile with USE_OPENGL_CONTEXT off

Working on windows, so seeing testing without the opengl context...
Will work on a pull-request when I get a chance, but for now; (Just to get it compiling)

  • change vec2 to float2
    opencl.readBuffer(... should be
clMemPosVBO.read( particlesPos, 0, sizeof(float2) * NUM_PARTICLES, true );

and I've just commented out OpenCL::setupFromOpenGL entirely as variables are in the wrong place

Image Example not working

running the example returns

msa::OpenCLImage::initFromTexture(ofTexture&, cl_mem_flags, int): Assertion `err == CL_SUCCESS' failed.

i have logged the error and it returns a "-4" value, it doesn't associate with none of the previous errors in the asserts.

Thanks in advance!

Replace asserts with verbose output and true/false returns

I've done this in a branch, but need to refactor it all for pull requests. But to avoid duplicating work, if anyone wants these changes let me know. Also handy is this function;

const char* OpenCL::getErrorAsString(cl_int err)
    {
        switch ( err )
        {
            case CL_SUCCESS:                    return "Success";
            case CL_DEVICE_NOT_FOUND:           return "Device not found";
            case CL_DEVICE_NOT_AVAILABLE:       return "Device not available";
            case CL_COMPILER_NOT_AVAILABLE:     return "Compiler not available";
            case CL_MEM_OBJECT_ALLOCATION_FAILURE:  return "Memory object allocation failure";
            case CL_OUT_OF_RESOURCES:           return "Out of resources";
            case CL_OUT_OF_HOST_MEMORY:         return "Out of host memory";
            case CL_PROFILING_INFO_NOT_AVAILABLE:   return "Profiling info not available";
            case CL_MEM_COPY_OVERLAP:           return "Memory copy overlap";
            case CL_IMAGE_FORMAT_MISMATCH:      return "Image format mismatch";
            case CL_IMAGE_FORMAT_NOT_SUPPORTED: return "Image format not supported";
            case CL_BUILD_PROGRAM_FAILURE:      return "Build program failure";
            case CL_MAP_FAILURE:                return "Map failure";
            case CL_INVALID_VALUE:              return "Invalid value";
            case CL_INVALID_DEVICE_TYPE:        return "Invalid device type";
            case CL_INVALID_PLATFORM:           return "Invalid platform";
            case CL_INVALID_DEVICE:             return "Invalid device";
            case CL_INVALID_CONTEXT:            return "Invalid context";
            case CL_INVALID_QUEUE_PROPERTIES:   return "Invalid queue properties";
            case CL_INVALID_COMMAND_QUEUE:      return "Invalid command queue";
            case CL_INVALID_HOST_PTR:           return "Invalid host pointer";
            case CL_INVALID_MEM_OBJECT:         return "Invalid memory object";
            case CL_INVALID_IMAGE_FORMAT_DESCRIPTOR:    return "Invalid image format descriptor";
            case CL_INVALID_IMAGE_SIZE:         return "Invalid image size";
            case CL_INVALID_SAMPLER:            return "Invalid sampler";
            case CL_INVALID_BINARY:             return "Invalid binary";
            case CL_INVALID_BUILD_OPTIONS:      return "Invalid build options";
            case CL_INVALID_PROGRAM:            return "Invalid program";
            case CL_INVALID_PROGRAM_EXECUTABLE: return "Invalid program executable";
            case CL_INVALID_KERNEL_NAME:        return "Invalid kernel name";
            case CL_INVALID_KERNEL_DEFINITION:  return "Invalid kernel definition";
            case CL_INVALID_KERNEL:             return "Invalid kernel";
            case CL_INVALID_ARG_INDEX:          return "Invalid argument index";
            case CL_INVALID_ARG_VALUE:          return "Invalid argument value";
            case CL_INVALID_ARG_SIZE:           return "Invalid argument size";
            case CL_INVALID_KERNEL_ARGS:        return "Invalid kernel arguments";
            case CL_INVALID_WORK_DIMENSION:     return "Invalid work dimension";
            case CL_INVALID_WORK_GROUP_SIZE:    return "Invalid work group size";
            case CL_INVALID_WORK_ITEM_SIZE:     return "invalid work item size";
            case CL_INVALID_GLOBAL_OFFSET:      return "Invalid global offset";
            case CL_INVALID_EVENT_WAIT_LIST:    return "Invalid event wait list";
            case CL_INVALID_EVENT:              return "Invalid event";
            case CL_INVALID_OPERATION:          return "Invalid operation";
            case CL_INVALID_GL_OBJECT:          return "Invalid OpenGL object";
            case CL_INVALID_BUFFER_SIZE:        return "Invalid buffer size";
            case CL_INVALID_MIP_LEVEL:          return "Invalid MIP level";
        }

        //  unhandled case
        assert(false);
        return "Unhandled opencl error";
    }

clEnqueueNDRangeKernel returns CL_INVALID_COMMAND_QUEUE

Have been trying to run the particle example, and have run in to an issue with the command queue.

The line below sets err to CL_INVALID_COMMAND_QUEUE, rather than CL_SUCCESS

err = clEnqueueNDRangeKernel(pOpenCL->getQueue(), clKernel, numDimensions, NULL, globalSize, localSize, 0, NULL, NULL);
assert(err == CL_SUCCESS);

The console output is this :

[verbose] OpenCL::loadProgramFromFile
[verbose] OpenCLProgram::OpenCLProgram
[verbose] OpenCLProgram::loadFromFile MSAOpenCL/Particle.cl, isBinary: 0
[verbose] OpenCLProgram::loadFromSource 
[verbose] OpenCL::loadKernel updateParticle, 0
[verbose] OpenCLProgram::loadKernel updateParticle
[verbose] OpenCLKernel::OpenCLKernel 3931920, updateParticle
[verbose] OpenCLBuffer::initBuffer
[verbose] OpenCLMemoryObject::memoryObjectInit
[verbose] OpenCLBuffer::initFromGLObject
[verbose] OpenCLMemoryObject::memoryObjectInit
Assertion failed: (err == CL_SUCCESS), function run, file /Users/mattbilson/Development/workspace/openframeworks/of_v0072_osx_release/apps/gl/msaOpenClExample-particles/../../../addons/ofxMSAOpenCL/src/MSAOpenCLKernel.cpp, line 37.

Hardware information log below in case that is useful

[verbose] OpenCL::setupFromOpenGL 
[verbose] 2 devices found

[verbose] 

*********
OpenCL Device information:
 vendorName..................NVIDIA
 deviceName..................GeForce 9600M GT
 driverVersion...............CLH 1.0
 deviceVersion...............OpenCL 1.0 
 maxComputeUnits.............4
 maxWorkItemDimensions.......3
 maxWorkItemSizes[0].........512
 maxWorkGroupSize............512
 maxClockFrequency...........1250
 maxMemAllocSize.............128.000 MB
 imageSupport................YES
 maxReadImageArgs............128
 maxWriteImageArgs...........8
 image2dMaxWidth.............4096
 image2dMaxHeight............4096
 image3dMaxWidth.............2048
 image3dMaxHeight............2048
 image3dMaxDepth.............2048
 maxSamplers.................16
 maxParameterSize............4352
 globalMemCacheSize..........0.000 MB
 globalMemSize...............256.000 MB
 maxConstantBufferSize.......64.000 KB
 maxConstantArgs.............9
 localMemSize................16.000 KB
 errorCorrectionSupport......NO
 profilingTimerResolution....1000
 endianLittle................1
 profile.....................FULL_PROFILE
 extensions..................cl_APPLE_SetMemObjectDestructor cl_APPLE_ContextLoggingFunctions cl_APPLE_clut cl_APPLE_query_kernel_names cl_APPLE_gl_sharing cl_khr_gl_event cl_khr_byte_addressable_store cl_khr_global_int32_base_atomics cl_khr_global_int32_extended_atomics 
*********

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.