Skip to content

Commit 7e89b09

Browse files
author
xuanxuqaq
committed
修复部分intel CPU被识别为opencl加速设备导致报错的问题
1 parent 9458cd6 commit 7e89b09

File tree

3 files changed

+29
-6
lines changed

3 files changed

+29
-6
lines changed

C++/openclAccelerator/src/dllmain.cpp

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ Device current_device;
4949
Memory<char> p_stop_signal;
5050
JavaVM* jvm;
5151

52+
constexpr auto bytes2G = 2147483648;
53+
5254
/*
5355
* Class: file_engine_dllInterface_gpu_OpenclAccelerator
5456
* Method: getDevices
@@ -64,7 +66,7 @@ JNIEXPORT jstring JNICALL Java_file_engine_dllInterface_gpu_OpenclAccelerator_ge
6466
for (size_t i = 0; i < device_count; ++i)
6567
{
6668
// 内存大于2G,并且是GPU
67-
if (constexpr auto bytes2G = 2147483648; devices[i].memory > bytes2G && devices[i].is_gpu)
69+
if (devices[i].memory > bytes2G && devices[i].is_gpu)
6870
{
6971
device_string.append(devices[i].name).append(",").append(std::to_string(i)).append(";");
7072
}
@@ -440,9 +442,19 @@ JNIEXPORT jboolean JNICALL Java_file_engine_dllInterface_gpu_OpenclAccelerator_i
440442
{
441443
auto&& devices = get_devices();
442444
if (devices.empty())
445+
{
443446
return JNI_FALSE;
444-
445-
return JNI_TRUE;
447+
}
448+
jboolean ret = JNI_FALSE;
449+
for (auto&& each : devices)
450+
{
451+
if (each.memory > bytes2G && each.is_gpu)
452+
{
453+
ret = JNI_TRUE;
454+
break;
455+
}
456+
}
457+
return ret;
446458
}
447459

448460
/*

src/main/java/file/engine/dllInterface/gpu/GPUAccelerator.java

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,15 +174,26 @@ public Map<String, String> getDevices() {
174174
private void getDeviceToMap(IGPUAccelerator igpuAccelerator, HashMap<String, String> deviceMap, Category category) {
175175
if (igpuAccelerator.isGPUAvailableOnSystem()) {
176176
String devices = igpuAccelerator.getDevices();
177+
if (devices.isBlank())
178+
return;
177179
String[] deviceInfo = RegexUtil.semicolon.split(devices);
178-
if (deviceInfo != null && deviceInfo.length != 0) {
179-
for (var eachDeviceInfo : deviceInfo) {
180-
String[] nameAndId = RegexUtil.comma.split(eachDeviceInfo);
180+
if (deviceInfo == null || deviceInfo.length == 0) {
181+
return;
182+
}
183+
for (var eachDeviceInfo : deviceInfo) {
184+
if (eachDeviceInfo.isBlank())
185+
continue;
186+
String[] nameAndId = RegexUtil.comma.split(eachDeviceInfo);
187+
if (null == nameAndId || nameAndId.length != 2)
188+
continue;
189+
try {
181190
String deviceName = nameAndId[0];
182191
int deviceId = Integer.parseInt(nameAndId[1]);
183192
if (!deviceMap.containsKey(deviceName)) {
184193
deviceMap.put(deviceName, category + ";" + deviceId);
185194
}
195+
} catch (Exception e) {
196+
e.printStackTrace();
186197
}
187198
}
188199
}
512 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)