nvcc 生成无效错误编译 JNI 代码
nvcc generating invalid error compiling JNI code
$ nvcc --version
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2017 NVIDIA Corporation
Built on Fri_Sep__1_21:08:03_CDT_2017
Cuda compilation tools, release 9.0, V9.0.176
错误是:
MyFile.cu(231): error: expression must have pointer type
相关代码:
JNIEXPORT jboolean JNICALL Java_MyFile_convergeMatrixCuda (
JNIEnv *env, jclass clazz, jfloatArray fxnMatrixJ, jfloatArray mulMatrixJ, jfloatArray addMatrixJ,
jfloatArray resultsJ, jint numRowsJ, jint numColsJ, jint maxIterations, jfloat epsilonJ)
{
int numRows = (int) numRowsJ;
int numCols = (int) numColsJ;
int maxIter = (int) maxIterations;
float epsilon = (float) epsilonJ;
float *fxnMatrixH = (*env)->GetFloatArrayElements (env, fxnMatrixJ, NULL);
GetFloatArrayElements returns 一个浮点数*。将“(*env)->GetFloatArrayElements”替换为 "env->GetFloatArrayElements" 会出现以下错误:
float *fxnMatrixH = env->GetFloatArrayElements (env, fxnMatrixJ, NULL);
MyFile.cu(231): error: argument of type "JNIEnv *" is incompatible with parameter of type "jfloatArray"
MyFile.cu(231): error: argument of type "jfloatArray" is incompatible with parameter of type "jboolean *"
MyFile.cu(231): error: too many arguments in function call
nvcc 在编译非 JNI 代码时确实可以正常工作
Source files for CUDA applications consist of a mixture of conventional C++ host code, plus GPU device functions.
(*env)->GetFloatArrayElements (env, fxnMatrixJ, NULL);
是您在 C 中调用 JNI 函数的方式。但在 C++ 中它将是 env->GetFloatArrayElements(fxnMatrixJ, NULL);
$ nvcc --version
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2017 NVIDIA Corporation
Built on Fri_Sep__1_21:08:03_CDT_2017
Cuda compilation tools, release 9.0, V9.0.176
错误是:
MyFile.cu(231): error: expression must have pointer type
相关代码:
JNIEXPORT jboolean JNICALL Java_MyFile_convergeMatrixCuda (
JNIEnv *env, jclass clazz, jfloatArray fxnMatrixJ, jfloatArray mulMatrixJ, jfloatArray addMatrixJ,
jfloatArray resultsJ, jint numRowsJ, jint numColsJ, jint maxIterations, jfloat epsilonJ)
{
int numRows = (int) numRowsJ;
int numCols = (int) numColsJ;
int maxIter = (int) maxIterations;
float epsilon = (float) epsilonJ;
float *fxnMatrixH = (*env)->GetFloatArrayElements (env, fxnMatrixJ, NULL);
GetFloatArrayElements returns 一个浮点数*。将“(*env)->GetFloatArrayElements”替换为 "env->GetFloatArrayElements" 会出现以下错误:
float *fxnMatrixH = env->GetFloatArrayElements (env, fxnMatrixJ, NULL);
MyFile.cu(231): error: argument of type "JNIEnv *" is incompatible with parameter of type "jfloatArray"
MyFile.cu(231): error: argument of type "jfloatArray" is incompatible with parameter of type "jboolean *"
MyFile.cu(231): error: too many arguments in function call
nvcc 在编译非 JNI 代码时确实可以正常工作
Source files for CUDA applications consist of a mixture of conventional C++ host code, plus GPU device functions.
(*env)->GetFloatArrayElements (env, fxnMatrixJ, NULL);
是您在 C 中调用 JNI 函数的方式。但在 C++ 中它将是 env->GetFloatArrayElements(fxnMatrixJ, NULL);