/** * Fills in the fields of target (Java class Flock) from the fields of source * (struct flock). */ bool FUSE26Util::fillFlock(JNIEnv *env, const struct flock *source, jobject target) { CSLogTraceEnter("bool FUSE26Util::fillFlock(%p, %p, %p)", env, source, target); bool ret = false; do { jclass clazz = env->GetObjectClass(target); if(clazz == NULL || env->ExceptionCheck() == JNI_TRUE) { CSLogError("Could not get object class!"); if(env->ExceptionCheck()) env->ExceptionDescribe(); break; } if(!setLongField(env, clazz, target, "l_start", source->l_start)) break; if(!setLongField(env, clazz, target, "l_len", source->l_len)) break; if(!setLongField(env, clazz, target, "l_pid", source->l_pid)) break; if(!setShortField(env, clazz, target, "l_type", source->l_type)) break; if(!setShortField(env, clazz, target, "l_whence", source->l_whence)) break; ret = true; } while(0); CSLogTraceLeave("bool FUSE26Util::fillFlock(%p, %p, %p): %d", env, source, target, ret); return ret; }
/** * Fills in the fields of target (Java class LongRef) from the fields of source * (uint64_t). */ bool FUSE26Util::fillFUSEConnInfo(JNIEnv *env, const struct fuse_conn_info *source, jobject target) { CSLogTraceEnter("bool FUSE26Util::fillFUSEConnInfo(%p, %p, %p)", env, source, target); bool ret = false; do { jclass clazz = env->GetObjectClass(target); if(clazz == NULL || env->ExceptionCheck() == JNI_TRUE) { CSLogError("Could not get object class!"); if(env->ExceptionCheck()) env->ExceptionDescribe(); break; } if(!setLongField(env, clazz, target, "proto_major", source->proto_major)) break; if(!setLongField(env, clazz, target, "proto_minor", source->proto_minor)) break; if(!setBooleanField(env, clazz, target, "async_read", (source->async_read ? JNI_TRUE : JNI_FALSE))) break; if(!setLongField(env, clazz, target, "max_write", source->max_write)) break; if(!setLongField(env, clazz, target, "max_readahead", source->max_readahead)) break; ret = true; } while(0); CSLogTraceLeave("bool FUSE26Util::fillFUSEConnInfo(%p, %p, %p): %d", env, source, target, ret); return ret; }
// Called periodically on every UI update JNIEXPORT void Java_com_superpowered_hlsexample_MainActivity_UpdateStatus(JNIEnv *javaEnvironment, jobject self) { jclass thisClass = javaEnvironment->GetObjectClass(self); //setFloatField(javaEnvironment, self, thisClass, "bufferStartPercent", player->bufferStartPercent); setFloatField(javaEnvironment, self, thisClass, "bufferEndPercent", player->bufferEndPercent); setLongField(javaEnvironment, self, thisClass, "durationSeconds", player->durationSeconds); setLongField(javaEnvironment, self, thisClass, "positionSeconds", player->positionSeconds); setFloatField(javaEnvironment, self, thisClass, "positionPercent", player->positionPercent); setBoolField(javaEnvironment, self, thisClass, "playing", player->playing); }
static void onRttResults(wifi_request_id id, unsigned num_results, wifi_rtt_result results[]) { JNIEnv *env = NULL; mVM->AttachCurrentThread(&env, NULL); ALOGD("onRttResults called, vm = %p, obj = %p, env = %p", mVM, mCls, env); jclass clsRttResult = (env)->FindClass("android/net/wifi/RttManager$RttResult"); if (clsRttResult == NULL) { ALOGE("Error in accessing class"); return; } jobjectArray rttResults = env->NewObjectArray(num_results, clsRttResult, NULL); if (rttResults == NULL) { ALOGE("Error in allocating array"); return; } for (unsigned i = 0; i < num_results; i++) { wifi_rtt_result& result = results[i]; jobject rttResult = createObject(env, "android/net/wifi/RttManager$RttResult"); if (rttResult == NULL) { ALOGE("Error in creating rtt result"); return; } char bssid[32]; sprintf(bssid, "%02x:%02x:%02x:%02x:%02x:%02x", result.addr[0], result.addr[1], result.addr[2], result.addr[3], result.addr[4], result.addr[5]); setStringField(env, rttResult, "bssid", bssid); setIntField(env, rttResult, "status", result.status); setIntField(env, rttResult, "requestType", result.type); setLongField(env, rttResult, "ts", result.ts); setIntField(env, rttResult, "rssi", result.rssi); setIntField(env, rttResult, "rssi_spread", result.rssi_spread); setIntField(env, rttResult, "tx_rate", result.tx_rate.bitrate); setLongField(env, rttResult, "rtt_ns", result.rtt); setLongField(env, rttResult, "rtt_sd_ns", result.rtt_sd); setLongField(env, rttResult, "rtt_spread_ns", result.rtt_spread); setIntField(env, rttResult, "distance_cm", result.distance); setIntField(env, rttResult, "distance_sd_cm", result.distance_sd); setIntField(env, rttResult, "distance_spread_cm", result.distance_spread); env->SetObjectArrayElement(rttResults, i, rttResult); } reportEvent(env, mCls, "onRttResults", "(I[Landroid/net/wifi/RttManager$RttResult;)V", id, rttResults); }
static jobject createScanResult(JNIEnv *env, wifi_scan_result *result) { // ALOGD("creating scan result"); jobject scanResult = createObject(env, "android/net/wifi/ScanResult"); if (scanResult == NULL) { ALOGE("Error in creating scan result"); return NULL; } // ALOGD("setting SSID to %s", result.ssid); setStringField(env, scanResult, "SSID", result->ssid); char bssid[32]; sprintf(bssid, "%02x:%02x:%02x:%02x:%02x:%02x", result->bssid[0], result->bssid[1], result->bssid[2], result->bssid[3], result->bssid[4], result->bssid[5]); setStringField(env, scanResult, "BSSID", bssid); setIntField(env, scanResult, "level", result->rssi); setIntField(env, scanResult, "frequency", result->channel); setLongField(env, scanResult, "timestamp", result->ts); return scanResult; }
static jobject android_net_wifi_getScanResults( JNIEnv *env, jclass cls, jint iface, jboolean flush) { wifi_scan_result results[256]; int num_results = 256; wifi_interface_handle handle = getIfaceHandle(env, cls, iface); ALOGD("getting scan results on interface[%d] = %p", iface, handle); int result = wifi_get_cached_gscan_results(handle, 1, num_results, results, &num_results); if (result == WIFI_SUCCESS) { jclass clsScanResult = (env)->FindClass("android/net/wifi/ScanResult"); if (clsScanResult == NULL) { ALOGE("Error in accessing class"); return NULL; } jobjectArray scanResults = env->NewObjectArray(num_results, clsScanResult, NULL); if (scanResults == NULL) { ALOGE("Error in allocating array"); return NULL; } for (int i = 0; i < num_results; i++) { jobject scanResult = createObject(env, "android/net/wifi/ScanResult"); if (scanResult == NULL) { ALOGE("Error in creating scan result"); return NULL; } setStringField(env, scanResult, "SSID", results[i].ssid); char bssid[32]; sprintf(bssid, "%02x:%02x:%02x:%02x:%02x:%02x", results[i].bssid[0], results[i].bssid[1], results[i].bssid[2], results[i].bssid[3], results[i].bssid[4], results[i].bssid[5]); setStringField(env, scanResult, "BSSID", bssid); setIntField(env, scanResult, "level", results[i].rssi); setIntField(env, scanResult, "frequency", results[i].channel); setLongField(env, scanResult, "timestamp", results[i].ts); env->SetObjectArrayElement(scanResults, i, scanResult); env->DeleteLocalRef(scanResult); } return scanResults; } else { return NULL; } }
static void onHotlistApFound(wifi_request_id id, unsigned num_results, wifi_scan_result *results) { JNIEnv *env = NULL; mVM->AttachCurrentThread(&env, NULL); ALOGD("onHotlistApFound called, vm = %p, obj = %p, env = %p, num_results = %d", mVM, mCls, env, num_results); jclass clsScanResult = (env)->FindClass("android/net/wifi/ScanResult"); if (clsScanResult == NULL) { ALOGE("Error in accessing class"); return; } jobjectArray scanResults = env->NewObjectArray(num_results, clsScanResult, NULL); if (scanResults == NULL) { ALOGE("Error in allocating array"); return; } for (unsigned i = 0; i < num_results; i++) { jobject scanResult = createObject(env, "android/net/wifi/ScanResult"); if (scanResult == NULL) { ALOGE("Error in creating scan result"); return; } setStringField(env, scanResult, "SSID", results[i].ssid); char bssid[32]; sprintf(bssid, "%02x:%02x:%02x:%02x:%02x:%02x", results[i].bssid[0], results[i].bssid[1], results[i].bssid[2], results[i].bssid[3], results[i].bssid[4], results[i].bssid[5]); setStringField(env, scanResult, "BSSID", bssid); setIntField(env, scanResult, "level", results[i].rssi); setIntField(env, scanResult, "frequency", results[i].channel); setLongField(env, scanResult, "timestamp", results[i].ts); env->SetObjectArrayElement(scanResults, i, scanResult); ALOGD("Found AP %32s %s", results[i].ssid, bssid); } reportEvent(env, mCls, "onHotlistApFound", "(I[Landroid/net/wifi/ScanResult;)V", id, scanResults); }
/** * Fills in the fields of target (Java class Utimbuf) from the fields of source * (struct utimbuf). */ bool FUSE26Util::fillUtimbuf(JNIEnv *env, const struct utimbuf *source, jobject target) { CSLogTraceEnter("bool FUSE26Util::fillUtimbuf(%p, %p, %p)", env, source, target); bool ret = false; do { jclass clazz = env->GetObjectClass(target); if(clazz == NULL || env->ExceptionCheck() == JNI_TRUE) { CSLogError("Could not get object class!"); if(env->ExceptionCheck()) env->ExceptionDescribe(); break; } if(!setLongField(env, clazz, target, "actime", source->actime)) break; if(!setLongField(env, clazz, target, "modtime", source->modtime)) break; ret = true; } while(0); CSLogTraceLeave("bool FUSE26Util::fillUtimbuf(%p, %p, %p): %d", env, source, target, ret); return ret; }
bool FUSE26Util::fillFUSEFileInfo(JNIEnv *env, const struct fuse_file_info *fi, jobject ffiObject) { CSLogTraceEnter("bool FUSE26Util::fillFUSEFileInfo(%p, %p, %p)", env, fi, ffiObject); bool ret = false; do { jclass ffiClass = env->GetObjectClass(ffiObject); if(ffiClass == NULL || env->ExceptionCheck() == JNI_TRUE) { CSLogError("Could not get object class!"); if(env->ExceptionCheck()) env->ExceptionDescribe(); break; } if(!setIntField(env, ffiClass, ffiObject, "flags", fi->flags)) break; if(!setLongField(env, ffiClass, ffiObject, "fh_old", fi->fh_old)) break; if(!setIntField(env, ffiClass, ffiObject, "writepage", fi->writepage)) break; if(!setBooleanField(env, ffiClass, ffiObject, "direct_io", (fi->direct_io == 0 ? JNI_FALSE : JNI_TRUE))) break; if(!setBooleanField(env, ffiClass, ffiObject, "keep_cache", (fi->keep_cache == 0 ? JNI_FALSE : JNI_TRUE))) break; if(!setBooleanField(env, ffiClass, ffiObject, "flush", (fi->flush == 0 ? JNI_FALSE : JNI_TRUE))) break; if(!setLongField(env, ffiClass, ffiObject, "fh", fi->fh)) break; if(!setLongField(env, ffiClass, ffiObject, "lock_owner", fi->lock_owner)) break; ret = true; } while(0); CSLogTraceLeave("bool FUSE26Util::fillFUSEFileInfo(%p, %p, %p): %d", env, fi, ffiObject, ret); return ret; }
JNIEXPORT void JNICALL Java_org_alex73_android_common_JniWrapper_getPermissions (JNIEnv *env, jclass cl, jobject fi) { jobject path = getObjectField(env, fi, "path", "Ljava/lang/String;"); struct stat buf; const char *nativePath = (*env)->GetStringUTFChars(env, path, 0); int r=stat(nativePath, &buf); (*env)->ReleaseStringUTFChars(env, path, nativePath); if (r==0) { setLongField(env, fi, "perm", buf.st_mode); setLongField(env, fi, "owner", buf.st_uid); setLongField(env, fi, "group", buf.st_gid); } else { setLongField(env, fi, "perm", -1); setLongField(env, fi, "owner", -1); setLongField(env, fi, "group", -1); } }
static jobject android_net_wifi_getLinkLayerStats (JNIEnv *env, jclass cls, jint iface) { wifi_stats_result_handler handler; memset(&handler, 0, sizeof(handler)); handler.on_link_stats_results = &onLinkStatsResults; wifi_interface_handle handle = getIfaceHandle(env, cls, iface); int result = wifi_get_link_stats(0, handle, handler); if (result < 0) { ALOGE("android_net_wifi_getLinkLayerStats: failed to get link statistics\n"); return NULL; } jobject wifiLinkLayerStats = createObject(env, "android/net/wifi/WifiLinkLayerStats"); if (wifiLinkLayerStats == NULL) { ALOGE("Error in allocating wifiLinkLayerStats"); return NULL; } setIntField(env, wifiLinkLayerStats, "beacon_rx", link_stat.beacon_rx); setIntField(env, wifiLinkLayerStats, "rssi_mgmt", link_stat.rssi_mgmt); setLongField(env, wifiLinkLayerStats, "rxmpdu_be", link_stat.ac[WIFI_AC_BE].rx_mpdu); setLongField(env, wifiLinkLayerStats, "rxmpdu_bk", link_stat.ac[WIFI_AC_BK].rx_mpdu); setLongField(env, wifiLinkLayerStats, "rxmpdu_vi", link_stat.ac[WIFI_AC_VI].rx_mpdu); setLongField(env, wifiLinkLayerStats, "rxmpdu_vo", link_stat.ac[WIFI_AC_VO].rx_mpdu); setLongField(env, wifiLinkLayerStats, "txmpdu_be", link_stat.ac[WIFI_AC_BE].tx_mpdu); setLongField(env, wifiLinkLayerStats, "txmpdu_bk", link_stat.ac[WIFI_AC_BK].tx_mpdu); setLongField(env, wifiLinkLayerStats, "txmpdu_vi", link_stat.ac[WIFI_AC_VI].tx_mpdu); setLongField(env, wifiLinkLayerStats, "txmpdu_vo", link_stat.ac[WIFI_AC_VO].tx_mpdu); setLongField(env, wifiLinkLayerStats, "lostmpdu_be", link_stat.ac[WIFI_AC_BE].mpdu_lost); setLongField(env, wifiLinkLayerStats, "lostmpdu_bk", link_stat.ac[WIFI_AC_BK].mpdu_lost); setLongField(env, wifiLinkLayerStats, "lostmpdu_vi", link_stat.ac[WIFI_AC_VI].mpdu_lost); setLongField(env, wifiLinkLayerStats, "lostmpdu_vo", link_stat.ac[WIFI_AC_VO].mpdu_lost); setLongField(env, wifiLinkLayerStats, "retries_be", link_stat.ac[WIFI_AC_BE].retries); setLongField(env, wifiLinkLayerStats, "retries_bk", link_stat.ac[WIFI_AC_BK].retries); setLongField(env, wifiLinkLayerStats, "retries_vi", link_stat.ac[WIFI_AC_VI].retries); setLongField(env, wifiLinkLayerStats, "retries_vo", link_stat.ac[WIFI_AC_VO].retries); setIntField(env, wifiLinkLayerStats, "on_time", radio_stat.on_time); setIntField(env, wifiLinkLayerStats, "tx_time", radio_stat.tx_time); setIntField(env, wifiLinkLayerStats, "rx_time", radio_stat.rx_time); setIntField(env, wifiLinkLayerStats, "on_time_scan", radio_stat.on_time_scan); return wifiLinkLayerStats; }
bool FUSE26Util::fillStat(JNIEnv *env, const struct stat *st, jobject statObject) { CSLogTraceEnter("bool FUSE26Util::fillStat(%p, %p, %p)", env, st, statObject); bool ret = false; do { jclass statClass = env->GetObjectClass(statObject); if(statClass == NULL || env->ExceptionCheck() == JNI_TRUE) { CSLogError("Could not get object class!"); if(env->ExceptionCheck()) env->ExceptionDescribe(); break; } jobject st_atimespec; jobject st_mtimespec; jobject st_ctimespec; if(!getObjectField(env, statClass, statObject, "st_atimespec", JAVA_CLASS(TIMESPEC_CLASS), &st_atimespec)) break; if(!getObjectField(env, statClass, statObject, "st_mtimespec", JAVA_CLASS(TIMESPEC_CLASS), &st_mtimespec)) break; if(!getObjectField(env, statClass, statObject, "st_ctimespec", JAVA_CLASS(TIMESPEC_CLASS), &st_ctimespec)) break; if(!setLongField(env, statClass, statObject, "st_dev", st->st_dev)) break; if(!setLongField(env, statClass, statObject, "st_ino", st->st_ino)) break; if(!setLongField(env, statClass, statObject, "st_mode", st->st_mode)) break; if(!setLongField(env, statClass, statObject, "st_nlink", st->st_nlink)) break; if(!setLongField(env, statClass, statObject, "st_uid", st->st_uid)) break; if(!setLongField(env, statClass, statObject, "st_gid", st->st_gid)) break; if(!setLongField(env, statClass, statObject, "st_rdev", st->st_rdev)) break; #if defined(__linux__) || defined(__sun__) if(!FUSE26Util::fillTimespec(env, &(st->st_atim), st_atimespec)) break; if(!FUSE26Util::fillTimespec(env, &(st->st_mtim), st_mtimespec)) break; if(!FUSE26Util::fillTimespec(env, &(st->st_ctim), st_ctimespec)) break; #else if(!FUSE26Util::fillTimespec(env, &(st->st_atimespec), st_atimespec)) break; if(!FUSE26Util::fillTimespec(env, &(st->st_mtimespec), st_mtimespec)) break; if(!FUSE26Util::fillTimespec(env, &(st->st_ctimespec), st_ctimespec)) break; #endif if(!setLongField(env, statClass, statObject, "st_size", st->st_size)) break; if(!setLongField(env, statClass, statObject, "st_blocks", st->st_blocks)) break; if(!setLongField(env, statClass, statObject, "st_blocksize", st->st_blksize)) break; #if !defined(__linux__) && !defined(__sun__) if(!setLongField(env, statClass, statObject, "st_flags", st->st_flags)) break; if(!setLongField(env, statClass, statObject, "st_gen", st->st_gen)) break; #endif env->DeleteLocalRef(st_atimespec); env->DeleteLocalRef(st_mtimespec); env->DeleteLocalRef(st_ctimespec); ret = true; } while(0); CSLogTraceLeave("bool FUSE26Util::fillStat(%p, %p, %p): %d", env, st, statObject, ret); return ret; }
/** * Fills in the fields of target (Java class StatVFS) from the fields of source * (struct statvfs). */ bool FUSE26Util::fillStatVFS(JNIEnv *env, const struct statvfs *source, jobject target) { CSLogTraceEnter("bool FUSE26Util::fillStatVFS(%p, %p, %p)", env, source, target); bool ret = false; do { jclass clazz = env->GetObjectClass(target); if(clazz == NULL || env->ExceptionCheck() == JNI_TRUE) { CSLogError("Could not get object class!"); if(env->ExceptionCheck()) env->ExceptionDescribe(); break; } if(!setLongField(env, clazz, target, "f_bsize", source->f_bsize)) break; if(!setLongField(env, clazz, target, "f_frsize", source->f_frsize)) break; if(!setLongField(env, clazz, target, "f_blocks", source->f_blocks)) break; if(!setLongField(env, clazz, target, "f_bfree", source->f_bfree)) break; if(!setLongField(env, clazz, target, "f_bavail", source->f_bavail)) break; if(!setLongField(env, clazz, target, "f_files", source->f_files)) break; if(!setLongField(env, clazz, target, "f_ffree", source->f_ffree)) break; if(!setLongField(env, clazz, target, "f_favail", source->f_favail)) break; if(!setLongField(env, clazz, target, "f_fsid", source->f_fsid)) break; if(!setLongField(env, clazz, target, "f_flag", source->f_flag)) break; if(!setLongField(env, clazz, target, "f_namemax", source->f_namemax)) break; ret = true; } while(0); CSLogTraceLeave("bool FUSE26Util::fillStatVFS(%p, %p, %p): %d", env, source, target, ret); return ret; }
void initDevice(JNIEnv * env, jobject this_ref, jint max_blocks_per_proc, jint max_threads_per_block, jlong free_space) { int status; jint num_blocks; int deviceCount = 0; size_t f_mem; size_t t_mem; size_t to_space_size; textureMemSize = 1; status = cuDeviceGetCount(&deviceCount); CHECK_STATUS(env,"error in cuDeviceGetCount",status) getBestDevice(env); status = cuCtxCreate(&cuContext, CU_CTX_MAP_HOST, cuDevice); CHECK_STATUS(env,"error in cuCtxCreate",status) status = cuMemGetInfo (&f_mem, &t_mem); CHECK_STATUS(env,"error in cuMemGetInfo",status) to_space_size = f_mem; num_blocks = numMultiProcessors * max_threads_per_block * max_blocks_per_proc; #if DEBUG printf("Memory: %i(MB)/%i(MB) (Free/Total)\n",f_mem/1024/1024, t_mem/1024/1024); printf("num_blocks = %i\n",num_blocks); printf("numMultiProcessors = %i\n",numMultiProcessors); printf("max_threads_per_block = %i\n",max_threads_per_block); printf("max_blocks_per_proc = %i\n",max_blocks_per_proc); fflush(stdout); #endif //space for 100 types in the scene classMemSize = sizeof(jint)*100; gc_space_size = 1024; to_space_size -= (num_blocks * sizeof(jlong)); to_space_size -= (num_blocks * sizeof(jlong)); to_space_size -= gc_space_size; to_space_size -= free_space; to_space_size -= classMemSize; //to_space_size -= textureMemSize; bufferSize = to_space_size; status = cuMemHostAlloc(&toSpace, to_space_size, 0); CHECK_STATUS(env,"toSpace memory allocation failed",status) status = cuMemAlloc(&gpuToSpace, to_space_size); CHECK_STATUS(env,"gpuToSpace memory allocation failed",status) status = cuMemAlloc(&gpuClassMemory, classMemSize); CHECK_STATUS(env,"gpuClassMemory memory allocation failed",status) /* status = cuMemHostAlloc(&textureMemory, textureMemSize, 0); if (CUDA_SUCCESS != status) { printf("error in cuMemHostAlloc textureMemory %d\n", status); } status = cuMemAlloc(&gpuTexture, textureMemSize); if (CUDA_SUCCESS != status) { printf("error in cuMemAlloc gpuTexture %d\n", status); } */ status = cuMemHostAlloc(&handlesMemory, num_blocks * sizeof(jlong), CU_MEMHOSTALLOC_WRITECOMBINED); CHECK_STATUS(env,"handlesMemory memory allocation failed",status) status = cuMemAlloc(&gpuHandlesMemory, num_blocks * sizeof(jlong)); CHECK_STATUS(env,"gpuHandlesMemory memory allocation failed",status) status = cuMemHostAlloc(&exceptionsMemory, num_blocks * sizeof(jlong), 0); CHECK_STATUS(env,"exceptionsMemory memory allocation failed",status) status = cuMemAlloc(&gpuExceptionsMemory, num_blocks * sizeof(jlong)); CHECK_STATUS(env,"gpuExceptionsMemory memory allocation failed",status) status = cuMemAlloc(&gcInfoSpace, gc_space_size); CHECK_STATUS(env,"gcInfoSpace memory allocation failed",status) status = cuMemAlloc(&gpuHeapEndPtr, 8); CHECK_STATUS(env,"gpuHeapEndPtr memory allocation failed",status) status = cuMemAlloc(&gpuBufferSize, 8); CHECK_STATUS(env,"gpuBufferSize memory allocation failed",status) thisRefClass = (*env)->GetObjectClass(env, this_ref); setLongField(env, this_ref, "m_ToSpaceAddr", (jlong) toSpace); setLongField(env, this_ref, "m_GpuToSpaceAddr", (jlong) gpuToSpace); setLongField(env, this_ref, "m_TextureAddr", (jlong) textureMemory); setLongField(env, this_ref, "m_GpuTextureAddr", (jlong) gpuTexture); setLongField(env, this_ref, "m_HandlesAddr", (jlong) handlesMemory); setLongField(env, this_ref, "m_GpuHandlesAddr", (jlong) gpuHandlesMemory); setLongField(env, this_ref, "m_ExceptionsHandlesAddr", (jlong) exceptionsMemory); setLongField(env, this_ref, "m_GpuExceptionsHandlesAddr", (jlong) gpuExceptionsMemory); setLongField(env, this_ref, "m_ToSpaceSize", (jlong) bufferSize); setLongField(env, this_ref, "m_MaxGridDim", (jlong) maxGridDim); setLongField(env, this_ref, "m_NumMultiProcessors", (jlong) numMultiProcessors); }
/* * Class: edu_syr_pcpratts_rootbeer_runtime2_cuda_CudaRuntime2 * Method: setup * Signature: ()V */ JNIEXPORT void JNICALL Java_edu_syr_pcpratts_rootbeer_runtime2_cuda_CudaRuntime2_setup (JNIEnv *env, jobject this_ref, jint max_blocks_per_proc, jint max_threads_per_block, jint free_space) { int status; jint num_blocks; int deviceCount = 0; size_t f_mem; size_t t_mem; size_t to_space_size; //size_t free_space = 1530L*1024L*1024L; textureMemSize = 1; status = cuInit(0); if (CUDA_SUCCESS != status) { printf("error in cuInit\n"); } status = cuDeviceGetCount(&deviceCount); if (CUDA_SUCCESS != status) { printf("error in cuDeviceGet\n"); } getBestDevice(); status = cuCtxCreate(&cuContext, CU_CTX_MAP_HOST, cuDevice); if (CUDA_SUCCESS != status) { printf("error in cuCtxCreate %d\n", status); } // ddb - not using this as this returns the total memory not the free memory //to_space_size = memSize(); cuMemGetInfo(&f_mem, &t_mem); to_space_size = f_mem; num_blocks = numMultiProcessors * max_threads_per_block * max_blocks_per_proc; #if DEBUG printf("Memory: %i(MB)/%i(MB) (Free/Total)\n",f_mem/1024/1024, t_mem/1024/1024); printf("num_blocks = %i\n",num_blocks); printf("numMultiProcessors = %i\n",numMultiProcessors); printf("max_threads_per_block = %i\n",max_threads_per_block); printf("max_blocks_per_proc = %i\n",max_blocks_per_proc); fflush(stdout); #endif gc_space_size = 1024; to_space_size -= (num_blocks * sizeof(jlong)); to_space_size -= (num_blocks * sizeof(jlong)); to_space_size -= gc_space_size; to_space_size -= free_space; //to_space_size -= textureMemSize; bufferSize = to_space_size; status = cuMemHostAlloc(&toSpace, to_space_size, 0); if (CUDA_SUCCESS != status) { throw_cuda_errror_exception(env, "toSpace memory allocation failed", status); return; } status = cuMemAlloc(&gpuToSpace, to_space_size); if (CUDA_SUCCESS != status) { throw_cuda_errror_exception(env, "gpuToSpace memory allocation failed", status); return; } /* status = cuMemHostAlloc(&textureMemory, textureMemSize, 0); if (CUDA_SUCCESS != status) { printf("error in cuMemHostAlloc textureMemory %d\n", status); } status = cuMemAlloc(&gpuTexture, textureMemSize); if (CUDA_SUCCESS != status) { printf("error in cuMemAlloc gpuTexture %d\n", status); } */ status = cuMemHostAlloc(&handlesMemory, num_blocks * sizeof(jlong), CU_MEMHOSTALLOC_WRITECOMBINED); if (CUDA_SUCCESS != status) { throw_cuda_errror_exception(env, "handlesMemory memory allocation failed", status); return; } status = cuMemAlloc(&gpuHandlesMemory, num_blocks * sizeof(jlong)); if (CUDA_SUCCESS != status) { throw_cuda_errror_exception(env, "gpuHandlesMemory memory allocation failed", status); return; } status = cuMemHostAlloc(&exceptionsMemory, num_blocks * sizeof(jlong), 0); if (CUDA_SUCCESS != status) { throw_cuda_errror_exception(env, "exceptionsMemory memory allocation failed", status); return; } status = cuMemAlloc(&gpuExceptionsMemory, num_blocks * sizeof(jlong)); if (CUDA_SUCCESS != status) { throw_cuda_errror_exception(env, "gpuExceptionsMemory memory allocation failed", status); return; } status = cuMemAlloc(&gcInfoSpace, gc_space_size); if (CUDA_SUCCESS != status) { throw_cuda_errror_exception(env, "gcInfoSpace memory allocation failed", status); return; } status = cuMemAlloc(&gpuHeapEndPtr, 8); if (CUDA_SUCCESS != status) { throw_cuda_errror_exception(env, "gpuHeapEndPtr memory allocation failed", status); return; } status = cuMemAlloc(&gpuBufferSize, 8); if (CUDA_SUCCESS != status) { throw_cuda_errror_exception(env, "gpuBufferSize memory allocation failed", status); return; } thisRefClass = (*env)->GetObjectClass(env, this_ref); setLongField(env, this_ref, "m_ToSpaceAddr", (jlong) toSpace); setLongField(env, this_ref, "m_GpuToSpaceAddr", (jlong) gpuToSpace); setLongField(env, this_ref, "m_TextureAddr", (jlong) textureMemory); setLongField(env, this_ref, "m_GpuTextureAddr", (jlong) gpuTexture); setLongField(env, this_ref, "m_HandlesAddr", (jlong) handlesMemory); setLongField(env, this_ref, "m_GpuHandlesAddr", (jlong) gpuHandlesMemory); setLongField(env, this_ref, "m_ExceptionsHandlesAddr", (jlong) exceptionsMemory); setLongField(env, this_ref, "m_GpuExceptionsHandlesAddr", (jlong) gpuExceptionsMemory); setLongField(env, this_ref, "m_ToSpaceSize", (jlong) bufferSize); setLongField(env, this_ref, "m_MaxGridDim", (jlong) maxGridDim); setLongField(env, this_ref, "m_NumMultiProcessors", (jlong) numMultiProcessors); }