Skip to content
pascal edited this page Jan 13, 2024 · 13 revisions

Welcome to the kuda-12.2 wiki!

Purpose

The purpose of this library is to facilitate convenient usage of CUDA for Kotlin developers.

Version Management

Following Semantic Versioning (major.minor.patch)

Branch Rule

  • master : merge develop branch. This branch will always have a 1:1 relationship with the kuda documentation(dokka).
  • develop : merge many githubid branches develop branch is the newest code
  • githubid : it is personal-common branch for kudakit organization members

Common Coding Rule

1. Use Automatic Type Casting of JNI

for example 1, Here is code that needs cleaning up

JNIEXPORT jlong JNICALL Java_kuda_runtimeapi_DeviceHandler_getDefaultMemPool(JNIEnv* env, jclass cls, jint device) {

	cudaMemPool_t memPool;

	cudaError_t cudaStatus = cudaDeviceGetMemPool(&memPool, (int)device);

	if (cudaStatus != cudaSuccess) {
		return cudaStatus;
	}

	return (jlong)memPool;
}

remove type casting in 'same data type (jint<->int, jlong<->long, etc..)'

JNIEXPORT jlong JNICALL Java_kuda_runtimeapi_DeviceHandler_getDefaultMemPool(JNIEnv* env, jclass cls, jint device) {

	cudaMemPool_t memPool;

	cudaError_t cudaStatus = cudaDeviceGetMemPool(&memPool, device);

	if (cudaStatus != cudaSuccess) {
		return cudaStatus;
	}

	return (jlong)memPool;
}

example 2, before

JNIEXPORT jint JNICALL Java_kuda_kublas_Kublas_getPointerMode(JNIEnv* env, jobject obj, jlong handle) {

	//initialize...
	cublasPointerMode_t cublasPointerMode = CUBLAS_POINTER_MODE_HOST;

	cublasHandle_t cublasHandle = reinterpret_cast<cublasHandle_t>(handle);

	cublasStatus_t cublasStatus = cublasGetPointerMode(cublasHandle, &cublasPointerMode);

	if (cublasStatus != CUBLAS_STATUS_SUCCESS) {
		return cublasStatus;
	}

	return (jint)static_cast<int>(cublasPointerMode);
}

after

JNIEXPORT jint JNICALL Java_kuda_kublas_Kublas_getPointerMode(JNIEnv* env, jobject obj, jlong handle) {

	//initialize...
	cublasPointerMode_t cublasPointerMode = CUBLAS_POINTER_MODE_HOST;

	cublasHandle_t cublasHandle = reinterpret_cast<cublasHandle_t>(handle);

	cublasStatus_t cublasStatus = cublasGetPointerMode(cublasHandle, &cublasPointerMode);

	if (cublasStatus != CUBLAS_STATUS_SUCCESS) {
		return cublasStatus;
	}

	return static_cast<int>(cublasPointerMode);
}
Clone this wiki locally