From e79c875fe2c656a6a4401115a4f4d24c69dfc0f0 Mon Sep 17 00:00:00 2001 From: Alexander Smorkalov Date: Wed, 25 Dec 2013 17:10:50 +0400 Subject: [PATCH 1/2] Java wrappers for functions from cv::gpu namespace in core module added. --- modules/java/generator/src/cpp/gpu.cpp | 770 ++++++++++++++++++ .../generator/src/java/gpu+DeviceInfo.java | 245 ++++++ modules/java/generator/src/java/gpu+Gpu.java | 128 +++ .../generator/src/java/gpu+TargetArchs.java | 141 ++++ 4 files changed, 1284 insertions(+) create mode 100644 modules/java/generator/src/cpp/gpu.cpp create mode 100644 modules/java/generator/src/java/gpu+DeviceInfo.java create mode 100644 modules/java/generator/src/java/gpu+Gpu.java create mode 100644 modules/java/generator/src/java/gpu+TargetArchs.java diff --git a/modules/java/generator/src/cpp/gpu.cpp b/modules/java/generator/src/cpp/gpu.cpp new file mode 100644 index 0000000000..f4b872b927 --- /dev/null +++ b/modules/java/generator/src/cpp/gpu.cpp @@ -0,0 +1,770 @@ +#define LOG_TAG "org.opencv.gpu" + +#include "common.h" + +#include "opencv2/opencv_modules.hpp" +#include "opencv2/core/gpumat.hpp" + +using namespace cv; +using namespace cv::gpu; + +/// throw java exception +static void throwJavaException(JNIEnv *env, const std::exception *e, const char *method) { + std::string what = "unknown exception"; + jclass je = 0; + + if(e) { + std::string exception_type = "std::exception"; + + if(dynamic_cast(e)) { + exception_type = "cv::Exception"; + je = env->FindClass("org/opencv/core/CvException"); + } + + what = exception_type + ": " + e->what(); + } + + if(!je) je = env->FindClass("java/lang/Exception"); + env->ThrowNew(je, what.c_str()); + + LOGE("%s caught %s", method, what.c_str()); + (void)method; // avoid "unused" warning +} + + +extern "C" { + + +// +// bool deviceSupports(cv::gpu::FeatureSet feature_set) +// + +JNIEXPORT jboolean JNICALL Java_org_opencv_gpu_Gpu_deviceSupports_10 (JNIEnv*, jclass, jint); + +JNIEXPORT jboolean JNICALL Java_org_opencv_gpu_Gpu_deviceSupports_10 + (JNIEnv* env, jclass , jint feature_set) +{ + static const char method_name[] = "gpu::deviceSupports_10()"; + try { + LOGD("%s", method_name); + + bool _retval_ = deviceSupports( (cv::gpu::FeatureSet)feature_set ); + return _retval_; + } catch(const std::exception &e) { + throwJavaException(env, &e, method_name); + } catch (...) { + throwJavaException(env, 0, method_name); + } + return 0; +} + + + +// +// int getCudaEnabledDeviceCount() +// + +JNIEXPORT jint JNICALL Java_org_opencv_gpu_Gpu_getCudaEnabledDeviceCount_10 (JNIEnv*, jclass); + +JNIEXPORT jint JNICALL Java_org_opencv_gpu_Gpu_getCudaEnabledDeviceCount_10 + (JNIEnv* env, jclass ) +{ + static const char method_name[] = "gpu::getCudaEnabledDeviceCount_10()"; + try { + LOGD("%s", method_name); + + int _retval_ = getCudaEnabledDeviceCount( ); + return _retval_; + } catch(const std::exception &e) { + throwJavaException(env, &e, method_name); + } catch (...) { + throwJavaException(env, 0, method_name); + } + return 0; +} + + + +// +// int getDevice() +// + +JNIEXPORT jint JNICALL Java_org_opencv_gpu_Gpu_getDevice_10 (JNIEnv*, jclass); + +JNIEXPORT jint JNICALL Java_org_opencv_gpu_Gpu_getDevice_10 + (JNIEnv* env, jclass ) +{ + static const char method_name[] = "gpu::getDevice_10()"; + try { + LOGD("%s", method_name); + + int _retval_ = getDevice( ); + return _retval_; + } catch(const std::exception &e) { + throwJavaException(env, &e, method_name); + } catch (...) { + throwJavaException(env, 0, method_name); + } + return 0; +} + + + +// +// void printCudaDeviceInfo(int device) +// + +JNIEXPORT void JNICALL Java_org_opencv_gpu_Gpu_printCudaDeviceInfo_10 (JNIEnv*, jclass, jint); + +JNIEXPORT void JNICALL Java_org_opencv_gpu_Gpu_printCudaDeviceInfo_10 + (JNIEnv* env, jclass , jint device) +{ + static const char method_name[] = "gpu::printCudaDeviceInfo_10()"; + try { + LOGD("%s", method_name); + + printCudaDeviceInfo( (int)device ); + return; + } catch(const std::exception &e) { + throwJavaException(env, &e, method_name); + } catch (...) { + throwJavaException(env, 0, method_name); + } + return; +} + + + +// +// void printShortCudaDeviceInfo(int device) +// + +JNIEXPORT void JNICALL Java_org_opencv_gpu_Gpu_printShortCudaDeviceInfo_10 (JNIEnv*, jclass, jint); + +JNIEXPORT void JNICALL Java_org_opencv_gpu_Gpu_printShortCudaDeviceInfo_10 + (JNIEnv* env, jclass , jint device) +{ + static const char method_name[] = "gpu::printShortCudaDeviceInfo_10()"; + try { + LOGD("%s", method_name); + + printShortCudaDeviceInfo( (int)device ); + return; + } catch(const std::exception &e) { + throwJavaException(env, &e, method_name); + } catch (...) { + throwJavaException(env, 0, method_name); + } + return; +} + + + +// +// void resetDevice() +// + +JNIEXPORT void JNICALL Java_org_opencv_gpu_Gpu_resetDevice_10 (JNIEnv*, jclass); + +JNIEXPORT void JNICALL Java_org_opencv_gpu_Gpu_resetDevice_10 + (JNIEnv* env, jclass ) +{ + static const char method_name[] = "gpu::resetDevice_10()"; + try { + LOGD("%s", method_name); + + resetDevice(); + return; + } catch(const std::exception &e) { + throwJavaException(env, &e, method_name); + } catch (...) { + throwJavaException(env, 0, method_name); + } + return; +} + + + +// +// void setDevice(int device) +// + +JNIEXPORT void JNICALL Java_org_opencv_gpu_Gpu_setDevice_10 (JNIEnv*, jclass, jint); + +JNIEXPORT void JNICALL Java_org_opencv_gpu_Gpu_setDevice_10 + (JNIEnv* env, jclass , jint device) +{ + static const char method_name[] = "gpu::setDevice_10()"; + try { + LOGD("%s", method_name); + + setDevice( (int)device ); + return; + } catch(const std::exception &e) { + throwJavaException(env, &e, method_name); + } catch (...) { + throwJavaException(env, 0, method_name); + } + return; +} + + + +// +// DeviceInfo::DeviceInfo() +// + +JNIEXPORT jlong JNICALL Java_org_opencv_gpu_DeviceInfo_DeviceInfo_10 (JNIEnv*, jclass); + +JNIEXPORT jlong JNICALL Java_org_opencv_gpu_DeviceInfo_DeviceInfo_10 + (JNIEnv* env, jclass ) +{ + static const char method_name[] = "gpu::DeviceInfo_10()"; + try { + LOGD("%s", method_name); + + DeviceInfo* _retval_ = new DeviceInfo( ); + return (jlong) _retval_; + } catch(const std::exception &e) { + throwJavaException(env, &e, method_name); + } catch (...) { + throwJavaException(env, 0, method_name); + } + return 0; +} + + + +// +// DeviceInfo::DeviceInfo(int device_id) +// + +JNIEXPORT jlong JNICALL Java_org_opencv_gpu_DeviceInfo_DeviceInfo_11 (JNIEnv*, jclass, jint); + +JNIEXPORT jlong JNICALL Java_org_opencv_gpu_DeviceInfo_DeviceInfo_11 + (JNIEnv* env, jclass , jint device_id) +{ + static const char method_name[] = "gpu::DeviceInfo_11()"; + try { + LOGD("%s", method_name); + + DeviceInfo* _retval_ = new DeviceInfo( (int)device_id ); + return (jlong) _retval_; + } catch(const std::exception &e) { + throwJavaException(env, &e, method_name); + } catch (...) { + throwJavaException(env, 0, method_name); + } + return 0; +} + + + +// +// int DeviceInfo::deviceID() +// + +JNIEXPORT jint JNICALL Java_org_opencv_gpu_DeviceInfo_deviceID_10 (JNIEnv*, jclass, jlong); + +JNIEXPORT jint JNICALL Java_org_opencv_gpu_DeviceInfo_deviceID_10 + (JNIEnv* env, jclass , jlong self) +{ + static const char method_name[] = "gpu::deviceID_10()"; + try { + LOGD("%s", method_name); + DeviceInfo* me = (DeviceInfo*) self; //TODO: check for NULL + int _retval_ = me->deviceID( ); + return _retval_; + } catch(const std::exception &e) { + throwJavaException(env, &e, method_name); + } catch (...) { + throwJavaException(env, 0, method_name); + } + return 0; +} + + + +// +// size_t DeviceInfo::freeMemory() +// + +JNIEXPORT jlong JNICALL Java_org_opencv_gpu_DeviceInfo_freeMemory_10 (JNIEnv*, jclass, jlong); + +JNIEXPORT jlong JNICALL Java_org_opencv_gpu_DeviceInfo_freeMemory_10 + (JNIEnv* env, jclass , jlong self) +{ + static const char method_name[] = "gpu::freeMemory_10()"; + try { + LOGD("%s", method_name); + DeviceInfo* me = (DeviceInfo*) self; //TODO: check for NULL + size_t _retval_ = me->freeMemory( ); + return _retval_; + } catch(const std::exception &e) { + throwJavaException(env, &e, method_name); + } catch (...) { + throwJavaException(env, 0, method_name); + } + return 0; +} + + + +// +// bool DeviceInfo::isCompatible() +// + +JNIEXPORT jboolean JNICALL Java_org_opencv_gpu_DeviceInfo_isCompatible_10 (JNIEnv*, jclass, jlong); + +JNIEXPORT jboolean JNICALL Java_org_opencv_gpu_DeviceInfo_isCompatible_10 + (JNIEnv* env, jclass , jlong self) +{ + static const char method_name[] = "gpu::isCompatible_10()"; + try { + LOGD("%s", method_name); + DeviceInfo* me = (DeviceInfo*) self; //TODO: check for NULL + bool _retval_ = me->isCompatible( ); + return _retval_; + } catch(const std::exception &e) { + throwJavaException(env, &e, method_name); + } catch (...) { + throwJavaException(env, 0, method_name); + } + return 0; +} + + + +// +// int DeviceInfo::majorVersion() +// + +JNIEXPORT jint JNICALL Java_org_opencv_gpu_DeviceInfo_majorVersion_10 (JNIEnv*, jclass, jlong); + +JNIEXPORT jint JNICALL Java_org_opencv_gpu_DeviceInfo_majorVersion_10 + (JNIEnv* env, jclass , jlong self) +{ + static const char method_name[] = "gpu::majorVersion_10()"; + try { + LOGD("%s", method_name); + DeviceInfo* me = (DeviceInfo*) self; //TODO: check for NULL + int _retval_ = me->majorVersion( ); + return _retval_; + } catch(const std::exception &e) { + throwJavaException(env, &e, method_name); + } catch (...) { + throwJavaException(env, 0, method_name); + } + return 0; +} + + + +// +// int DeviceInfo::minorVersion() +// + +JNIEXPORT jint JNICALL Java_org_opencv_gpu_DeviceInfo_minorVersion_10 (JNIEnv*, jclass, jlong); + +JNIEXPORT jint JNICALL Java_org_opencv_gpu_DeviceInfo_minorVersion_10 + (JNIEnv* env, jclass , jlong self) +{ + static const char method_name[] = "gpu::minorVersion_10()"; + try { + LOGD("%s", method_name); + DeviceInfo* me = (DeviceInfo*) self; //TODO: check for NULL + int _retval_ = me->minorVersion( ); + return _retval_; + } catch(const std::exception &e) { + throwJavaException(env, &e, method_name); + } catch (...) { + throwJavaException(env, 0, method_name); + } + return 0; +} + + + +// +// int DeviceInfo::multiProcessorCount() +// + +JNIEXPORT jint JNICALL Java_org_opencv_gpu_DeviceInfo_multiProcessorCount_10 (JNIEnv*, jclass, jlong); + +JNIEXPORT jint JNICALL Java_org_opencv_gpu_DeviceInfo_multiProcessorCount_10 + (JNIEnv* env, jclass , jlong self) +{ + static const char method_name[] = "gpu::multiProcessorCount_10()"; + try { + LOGD("%s", method_name); + DeviceInfo* me = (DeviceInfo*) self; //TODO: check for NULL + int _retval_ = me->multiProcessorCount( ); + return _retval_; + } catch(const std::exception &e) { + throwJavaException(env, &e, method_name); + } catch (...) { + throwJavaException(env, 0, method_name); + } + return 0; +} + + + +// +// string DeviceInfo::name() +// + +JNIEXPORT jstring JNICALL Java_org_opencv_gpu_DeviceInfo_name_10 (JNIEnv*, jclass, jlong); + +JNIEXPORT jstring JNICALL Java_org_opencv_gpu_DeviceInfo_name_10 + (JNIEnv* env, jclass , jlong self) +{ + static const char method_name[] = "gpu::name_10()"; + try { + LOGD("%s", method_name); + DeviceInfo* me = (DeviceInfo*) self; //TODO: check for NULL + string _retval_ = me->name( ); + return env->NewStringUTF(_retval_.c_str()); + } catch(const std::exception &e) { + throwJavaException(env, &e, method_name); + } catch (...) { + throwJavaException(env, 0, method_name); + } + return env->NewStringUTF(""); +} + + + +// +// void DeviceInfo::queryMemory(size_t& totalMemory, size_t& freeMemory) +// + +JNIEXPORT void JNICALL Java_org_opencv_gpu_DeviceInfo_queryMemory_10 (JNIEnv*, jclass, jlong, jdoubleArray, jdoubleArray); + +JNIEXPORT void JNICALL Java_org_opencv_gpu_DeviceInfo_queryMemory_10 +(JNIEnv* env, jclass , jlong self, jdoubleArray totalMemory_out, jdoubleArray freeMemory_out) +{ + static const char method_name[] = "gpu::queryMemory_10()"; + try { + LOGD("%s", method_name); + DeviceInfo* me = (DeviceInfo*) self; //TODO: check for NULL + size_t totalMemory; + size_t freeMemory; + me->queryMemory( totalMemory, freeMemory ); + jdouble tmp_totalMemory[1] = {totalMemory}; + env->SetDoubleArrayRegion(totalMemory_out, 0, 1, tmp_totalMemory); + jdouble tmp_freeMemory[1] = {freeMemory}; + env->SetDoubleArrayRegion(freeMemory_out, 0, 1, tmp_freeMemory); + return; + } catch(const std::exception &e) { + throwJavaException(env, &e, method_name); + } catch (...) { + throwJavaException(env, 0, method_name); + } + return; +} + + + +// +// size_t DeviceInfo::sharedMemPerBlock() +// + +JNIEXPORT jlong JNICALL Java_org_opencv_gpu_DeviceInfo_sharedMemPerBlock_10 (JNIEnv*, jclass, jlong); + +JNIEXPORT jlong JNICALL Java_org_opencv_gpu_DeviceInfo_sharedMemPerBlock_10 + (JNIEnv* env, jclass , jlong self) +{ + static const char method_name[] = "gpu::sharedMemPerBlock_10()"; + try { + LOGD("%s", method_name); + DeviceInfo* me = (DeviceInfo*) self; //TODO: check for NULL + size_t _retval_ = me->sharedMemPerBlock( ); + return _retval_; + } catch(const std::exception &e) { + throwJavaException(env, &e, method_name); + } catch (...) { + throwJavaException(env, 0, method_name); + } + return 0; +} + + + +// +// bool DeviceInfo::supports(cv::gpu::FeatureSet feature_set) +// + +JNIEXPORT jboolean JNICALL Java_org_opencv_gpu_DeviceInfo_supports_10 (JNIEnv*, jclass, jlong, jint); + +JNIEXPORT jboolean JNICALL Java_org_opencv_gpu_DeviceInfo_supports_10 + (JNIEnv* env, jclass , jlong self, jint feature_set) +{ + static const char method_name[] = "gpu::supports_10()"; + try { + LOGD("%s", method_name); + DeviceInfo* me = (DeviceInfo*) self; //TODO: check for NULL + bool _retval_ = me->supports( (cv::gpu::FeatureSet)feature_set ); + return _retval_; + } catch(const std::exception &e) { + throwJavaException(env, &e, method_name); + } catch (...) { + throwJavaException(env, 0, method_name); + } + return 0; +} + + + +// +// size_t DeviceInfo::totalMemory() +// + +JNIEXPORT jlong JNICALL Java_org_opencv_gpu_DeviceInfo_totalMemory_10 (JNIEnv*, jclass, jlong); + +JNIEXPORT jlong JNICALL Java_org_opencv_gpu_DeviceInfo_totalMemory_10 + (JNIEnv* env, jclass , jlong self) +{ + static const char method_name[] = "gpu::totalMemory_10()"; + try { + LOGD("%s", method_name); + DeviceInfo* me = (DeviceInfo*) self; //TODO: check for NULL + size_t _retval_ = me->totalMemory( ); + return _retval_; + } catch(const std::exception &e) { + throwJavaException(env, &e, method_name); + } catch (...) { + throwJavaException(env, 0, method_name); + } + return 0; +} + + + +// +// native support for java finalize() +// static void DeviceInfo::delete( __int64 self ) +// +JNIEXPORT void JNICALL Java_org_opencv_gpu_DeviceInfo_delete(JNIEnv*, jclass, jlong); + +JNIEXPORT void JNICALL Java_org_opencv_gpu_DeviceInfo_delete + (JNIEnv*, jclass, jlong self) +{ + delete (DeviceInfo*) self; +} + + +// +// static bool TargetArchs::builtWith(cv::gpu::FeatureSet feature_set) +// + +JNIEXPORT jboolean JNICALL Java_org_opencv_gpu_TargetArchs_builtWith_10 (JNIEnv*, jclass, jint); + +JNIEXPORT jboolean JNICALL Java_org_opencv_gpu_TargetArchs_builtWith_10 + (JNIEnv* env, jclass , jint feature_set) +{ + static const char method_name[] = "gpu::builtWith_10()"; + try { + LOGD("%s", method_name); + + bool _retval_ = TargetArchs::builtWith( (cv::gpu::FeatureSet)feature_set ); + return _retval_; + } catch(const std::exception &e) { + throwJavaException(env, &e, method_name); + } catch (...) { + throwJavaException(env, 0, method_name); + } + return 0; +} + + + +// +// static bool TargetArchs::has(int major, int minor) +// + +JNIEXPORT jboolean JNICALL Java_org_opencv_gpu_TargetArchs_has_10 (JNIEnv*, jclass, jint, jint); + +JNIEXPORT jboolean JNICALL Java_org_opencv_gpu_TargetArchs_has_10 + (JNIEnv* env, jclass , jint major, jint minor) +{ + static const char method_name[] = "gpu::has_10()"; + try { + LOGD("%s", method_name); + + bool _retval_ = TargetArchs::has( (int)major, (int)minor ); + return _retval_; + } catch(const std::exception &e) { + throwJavaException(env, &e, method_name); + } catch (...) { + throwJavaException(env, 0, method_name); + } + return 0; +} + + + +// +// static bool TargetArchs::hasBin(int major, int minor) +// + +JNIEXPORT jboolean JNICALL Java_org_opencv_gpu_TargetArchs_hasBin_10 (JNIEnv*, jclass, jint, jint); + +JNIEXPORT jboolean JNICALL Java_org_opencv_gpu_TargetArchs_hasBin_10 + (JNIEnv* env, jclass , jint major, jint minor) +{ + static const char method_name[] = "gpu::hasBin_10()"; + try { + LOGD("%s", method_name); + + bool _retval_ = TargetArchs::hasBin( (int)major, (int)minor ); + return _retval_; + } catch(const std::exception &e) { + throwJavaException(env, &e, method_name); + } catch (...) { + throwJavaException(env, 0, method_name); + } + return 0; +} + + + +// +// static bool TargetArchs::hasEqualOrGreater(int major, int minor) +// + +JNIEXPORT jboolean JNICALL Java_org_opencv_gpu_TargetArchs_hasEqualOrGreater_10 (JNIEnv*, jclass, jint, jint); + +JNIEXPORT jboolean JNICALL Java_org_opencv_gpu_TargetArchs_hasEqualOrGreater_10 + (JNIEnv* env, jclass , jint major, jint minor) +{ + static const char method_name[] = "gpu::hasEqualOrGreater_10()"; + try { + LOGD("%s", method_name); + + bool _retval_ = TargetArchs::hasEqualOrGreater( (int)major, (int)minor ); + return _retval_; + } catch(const std::exception &e) { + throwJavaException(env, &e, method_name); + } catch (...) { + throwJavaException(env, 0, method_name); + } + return 0; +} + + + +// +// static bool TargetArchs::hasEqualOrGreaterBin(int major, int minor) +// + +JNIEXPORT jboolean JNICALL Java_org_opencv_gpu_TargetArchs_hasEqualOrGreaterBin_10 (JNIEnv*, jclass, jint, jint); + +JNIEXPORT jboolean JNICALL Java_org_opencv_gpu_TargetArchs_hasEqualOrGreaterBin_10 + (JNIEnv* env, jclass , jint major, jint minor) +{ + static const char method_name[] = "gpu::hasEqualOrGreaterBin_10()"; + try { + LOGD("%s", method_name); + + bool _retval_ = TargetArchs::hasEqualOrGreaterBin( (int)major, (int)minor ); + return _retval_; + } catch(const std::exception &e) { + throwJavaException(env, &e, method_name); + } catch (...) { + throwJavaException(env, 0, method_name); + } + return 0; +} + + + +// +// static bool TargetArchs::hasEqualOrGreaterPtx(int major, int minor) +// + +JNIEXPORT jboolean JNICALL Java_org_opencv_gpu_TargetArchs_hasEqualOrGreaterPtx_10 (JNIEnv*, jclass, jint, jint); + +JNIEXPORT jboolean JNICALL Java_org_opencv_gpu_TargetArchs_hasEqualOrGreaterPtx_10 + (JNIEnv* env, jclass , jint major, jint minor) +{ + static const char method_name[] = "gpu::hasEqualOrGreaterPtx_10()"; + try { + LOGD("%s", method_name); + + bool _retval_ = TargetArchs::hasEqualOrGreaterPtx( (int)major, (int)minor ); + return _retval_; + } catch(const std::exception &e) { + throwJavaException(env, &e, method_name); + } catch (...) { + throwJavaException(env, 0, method_name); + } + return 0; +} + + + +// +// static bool TargetArchs::hasEqualOrLessPtx(int major, int minor) +// + +JNIEXPORT jboolean JNICALL Java_org_opencv_gpu_TargetArchs_hasEqualOrLessPtx_10 (JNIEnv*, jclass, jint, jint); + +JNIEXPORT jboolean JNICALL Java_org_opencv_gpu_TargetArchs_hasEqualOrLessPtx_10 + (JNIEnv* env, jclass , jint major, jint minor) +{ + static const char method_name[] = "gpu::hasEqualOrLessPtx_10()"; + try { + LOGD("%s", method_name); + + bool _retval_ = TargetArchs::hasEqualOrLessPtx( (int)major, (int)minor ); + return _retval_; + } catch(const std::exception &e) { + throwJavaException(env, &e, method_name); + } catch (...) { + throwJavaException(env, 0, method_name); + } + return 0; +} + + + +// +// static bool TargetArchs::hasPtx(int major, int minor) +// + +JNIEXPORT jboolean JNICALL Java_org_opencv_gpu_TargetArchs_hasPtx_10 (JNIEnv*, jclass, jint, jint); + +JNIEXPORT jboolean JNICALL Java_org_opencv_gpu_TargetArchs_hasPtx_10 + (JNIEnv* env, jclass , jint major, jint minor) +{ + static const char method_name[] = "gpu::hasPtx_10()"; + try { + LOGD("%s", method_name); + + bool _retval_ = TargetArchs::hasPtx( (int)major, (int)minor ); + return _retval_; + } catch(const std::exception &e) { + throwJavaException(env, &e, method_name); + } catch (...) { + throwJavaException(env, 0, method_name); + } + return 0; +} + + + +// +// native support for java finalize() +// static void TargetArchs::delete( __int64 self ) +// +JNIEXPORT void JNICALL Java_org_opencv_gpu_TargetArchs_delete(JNIEnv*, jclass, jlong); + +JNIEXPORT void JNICALL Java_org_opencv_gpu_TargetArchs_delete + (JNIEnv*, jclass, jlong self) +{ + delete (TargetArchs*) self; +} + + +} // extern "C" diff --git a/modules/java/generator/src/java/gpu+DeviceInfo.java b/modules/java/generator/src/java/gpu+DeviceInfo.java new file mode 100644 index 0000000000..ab6d339c0b --- /dev/null +++ b/modules/java/generator/src/java/gpu+DeviceInfo.java @@ -0,0 +1,245 @@ +package org.opencv.gpu; + +import java.lang.String; + +// C++: class DeviceInfo +//javadoc: DeviceInfo +public class DeviceInfo { + + protected final long nativeObj; + protected DeviceInfo(long addr) { nativeObj = addr; } + + + // + // C++: DeviceInfo::DeviceInfo() + // + + //javadoc: DeviceInfo::DeviceInfo() + public DeviceInfo() + { + + nativeObj = DeviceInfo_0(); + + return; + } + + + // + // C++: DeviceInfo::DeviceInfo(int device_id) + // + + //javadoc: DeviceInfo::DeviceInfo(device_id) + public DeviceInfo(int device_id) + { + + nativeObj = DeviceInfo_1(device_id); + + return; + } + + + // + // C++: int DeviceInfo::deviceID() + // + + //javadoc: DeviceInfo::deviceID() + public int deviceID() + { + + int retVal = deviceID_0(nativeObj); + + return retVal; + } + + + // + // C++: size_t DeviceInfo::freeMemory() + // + + //javadoc: DeviceInfo::freeMemory() + public long freeMemory() + { + + long retVal = freeMemory_0(nativeObj); + + return retVal; + } + + + // + // C++: bool DeviceInfo::isCompatible() + // + + //javadoc: DeviceInfo::isCompatible() + public boolean isCompatible() + { + + boolean retVal = isCompatible_0(nativeObj); + + return retVal; + } + + + // + // C++: int DeviceInfo::majorVersion() + // + + //javadoc: DeviceInfo::majorVersion() + public int majorVersion() + { + + int retVal = majorVersion_0(nativeObj); + + return retVal; + } + + + // + // C++: int DeviceInfo::minorVersion() + // + + //javadoc: DeviceInfo::minorVersion() + public int minorVersion() + { + + int retVal = minorVersion_0(nativeObj); + + return retVal; + } + + + // + // C++: int DeviceInfo::multiProcessorCount() + // + + //javadoc: DeviceInfo::multiProcessorCount() + public int multiProcessorCount() + { + + int retVal = multiProcessorCount_0(nativeObj); + + return retVal; + } + + + // + // C++: string DeviceInfo::name() + // + + //javadoc: DeviceInfo::name() + public String name() + { + + String retVal = name_0(nativeObj); + + return retVal; + } + + + // + // C++: void DeviceInfo::queryMemory(size_t& totalMemory, size_t& freeMemory) + // + + //javadoc: DeviceInfo::queryMemory(totalMemory, freeMemory) + public void queryMemory(long totalMemory, long freeMemory) + { + double[] totalMemory_out = new double[1]; + double[] freeMemory_out = new double[1]; + queryMemory_0(nativeObj, totalMemory_out, freeMemory_out); + totalMemory = (long)totalMemory_out[0]; + freeMemory = (long)freeMemory_out[0]; + } + + + // + // C++: size_t DeviceInfo::sharedMemPerBlock() + // + + //javadoc: DeviceInfo::sharedMemPerBlock() + public long sharedMemPerBlock() + { + + long retVal = sharedMemPerBlock_0(nativeObj); + + return retVal; + } + + + // + // C++: bool DeviceInfo::supports(int feature_set) + // + + //javadoc: DeviceInfo::supports(feature_set) + public boolean supports(int feature_set) + { + + boolean retVal = supports_0(nativeObj, feature_set); + + return retVal; + } + + + // + // C++: size_t DeviceInfo::totalMemory() + // + + //javadoc: DeviceInfo::totalMemory() + public long totalMemory() + { + + long retVal = totalMemory_0(nativeObj); + + return retVal; + } + + + @Override + protected void finalize() throws Throwable { + delete(nativeObj); + } + + + + // C++: DeviceInfo::DeviceInfo() + private static native long DeviceInfo_0(); + + // C++: DeviceInfo::DeviceInfo(int device_id) + private static native long DeviceInfo_1(int device_id); + + // C++: int DeviceInfo::deviceID() + private static native int deviceID_0(long nativeObj); + + // C++: size_t DeviceInfo::freeMemory() + private static native long freeMemory_0(long nativeObj); + + // C++: bool DeviceInfo::isCompatible() + private static native boolean isCompatible_0(long nativeObj); + + // C++: int DeviceInfo::majorVersion() + private static native int majorVersion_0(long nativeObj); + + // C++: int DeviceInfo::minorVersion() + private static native int minorVersion_0(long nativeObj); + + // C++: int DeviceInfo::multiProcessorCount() + private static native int multiProcessorCount_0(long nativeObj); + + // C++: string DeviceInfo::name() + private static native String name_0(long nativeObj); + + // C++: void DeviceInfo::queryMemory(size_t& totalMemory, size_t& freeMemory) + private static native void queryMemory_0(long nativeObj, double[] totalMemory_out, double[] freeMemory_out); + + // C++: size_t DeviceInfo::sharedMemPerBlock() + private static native long sharedMemPerBlock_0(long nativeObj); + + // C++: bool DeviceInfo::supports(int feature_set) + private static native boolean supports_0(long nativeObj, int feature_set); + + // C++: size_t DeviceInfo::totalMemory() + private static native long totalMemory_0(long nativeObj); + + // native support for java finalize() + private static native void delete(long nativeObj); + +} diff --git a/modules/java/generator/src/java/gpu+Gpu.java b/modules/java/generator/src/java/gpu+Gpu.java new file mode 100644 index 0000000000..f3217176d2 --- /dev/null +++ b/modules/java/generator/src/java/gpu+Gpu.java @@ -0,0 +1,128 @@ +package org.opencv.gpu; + +public class Gpu { + + public static final int + FEATURE_SET_COMPUTE_10 = 10, + FEATURE_SET_COMPUTE_11 = 11, + FEATURE_SET_COMPUTE_12 = 12, + FEATURE_SET_COMPUTE_13 = 13, + FEATURE_SET_COMPUTE_20 = 20, + FEATURE_SET_COMPUTE_21 = 21, + FEATURE_SET_COMPUTE_30 = 30, + FEATURE_SET_COMPUTE_35 = 35, + GLOBAL_ATOMICS = FEATURE_SET_COMPUTE_11, + SHARED_ATOMICS = FEATURE_SET_COMPUTE_12, + NATIVE_DOUBLE = FEATURE_SET_COMPUTE_13, + WARP_SHUFFLE_FUNCTIONS = FEATURE_SET_COMPUTE_30, + DYNAMIC_PARALLELISM = FEATURE_SET_COMPUTE_35; + + + // + // C++: bool deviceSupports(int feature_set) + // + + //javadoc: deviceSupports(feature_set) + public static boolean deviceSupports(int feature_set) + { + boolean retVal = deviceSupports_0(feature_set); + return retVal; + } + + + // + // C++: int getCudaEnabledDeviceCount() + // + + //javadoc: getCudaEnabledDeviceCount() + public static int getCudaEnabledDeviceCount() + { + int retVal = getCudaEnabledDeviceCount_0(); + return retVal; + } + + + // + // C++: int getDevice() + // + + //javadoc: getDevice() + public static int getDevice() + { + int retVal = getDevice_0(); + return retVal; + } + + + // + // C++: void printCudaDeviceInfo(int device) + // + + //javadoc: printCudaDeviceInfo(device) + public static void printCudaDeviceInfo(int device) + { + printCudaDeviceInfo_0(device); + return; + } + + + // + // C++: void printShortCudaDeviceInfo(int device) + // + + //javadoc: printShortCudaDeviceInfo(device) + public static void printShortCudaDeviceInfo(int device) + { + printShortCudaDeviceInfo_0(device); + return; + } + + + // + // C++: void resetDevice() + // + + //javadoc: resetDevice() + public static void resetDevice() + { + resetDevice_0(); + return; + } + + + // + // C++: void setDevice(int device) + // + + //javadoc: setDevice(device) + public static void setDevice(int device) + { + setDevice_0(device); + return; + } + + + + + // C++: bool deviceSupports(int feature_set) + private static native boolean deviceSupports_0(int feature_set); + + // C++: int getCudaEnabledDeviceCount() + private static native int getCudaEnabledDeviceCount_0(); + + // C++: int getDevice() + private static native int getDevice_0(); + + // C++: void printCudaDeviceInfo(int device) + private static native void printCudaDeviceInfo_0(int device); + + // C++: void printShortCudaDeviceInfo(int device) + private static native void printShortCudaDeviceInfo_0(int device); + + // C++: void resetDevice() + private static native void resetDevice_0(); + + // C++: void setDevice(int device) + private static native void setDevice_0(int device); + +} diff --git a/modules/java/generator/src/java/gpu+TargetArchs.java b/modules/java/generator/src/java/gpu+TargetArchs.java new file mode 100644 index 0000000000..291a39c745 --- /dev/null +++ b/modules/java/generator/src/java/gpu+TargetArchs.java @@ -0,0 +1,141 @@ +package org.opencv.gpu; + +// C++: class TargetArchs +//javadoc: TargetArchs +public class TargetArchs { + + protected final long nativeObj; + protected TargetArchs(long addr) { nativeObj = addr; } + + + // + // C++: static bool TargetArchs::builtWith(int feature_set) + // + + //javadoc: TargetArchs::builtWith(feature_set) + public static boolean builtWith(int feature_set) + { + boolean retVal = builtWith_0(feature_set); + return retVal; + } + + + // + // C++: static bool TargetArchs::has(int major, int minor) + // + + //javadoc: TargetArchs::has(major, minor) + public static boolean has(int major, int minor) + { + boolean retVal = has_0(major, minor); + return retVal; + } + + + // + // C++: static bool TargetArchs::hasBin(int major, int minor) + // + + //javadoc: TargetArchs::hasBin(major, minor) + public static boolean hasBin(int major, int minor) + { + boolean retVal = hasBin_0(major, minor); + return retVal; + } + + + // + // C++: static bool TargetArchs::hasEqualOrGreater(int major, int minor) + // + + //javadoc: TargetArchs::hasEqualOrGreater(major, minor) + public static boolean hasEqualOrGreater(int major, int minor) + { + boolean retVal = hasEqualOrGreater_0(major, minor); + return retVal; + } + + + // + // C++: static bool TargetArchs::hasEqualOrGreaterBin(int major, int minor) + // + + //javadoc: TargetArchs::hasEqualOrGreaterBin(major, minor) + public static boolean hasEqualOrGreaterBin(int major, int minor) + { + boolean retVal = hasEqualOrGreaterBin_0(major, minor); + return retVal; + } + + + // + // C++: static bool TargetArchs::hasEqualOrGreaterPtx(int major, int minor) + // + + //javadoc: TargetArchs::hasEqualOrGreaterPtx(major, minor) + public static boolean hasEqualOrGreaterPtx(int major, int minor) + { + boolean retVal = hasEqualOrGreaterPtx_0(major, minor); + return retVal; + } + + + // + // C++: static bool TargetArchs::hasEqualOrLessPtx(int major, int minor) + // + + //javadoc: TargetArchs::hasEqualOrLessPtx(major, minor) + public static boolean hasEqualOrLessPtx(int major, int minor) + { + boolean retVal = hasEqualOrLessPtx_0(major, minor); + return retVal; + } + + + // + // C++: static bool TargetArchs::hasPtx(int major, int minor) + // + + //javadoc: TargetArchs::hasPtx(major, minor) + public static boolean hasPtx(int major, int minor) + { + boolean retVal = hasPtx_0(major, minor); + return retVal; + } + + + @Override + protected void finalize() throws Throwable { + delete(nativeObj); + } + + + + // C++: static bool TargetArchs::builtWith(int feature_set) + private static native boolean builtWith_0(int feature_set); + + // C++: static bool TargetArchs::has(int major, int minor) + private static native boolean has_0(int major, int minor); + + // C++: static bool TargetArchs::hasBin(int major, int minor) + private static native boolean hasBin_0(int major, int minor); + + // C++: static bool TargetArchs::hasEqualOrGreater(int major, int minor) + private static native boolean hasEqualOrGreater_0(int major, int minor); + + // C++: static bool TargetArchs::hasEqualOrGreaterBin(int major, int minor) + private static native boolean hasEqualOrGreaterBin_0(int major, int minor); + + // C++: static bool TargetArchs::hasEqualOrGreaterPtx(int major, int minor) + private static native boolean hasEqualOrGreaterPtx_0(int major, int minor); + + // C++: static bool TargetArchs::hasEqualOrLessPtx(int major, int minor) + private static native boolean hasEqualOrLessPtx_0(int major, int minor); + + // C++: static bool TargetArchs::hasPtx(int major, int minor) + private static native boolean hasPtx_0(int major, int minor); + + // native support for java finalize() + private static native void delete(long nativeObj); + +} From 358e59e91b555f686ee3bd2b1dc68433727151c6 Mon Sep 17 00:00:00 2001 From: Alexander Smorkalov Date: Tue, 24 Dec 2013 16:36:11 +0400 Subject: [PATCH 2/2] Fake dependency from CUDA in case of satic linkage with OpenCV removed. --- cmake/OpenCVGenAndroidMK.cmake | 7 +++++++ cmake/templates/OpenCV.mk.in | 6 +++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/cmake/OpenCVGenAndroidMK.cmake b/cmake/OpenCVGenAndroidMK.cmake index fbac8d2c63..c5a979e44b 100644 --- a/cmake/OpenCVGenAndroidMK.cmake +++ b/cmake/OpenCVGenAndroidMK.cmake @@ -44,6 +44,7 @@ if(ANDROID) # build the list of opencv libs and dependencies for all modules set(OPENCV_MODULES_CONFIGMAKE "") + set(OPENCV_HAVE_GPU_MODULE_CONFIGMAKE "off") set(OPENCV_EXTRA_COMPONENTS_CONFIGMAKE "") set(OPENCV_3RDPARTY_COMPONENTS_CONFIGMAKE "") foreach(m ${OPENCV_MODULES_PUBLIC}) @@ -68,6 +69,12 @@ if(ANDROID) list(REMOVE_ITEM OPENCV_MODULES_CONFIGMAKE ${OPENCV_3RDPARTY_COMPONENTS_CONFIGMAKE}) endif() + # GPU module enabled separately + list(REMOVE_ITEM OPENCV_MODULES_CONFIGMAKE "gpu") + if(HAVE_opencv_gpu) + set(OPENCV_HAVE_GPU_MODULE_CONFIGMAKE "on") + endif() + # convert CMake lists to makefile literals foreach(lst OPENCV_MODULES_CONFIGMAKE OPENCV_3RDPARTY_COMPONENTS_CONFIGMAKE OPENCV_EXTRA_COMPONENTS_CONFIGMAKE) ocv_list_unique(${lst}) diff --git a/cmake/templates/OpenCV.mk.in b/cmake/templates/OpenCV.mk.in index fdf700591a..0fd7b9e058 100644 --- a/cmake/templates/OpenCV.mk.in +++ b/cmake/templates/OpenCV.mk.in @@ -13,10 +13,11 @@ OPENCV_BASEDIR:=@OPENCV_BASE_INCLUDE_DIR_CONFIGCMAKE@ OPENCV_LOCAL_C_INCLUDES:=@OPENCV_INCLUDE_DIRS_CONFIGCMAKE@ OPENCV_MODULES:=@OPENCV_MODULES_CONFIGMAKE@ +OPENCV_HAVE_GPU_MODULE=@OPENCV_HAVE_GPU_MODULE_CONFIGMAKE@ OPENCV_USE_GPU_MODULE:= ifeq ($(TARGET_ARCH_ABI),armeabi-v7a) - ifneq ($(findstring gpu,$(OPENCV_MODULES)),) + ifeq ($(OPENCV_HAVE_GPU_MODULE),on) ifneq ($(CUDA_TOOLKIT_DIR),) OPENCV_USE_GPU_MODULE:=on endif @@ -114,6 +115,9 @@ ifeq ($(OPENCV_MK_$(OPENCV_TARGET_ARCH_ABI)_ALREADY_INCLUDED),) ifneq ($(OPENCV_BASEDIR),) OPENCV_LOCAL_C_INCLUDES += $(foreach mod, $(OPENCV_MODULES), $(OPENCV_BASEDIR)/modules/$(mod)/include) + ifeq ($(OPENCV_USE_GPU_MODULE),on) + OPENCV_LOCAL_C_INCLUDES += $(OPENCV_BASEDIR)/modules/gpu/include + endif endif #turn off module installation to prevent their redefinition