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

import java.nio.ByteBuffer;

/**
 *
 * @author Michael Bien
 */
public class CLDevice {
    
    private final CL cl;
    private final long deviceID;

    CLDevice(CL cl, long id) {
        this.cl = cl;
        this.deviceID = id;
    }

    /**
     * Returns the name of this device.
     */
    public String getName() {
        return getInfoString(CL.CL_DEVICE_NAME);
    }

    public String getInfoString(int key) {

        long[] longBuffer = new long[1];
        ByteBuffer bb = ByteBuffer.allocate(512);

        int ret = cl.clGetDeviceInfo(deviceID, key, bb.capacity(), bb, longBuffer, 0);
        
        if(CL.CL_SUCCESS != ret)
            throw new CLException(ret, "can not receive info string");

        return new String(bb.array(), 0, (int)longBuffer[0]);
        
    }

//   ret = cl.clGetDeviceInfo(device, CL.CL_DEVICE_TYPE, bb.capacity(), bb, longBuffer, 0);
//   assertEquals(CL.CL_SUCCESS, ret);
}