编辑:问题解决了! rzymek的回答很有帮助。
问题:对于JOCL,如何通过设备裂变从opencl计算中排除某些CPU内核?(对于0.1.9版本,cl_device_partition_property的Java端口似乎已损坏)
编辑:我发现:
clCreateSubDevices(devices[0][1],core , 1, cpuCores, coreIDs);
但是java / jocl不接受:
cl_device_partition_property core=CL.CL_DEVICE_PARTITION_BY_COUNTS;
错误是:
Type mismatch: cannot convert from int to cl_device_partition_property
刚尝试过null初始化,然后使用变量自己的方法来设置属性:
cl_device_partition_property core = null;
core.addProperty(CL_DEVICE_PARTITION_BY_COUNTS, platforms[0]);
编辑:现在它给
java.lang.NullPointerException,
错误。
IT需要为无符号整数(不是cl_device_partition_property),但是Java没有它。
构造函数的新尝试:
cl_device_partition_property core = new cl_device_partition_property();
错误:
A fatal error has been detected by the Java Runtime Environment:
#
# EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x000007fedb6500bf, pid=4952, tid=4852
#
# JRE version: 7.0_21-b11
# Java VM: Java HotSpot(TM) 64-Bit Server VM (23.21-b01 mixed mode windows-amd64 compressed oops)
# Problematic frame:
# C [amdocl64.dll+0x1800bf] clGetSamplerInfo+0x1972f
#
# Failed to write core dump. Minidumps are not enabled by default on client versions of Windows
#
# An error report file with more information is saved as:
# C:\javalar\buraya\paralelProje\hs_err_pid4952.log
#
# If you would like to submit a bug report, please visit:
# http://bugreport.sun.com/bugreport/crash.jsp
# The crash happened outside the Java Virtual Machine in native code.
# See problematic frame for where to report the bug.
#
[error occurred during error reporting , id 0xc0000005]
另一种尝试:
cl_device_partition_property core = (CL_UNSIGNED_INT32)CL_DEVICE_PARTITION_BY_COUNTS;
错误:
CL_UNSIGNED_INT32 cannot be resolved to a type
这也行不通:
Pointer xyz=Pointer.to(core); // jocl's pointer type.
clCreateSubDevices(device,xyz, 1, cpuCores, coreIDs);
编辑:问题解决了!谢谢。现在可以对我的cpu进行分区:
最佳答案
我认为这是JOCL缺少的功能。
我认为您可以尝试这两种解决方法。
假设您要设置此属性列表:
{ CL_DEVICE_PARTITION_BY_COUNTS, 3, 1, CL_DEVICE_PARTITION_BY_COUNTS_LIST_END, 0 }
(摘自http://software.intel.com/en-us/articles/opencl-device-fission-for-cpu-performance的“属性列表示例”)。
解决方法1:
cl_device_partition_property properties = new cl_device_partition_property();
properties.addProperty(CL.CL_DEVICE_PARTITION_BY_COUNTS, 3);
properties.addProperty(1, CL.CL_DEVICE_PARTITION_BY_COUNTS_LIST_END);
说明:addProperty方法仅将id和值都附加到long []数组的末尾,并将其转换为Buffer:
public void addProperty(long id, long value)
{
LongBuffer oldBuffer = (LongBuffer)getBuffer();
long newArray[] = new long[oldBuffer.capacity()+2];
oldBuffer.get(newArray, 0, oldBuffer.capacity());
newArray[oldBuffer.capacity()-1] = id;
newArray[oldBuffer.capacity()+0] = value;
newArray[oldBuffer.capacity()+1] = 0;
setBuffer(LongBuffer.wrap(newArray));
}
因此可以创建任何列表,例如:
addProperty(item[0], item[1]);
addProperty(item[2], item[3]);
addProperty(item[4], item[5]);
addProperty(item[6], 0);
解决方法2:
在
org.jcol
包中创建一个类,以访问受限方法setBuffer
:package org.jocl;
import java.nio.LongBuffer;
public class cl_device_partition_property_gateway {
public static void set(cl_device_partition_property properties, long[] newArray) {
properties.setBuffer(LongBuffer.wrap(newArray));
}
}
然后,您可以直接设置long []数组:
cl_device_partition_property properties = new cl_device_partition_property();
long[] values = { CL.CL_DEVICE_PARTITION_BY_COUNTS, 3, 1,
CL.CL_DEVICE_PARTITION_BY_COUNTS_LIST_END, 0 };
cl_device_partition_property_gateway.set(properties, values);