在源代码对pointer 2. can的注释中,评论说“结果”参数可以是“主机或设备指针”。
public static int cublasSdot(
cublasHandle handle,
int n,
Pointer x,
int incx,
Pointer y,
int incy,
Pointer result)/** host or device pointer */
{
return checkResult(cublasSdotNative(handle, n, x, incx, y, incy, result));
}但是,我只能在Pointer.to fs ={0}中使用像float[] (Fs)这样的主机指针。如果我使用'CUdeviceptr devicePtr =新CUdeviceptr();JCudaDriver.cuMemAlloc(devicePtr,100 *Sizeof.FLOAT)之类的设备指针,程序会崩溃,控制台消息如下:
#
# A fatal error has been detected by the Java Runtime Environment:
#
# EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x000007fed93af2a3, pid=9376, tid=0x0000000000003a7c
# .....最大限度地减少主机和设备之间的数据传输,节省时间。如何使用设备指针作为此方法的“结果”参数,以及其他带有结果指针的JCuda方法如何使用/**主机或设备指针**/?
发布于 2016-11-08 15:31:57
CUBLAS可以将某些计算的结果(如点积)写入主机或设备内存。必须使用cublasSetPointerMode显式地设置目标内存类型。
在JCublas2PointerModes示例中显示了如何使用此方法的示例。
它曾经将点积计算的结果写入主机内存(在没有显式设置指针模式的情况下,这也是默认的):
// Set the pointer mode to HOST
cublasSetPointerMode(handle, CUBLAS_POINTER_MODE_HOST);
// Prepare the pointer for the result in HOST memory
float hostResult[] = { -1.0f };
Pointer hostResultPointer = Pointer.to(hostResult);
// Execute the 'dot' function
cublasSdot(handle, n, deviceData, 1, deviceData, 1, hostResultPointer);然后更改指针模式并再次调用函数,这一次将结果写入设备内存:
cublasSetPointerMode(handle, CUBLAS_POINTER_MODE_DEVICE);
// Prepare the pointer for the result in DEVICE memory
Pointer deviceResultPointer = new Pointer();
cudaMalloc(deviceResultPointer, Sizeof.FLOAT);
// Execute the 'dot' function
cublasSdot(handle, n, deviceData, 1, deviceData, 1, deviceResultPointer);https://stackoverflow.com/questions/40461564
复制相似问题