Search in sources :

Example 1 with OpenCLType

use of de.mirkosertic.bytecoder.api.opencl.OpenCLType 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)

Example 2 with OpenCLType

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

the class OpenCLWriter method toStructName.

private String toStructName(BytecodeObjectTypeRef aObjectType) {
    BytecodeLinkedClass theLinkedClass = linkerContext.resolveClass(aObjectType);
    BytecodeClass theBytecodeClass = theLinkedClass.getBytecodeClass();
    BytecodeAnnotation theAnnotation = theBytecodeClass.getAttributes().getAnnotationByType(OpenCLType.class.getName());
    if (theAnnotation == null) {
        throw new IllegalArgumentException("No @OpenCLType found for " + aObjectType.name());
    }
    return theAnnotation.getElementValueByName("name").stringValue();
}
Also used : BytecodeAnnotation(de.mirkosertic.bytecoder.core.BytecodeAnnotation) OpenCLType(de.mirkosertic.bytecoder.api.opencl.OpenCLType) BytecodeLinkedClass(de.mirkosertic.bytecoder.core.BytecodeLinkedClass) BytecodeClass(de.mirkosertic.bytecoder.core.BytecodeClass)

Aggregations

OpenCLType (de.mirkosertic.bytecoder.api.opencl.OpenCLType)2 FloatSerializable (de.mirkosertic.bytecoder.api.opencl.FloatSerializable)1 BytecodeAnnotation (de.mirkosertic.bytecoder.core.BytecodeAnnotation)1 BytecodeClass (de.mirkosertic.bytecoder.core.BytecodeClass)1 BytecodeLinkedClass (de.mirkosertic.bytecoder.core.BytecodeLinkedClass)1 FloatBuffer (java.nio.FloatBuffer)1 CL.clReleaseMemObject (org.jocl.CL.clReleaseMemObject)1