Search in sources :

Example 1 with FloatSerializable

use of de.mirkosertic.bytecoder.api.opencl.FloatSerializable in project Bytecoder by mirkosertic.

the class OpenCLContext method toDataRef.

private static DataRef toDataRef(Object[] aArray, Class aDataType) {
    if (FloatSerializable.class.isAssignableFrom(aDataType)) {
        OpenCLType theType = (OpenCLType) aDataType.getAnnotation(OpenCLType.class);
        int theSize = aArray.length * theType.elementCount();
        FloatBuffer theBuffer = FloatBuffer.allocate(theSize);
        for (Object anAArray : aArray) {
            FloatSerializable theVec = (FloatSerializable) anAArray;
            theVec.writeTo(theBuffer);
        }
        return new DataRef(Pointer.to(theBuffer), Sizeof.cl_float * theSize) {

            @Override
            public void updateFromBuffer() {
                theBuffer.rewind();
                for (Object anAArray : aArray) {
                    FloatSerializable theVec = (FloatSerializable) anAArray;
                    theVec.readFrom(theBuffer);
                }
            }
        };
    }
    throw new IllegalArgumentException("Not supported datatype : " + aDataType);
}
Also used : OpenCLType(de.mirkosertic.bytecoder.api.opencl.OpenCLType) FloatBuffer(java.nio.FloatBuffer) CL.clReleaseMemObject(org.jocl.CL.clReleaseMemObject) FloatSerializable(de.mirkosertic.bytecoder.api.opencl.FloatSerializable)

Aggregations

FloatSerializable (de.mirkosertic.bytecoder.api.opencl.FloatSerializable)1 OpenCLType (de.mirkosertic.bytecoder.api.opencl.OpenCLType)1 FloatBuffer (java.nio.FloatBuffer)1 CL.clReleaseMemObject (org.jocl.CL.clReleaseMemObject)1