Skip to content

Commit

Permalink
修复部分intel CPU被识别为opencl加速设备导致报错的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
xuanxuqaq committed Oct 1, 2022
1 parent 9458cd6 commit 7e89b09
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 6 deletions.
18 changes: 15 additions & 3 deletions C++/openclAccelerator/src/dllmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ Device current_device;
Memory<char> p_stop_signal;
JavaVM* jvm;

constexpr auto bytes2G = 2147483648;

/*
* Class: file_engine_dllInterface_gpu_OpenclAccelerator
* Method: getDevices
Expand All @@ -64,7 +66,7 @@ JNIEXPORT jstring JNICALL Java_file_engine_dllInterface_gpu_OpenclAccelerator_ge
for (size_t i = 0; i < device_count; ++i)
{
// 内存大于2G,并且是GPU
if (constexpr auto bytes2G = 2147483648; devices[i].memory > bytes2G && devices[i].is_gpu)
if (devices[i].memory > bytes2G && devices[i].is_gpu)
{
device_string.append(devices[i].name).append(",").append(std::to_string(i)).append(";");
}
Expand Down Expand Up @@ -440,9 +442,19 @@ JNIEXPORT jboolean JNICALL Java_file_engine_dllInterface_gpu_OpenclAccelerator_i
{
auto&& devices = get_devices();
if (devices.empty())
{
return JNI_FALSE;

return JNI_TRUE;
}
jboolean ret = JNI_FALSE;
for (auto&& each : devices)
{
if (each.memory > bytes2G && each.is_gpu)
{
ret = JNI_TRUE;
break;
}
}
return ret;
}

/*
Expand Down
17 changes: 14 additions & 3 deletions src/main/java/file/engine/dllInterface/gpu/GPUAccelerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -174,15 +174,26 @@ public Map<String, String> getDevices() {
private void getDeviceToMap(IGPUAccelerator igpuAccelerator, HashMap<String, String> deviceMap, Category category) {
if (igpuAccelerator.isGPUAvailableOnSystem()) {
String devices = igpuAccelerator.getDevices();
if (devices.isBlank())
return;
String[] deviceInfo = RegexUtil.semicolon.split(devices);
if (deviceInfo != null && deviceInfo.length != 0) {
for (var eachDeviceInfo : deviceInfo) {
String[] nameAndId = RegexUtil.comma.split(eachDeviceInfo);
if (deviceInfo == null || deviceInfo.length == 0) {
return;
}
for (var eachDeviceInfo : deviceInfo) {
if (eachDeviceInfo.isBlank())
continue;
String[] nameAndId = RegexUtil.comma.split(eachDeviceInfo);
if (null == nameAndId || nameAndId.length != 2)
continue;
try {
String deviceName = nameAndId[0];
int deviceId = Integer.parseInt(nameAndId[1]);
if (!deviceMap.containsKey(deviceName)) {
deviceMap.put(deviceName, category + ";" + deviceId);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
Expand Down
Binary file modified src/main/resources/win32-native/openclAccelerator.dll
Binary file not shown.

0 comments on commit 7e89b09

Please sign in to comment.