aboutsummaryrefslogtreecommitdiffstats
path: root/src/com/mbien/opencl/CLInfoAccessor.java
blob: e366f7eaf96b18f6b24ae7b8771533c6f11c61f7 (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
package com.mbien.opencl;

import java.nio.Buffer;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;

import static com.mbien.opencl.CLException.*;

/**
 * Internal utility for common OpenCL clGetFooInfo calls.
 * @author Michael Bien
 */
abstract class CLInfoAccessor {

    private final static ByteBuffer buffer;
    private final static long[] longBuffer;

    // TODO revisit for command queue concurrency
    // TODO use direct memory code path as soon gluegen is fixed
    static{
        buffer = ByteBuffer.allocate(512);
        buffer.order(ByteOrder.nativeOrder());
        longBuffer = new long[1];
    }

    public CLInfoAccessor() {
    }

    final long getLong(int key) {

        buffer.rewind();
        int ret = getInfo(key, 8, buffer, null, 0);
        checkForError(ret, "error while asking for info value");

        return buffer.getLong();
    }

    final String getString(int key) {

        buffer.rewind();
        int ret = getInfo(key, buffer.capacity(), buffer, longBuffer, 0);
        checkForError(ret, "error while asking for info string");

        return CLUtils.clString2JavaString(buffer.array(), (int)longBuffer[0]);

    }

    protected abstract int getInfo(int name, long valueSize, Buffer value, long[] valueSizeRet, int valueSizeRetOffset);


}