【问题标题】:Jocl and Device FissionJocl 和设备裂变
【发布时间】:2013-05-23 00:08:50
【问题描述】:

编辑:问题解决了! rzymek 的回答很有帮助。

问题:对于 JOCL,如何通过设备裂变从 opencl 计算中排除一些 CPU 内核?(cl_device_partition_property 的 Java 端口在 0.1.9 版本中似乎已损坏)

编辑:我发现了这个:

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

刚刚尝试空初始化,然后使用变量自己的方法来设置属性:

    cl_device_partition_property core = null;
    core.addProperty(CL_DEVICE_PARTITION_BY_COUNTS, platforms[0]);

编辑:现在它给出了

    java.lang.NullPointerException,

错误。

IT 需要是 unsigned int(不是 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 的来源(我猜是这个?jocl.org/downloads/downloads.html)看看幕后发生了什么?
  • 是的,它是新添加的(来自此版本之前的两个版本),只是不编译或给出致命错误。其他一切正常。 windows-7 64 位家庭高级版 + eclipse juno。有 addProperty(id, value.getNativePointer());没有明确的声明。

标签: java opencl jocl


【解决方案1】:

我认为这是 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 和 value 都附加到 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);

【讨论】:

  • 总比没有好。明天试试。
  • 所以属性的末尾会自动添加一个零。
  • 解决方法 1 似乎有效。谢谢。从现在开始,这些至强将变得高效。
  • 是的,addProperty 确保末尾有一个 0。我更喜欢第二种解决方法:)
  • 但仍有 %30 的时间出现致命错误。启动程序时。如果它打开,运行良好,直到 java3d 和 jmonkey 清除 opencl 上下文或程序。刚刚对我的 fx8150 进行了分区 :) 是的,第二个解决方法似乎更好。
猜你喜欢
  • 2015-04-11
  • 1970-01-01
  • 2011-06-06
  • 1970-01-01
  • 2018-06-13
  • 2019-01-17
  • 2016-03-08
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多