Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
JCuda';s JCublas2.cublasSdot:未能将设备指针用于结果指针参数_Jcuda - Fatal编程技术网

JCuda';s JCublas2.cublasSdot:未能将设备指针用于结果指针参数

JCuda';s JCublas2.cublasSdot:未能将设备指针用于结果指针参数,jcuda,Jcuda,在JCublas2.cublasSdot的源代码注释中,注释了“result”参数可以是“主机或设备指针” public static int cublasSdot( cublasHandle handle, int n, Pointer x, int incx, Pointer y, int incy, Pointer result)/** host or device pointer */ { return che

在JCublas2.cublasSdot的源代码注释中,注释了“result”参数可以是“主机或设备指针”

 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));
}
但是,我只能使用带有float[]fs={0}的主机指针,如pointer.to(fs)。如果我使用像'CUdeviceptr devicePtr=new 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
# .....

尽量减少主机和设备之间的数据传输,节省时间。如何使用设备指针作为此方法的“result”参数,以及其他结果指针以/**主机或设备指针**/注释的JCuda方法

CUBLAS可以将某些计算结果(如点积)写入主机或设备内存。必须使用显式设置目标内存类型

示例中显示了如何使用此功能的示例

它曾经将点积计算的结果写入主机内存(当没有明确设置指针模式时,这也是默认值):

然后更改指针模式并再次调用函数,这次将结果写入设备内存:


非常感谢,马可。我稍后再试试。这正好解决了问题。
// 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);