在使用halcon对像素较大的bmp图片借助算子进行相关操作时,会发生系统提示没有足够的内存空间,即clion后台会直接报409空指针异常。可借助GPU对算子加速来解决该问题。GPU代码加速如下(C++):
//开启GPU加速
QueryAvailableComputeDevices(&hv_DeviceIdentifier); //查询可利用的设备
hv_DeviceHandle = 0;
bool l = false;
HTuple end_val = (hv_DeviceIdentifier.TupleLength()) - 1;
HTuple step = 1,hv_i;
for (hv_i = 0; hv_i.Continue(end_val, step); hv_i += step) {
GetComputeDeviceInfo(HTuple(hv_DeviceIdentifier[hv_i]),"name",&Name);
// cout<<Name<<endl;
if(0 != (int(Name==HTuple("NVIDIA GeForce RTX 3070 Ti Laptop GPU")))){
OpenComputeDevice(HTuple(hv_DeviceIdentifier[hv_i]), &hv_DeviceHandle);
l = true;
break;
}
}
if(!l) {
printf("ERROR Find GPU\n");
return;
}
SetComputeDeviceParam(hv_DeviceHandle, "alloc_pinned", "true");
SetComputeDeviceParam(hv_DeviceHandle, "image_cache_capacity", 16*1024*1024*1024);
InitComputeDevice(hv_DeviceHandle, "all");
ActivateComputeDevice(hv_DeviceHandle);