summaryrefslogtreecommitdiffstats
path: root/make/config/clImplCustomCode.java
blob: 6c407110d4767d803f0dee5253d7ced4a85ab103 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56

    /** If null, OpenCL is not available on this machine. */
    static final DynamicLibraryBundle dynamicLookupHelper;
    protected static final CLProcAddressTable addressTable;

    static {
        addressTable = new CLProcAddressTable();
        dynamicLookupHelper = AccessController.doPrivileged(new PrivilegedAction<DynamicLibraryBundle>() {
                                  public DynamicLibraryBundle run() {
                                      final DynamicLibraryBundle bundle = new DynamicLibraryBundle(new CLDynamicLibraryBundleInfo());
                                      if(!bundle.isToolLibLoaded()) {
                                          // couldn't load native CL library
                                          // TODO: log this?
                                          return null;
                                      }
                                      if(!bundle.isLibComplete()) {
                                          // couldn't load native CL/JNI glue library
                                          // TODO: log this?
                                          return null;
                                      }
                                      addressTable.reset(bundle);
                                      return bundle;
                                  } } );
    }

    /**
     * Accessor.
     * @returns true if OpenCL is available on this machine.
     */
    public static boolean isAvailable() { return dynamicLookupHelper != null; }
    public static CLProcAddressTable getCLProcAddressTable() { return addressTable; }

    static long clGetExtensionFunctionAddress(long clGetExtensionFunctionAddressHandle, java.lang.String procname)
    {
        if (clGetExtensionFunctionAddressHandle == 0) {
            throw new RuntimeException("Passed null pointer for method \"clGetExtensionFunctionAddress\"");
        }
        return dispatch_clGetExtensionFunctionAddressStatic(procname, clGetExtensionFunctionAddressHandle);
    }

    public CLAbstractImpl() {
    }

    /** Entry point (through function pointer) to C language function: <br> <code> void* clGetExtensionFunctionAddress(const char *  fname); </code>    */
    long clGetExtensionFunctionAddress(String fname)  {

        final long __addr_ = addressTable._addressof_clGetExtensionFunctionAddress;
        if (__addr_ == 0) {
            throw new UnsupportedOperationException("Method \"clGetExtensionFunctionAddress\" not available");
        }
        return dispatch_clGetExtensionFunctionAddressStatic(fname, __addr_);
    }

    /** Entry point (through function pointer) to C language function: <br> <code> void* clGetExtensionFunctionAddress(const char *  fname); </code>    */
    private static native long dispatch_clGetExtensionFunctionAddressStatic(String fname, long procAddress);