Search in sources :

Example 1 with OpenCLCompileBackend

use of de.mirkosertic.bytecoder.backend.opencl.OpenCLCompileBackend in project Bytecoder by mirkosertic.

the class CompilerTest method testSimpleKernel.

@Test
public void testSimpleKernel() {
    OpenCLCompileBackend backend = new OpenCLCompileBackend();
    CompileOptions compileOptions = new CompileOptions(new Slf4JLogger(), false, KnownOptimizer.ALL);
    Kernel theKernel = createKernel();
    Class theKernelClass = theKernel.getClass();
    System.out.println(theKernelClass);
    Method[] theMethods = theKernelClass.getDeclaredMethods();
    if (theMethods.length != 1) {
        throw new IllegalArgumentException("A kernel must have exactly one declared method!");
    }
    Method theMethod = theMethods[0];
    BytecodeMethodSignature theSignature = backend.signatureFrom(theMethod);
    BytecodeLoader theLoader = new BytecodeLoader(getClass().getClassLoader());
    BytecodeLinkerContext theLinkerContext = new BytecodeLinkerContext(theLoader, compileOptions.getLogger());
    OpenCLCompileResult theCompiledKernel = backend.generateCodeFor(compileOptions, theLinkerContext, theKernelClass, theMethod.getName(), theSignature);
    System.out.println(theCompiledKernel.getData());
}
Also used : OpenCLCompileBackend(de.mirkosertic.bytecoder.backend.opencl.OpenCLCompileBackend) BytecodeMethodSignature(de.mirkosertic.bytecoder.core.BytecodeMethodSignature) OpenCLCompileResult(de.mirkosertic.bytecoder.backend.opencl.OpenCLCompileResult) BytecodeLoader(de.mirkosertic.bytecoder.core.BytecodeLoader) BytecodeLinkerContext(de.mirkosertic.bytecoder.core.BytecodeLinkerContext) CompileOptions(de.mirkosertic.bytecoder.backend.CompileOptions) Method(java.lang.reflect.Method) Slf4JLogger(de.mirkosertic.bytecoder.unittest.Slf4JLogger) Test(org.junit.Test)

Example 2 with OpenCLCompileBackend

use of de.mirkosertic.bytecoder.backend.opencl.OpenCLCompileBackend in project Bytecoder by mirkosertic.

the class CompilerTest method testKernelWithComplexType.

@Test
public void testKernelWithComplexType() {
    OpenCLCompileBackend backend = new OpenCLCompileBackend();
    CompileOptions compileOptions = new CompileOptions(new Slf4JLogger(), false, KnownOptimizer.ALL);
    Float2[] theIn = new Float2[10];
    Float2[] theOut = new Float2[10];
    Kernel theKernel = new Kernel() {

        public void processWorkItem() {
            int theIndex = get_global_id(0);
            Float2 a = theIn[theIndex];
            Float2 b = theOut[theIndex];
            b.s0 = a.s0;
            b.s1 = a.s1;
        }
    };
    Class theKernelClass = theKernel.getClass();
    System.out.println(theKernelClass);
    Method[] theMethods = theKernelClass.getDeclaredMethods();
    if (theMethods.length != 1) {
        throw new IllegalArgumentException("A kernel must have exactly one declared method!");
    }
    Method theMethod = theMethods[0];
    BytecodeMethodSignature theSignature = backend.signatureFrom(theMethod);
    BytecodeLoader theLoader = new BytecodeLoader(getClass().getClassLoader());
    BytecodeLinkerContext theLinkerContext = new BytecodeLinkerContext(theLoader, compileOptions.getLogger());
    OpenCLCompileResult theCompiedKernel = backend.generateCodeFor(compileOptions, theLinkerContext, theKernelClass, theMethod.getName(), theSignature);
    System.out.println(theCompiedKernel.getData());
}
Also used : BytecodeMethodSignature(de.mirkosertic.bytecoder.core.BytecodeMethodSignature) BytecodeLoader(de.mirkosertic.bytecoder.core.BytecodeLoader) CompileOptions(de.mirkosertic.bytecoder.backend.CompileOptions) Method(java.lang.reflect.Method) OpenCLCompileBackend(de.mirkosertic.bytecoder.backend.opencl.OpenCLCompileBackend) OpenCLCompileResult(de.mirkosertic.bytecoder.backend.opencl.OpenCLCompileResult) BytecodeLinkerContext(de.mirkosertic.bytecoder.core.BytecodeLinkerContext) Slf4JLogger(de.mirkosertic.bytecoder.unittest.Slf4JLogger) Test(org.junit.Test)

Aggregations

CompileOptions (de.mirkosertic.bytecoder.backend.CompileOptions)2 OpenCLCompileBackend (de.mirkosertic.bytecoder.backend.opencl.OpenCLCompileBackend)2 OpenCLCompileResult (de.mirkosertic.bytecoder.backend.opencl.OpenCLCompileResult)2 BytecodeLinkerContext (de.mirkosertic.bytecoder.core.BytecodeLinkerContext)2 BytecodeLoader (de.mirkosertic.bytecoder.core.BytecodeLoader)2 BytecodeMethodSignature (de.mirkosertic.bytecoder.core.BytecodeMethodSignature)2 Slf4JLogger (de.mirkosertic.bytecoder.unittest.Slf4JLogger)2 Method (java.lang.reflect.Method)2 Test (org.junit.Test)2