diff --git a/java/src/main/native/.clang-format b/java/src/main/native/.clang-format deleted file mode 100644 index e0866533a36..00000000000 --- a/java/src/main/native/.clang-format +++ /dev/null @@ -1,204 +0,0 @@ ---- -# Reference: https://clang.llvm.org/docs/ClangFormatStyleOptions.html -Language: Cpp -# BasedOnStyle: LLVM -# no indentation (-2 from indent, which is 2) -AccessModifierOffset: -2 -AlignAfterOpenBracket: Align -# int aaaa = 12; -# int b = 23; -# int ccc = 23; -# leaving OFF -AlignConsecutiveAssignments: false -# int aaaa = 12; -# float b = 23; -# std::string ccc = 23; -# leaving OFF -AlignConsecutiveDeclarations: false -##define A \ -# int aaaa; \ -# int b; \ -# int dddddddddd; -# leaving ON -AlignEscapedNewlines: Right -# int aaa = bbbbbbbbbbbbbbb + -# ccccccccccccccc; -# leaving ON -AlignOperands: true -# true: false: -# int a; // My comment a vs. int a; // My comment a -# int b = 2; // comment b int b = 2; // comment about b -# leaving ON -AlignTrailingComments: true -# squeezes a long declaration's arguments to the next line: -#true: -#void myFunction( -# int a, int b, int c, int d, int e); -# -#false: -#void myFunction(int a, -# int b, -# int c, -# int d, -# int e); -# leaving ON -AllowAllParametersOfDeclarationOnNextLine: true -# changed to ON, as we use short blocks on same lines -AllowShortBlocksOnASingleLine: true -# set this to ON, we use this in a few places -AllowShortCaseLabelsOnASingleLine: true -# set this to ON -AllowShortFunctionsOnASingleLine: Inline -AllowShortIfStatementsOnASingleLine: false -AllowShortLoopsOnASingleLine: false -# Deprecated option. -# PenaltyReturnTypeOnItsOwnLine applies, as we set this to None, -# where it tries to break after the return type automatically -AlwaysBreakAfterDefinitionReturnType: None -AlwaysBreakAfterReturnType: None -AlwaysBreakBeforeMultilineStrings: false -AlwaysBreakTemplateDeclarations: MultiLine - -# if all the arguments for a function don't fit in a single line, -# with a value of "false", it'll split each argument into different lines -BinPackArguments: true -BinPackParameters: true - -# if this is set to Custom, the BraceWrapping flags apply -BreakBeforeBraces: Custom -BraceWrapping: - AfterClass: false - AfterControlStatement: false - AfterEnum: false - AfterFunction: false - AfterNamespace: false - AfterObjCDeclaration: false - AfterStruct: false - AfterUnion: false - AfterExternBlock: false - BeforeCatch: false - BeforeElse: false - IndentBraces: false - SplitEmptyFunction: false - SplitEmptyRecord: false - SplitEmptyNamespace: false - -# will break after operators when a line is too long -BreakBeforeBinaryOperators: None -# not in docs.. so that's nice -BreakBeforeInheritanceComma: false -# This will break inheritance list and align on colon, -# it also places each inherited class in a different line. -# Leaving ON -BreakInheritanceList: BeforeColon - -# -#true: -#veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongDescription -# ? firstValue -# : SecondValueVeryVeryVeryVeryLong; -# -#false: -#veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongDescription ? -# firstValue : -# SecondValueVeryVeryVeryVeryLong; -BreakBeforeTernaryOperators: false - -BreakConstructorInitializersBeforeComma: false -BreakConstructorInitializers: BeforeColon -BreakAfterJavaFieldAnnotations: true -BreakStringLiterals: true -# So the line lengths in cudf are not following a limit, at the moment. -# Usually it's a long comment that makes the line length inconsistent. -# Command I used to find max line lengths (from cpp directory): -# find include src tests|grep "\." |xargs -I{} bash -c "awk '{print length}' {} | sort -rn | head -1"|sort -n -# I picked 100, as it seemed somewhere around median -ColumnLimit: 100 -# TODO: not aware of any of these at this time -CommentPragmas: '^ IWYU pragma:' -# So it doesn't put subsequent namespaces in the same line -CompactNamespaces: false -ConstructorInitializerAllOnOneLineOrOnePerLine: false -ConstructorInitializerIndentWidth: 4 -ContinuationIndentWidth: 4 -# TODO: adds spaces around the element list -# in initializer: vector x{ {}, ..., {} } -Cpp11BracedListStyle: true -DerivePointerAlignment: false -DisableFormat: false -ExperimentalAutoDetectBinPacking: false -# } // namespace a => useful -FixNamespaceComments: true -ForEachMacros: - - foreach - - Q_FOREACH - - BOOST_FOREACH -IncludeBlocks: Regroup -IncludeCategories: - - Regex: '<[[:alnum:]]+>' - Priority: 0 - - Regex: '<[[:alnum:].]+>' - Priority: 1 - - Regex: '<.*>' - Priority: 2 - - Regex: '.*/.*' - Priority: 3 - - Regex: '.*' - Priority: 4 -# if a header matches this in an include group, it will be moved up to the -# top of the group. -IncludeIsMainRegex: '(Test)?$' -IndentCaseLabels: true -IndentPPDirectives: None -IndentWidth: 2 -IndentWrappedFunctionNames: false -JavaScriptQuotes: Leave -JavaScriptWrapImports: true -KeepEmptyLinesAtTheStartOfBlocks: true -MacroBlockBegin: '' -MacroBlockEnd: '' -MaxEmptyLinesToKeep: 1 -NamespaceIndentation: None -ObjCBinPackProtocolList: Auto -ObjCBlockIndentWidth: 2 -ObjCSpaceAfterProperty: false -ObjCSpaceBeforeProtocolList: true - -# Penalties: leaving unchanged for now -# https://stackoverflow.com/questions/26635370/in-clang-format-what-do-the-penalties-do -PenaltyBreakAssignment: 2 -PenaltyBreakBeforeFirstCallParameter: 19 -PenaltyBreakComment: 300 -PenaltyBreakFirstLessLess: 120 -PenaltyBreakString: 1000 -PenaltyBreakTemplateDeclaration: 10 -PenaltyExcessCharacter: 1000000 -# As currently set, we don't see return types being -# left on their own line, leaving at 60 -PenaltyReturnTypeOnItsOwnLine: 60 - -# char* foo vs char *foo, picking Right aligned -PointerAlignment: Right -ReflowComments: true -# leaving ON, but this could be something to turn OFF -SortIncludes: true -SortUsingDeclarations: true -SpaceAfterCStyleCast: false -SpaceAfterTemplateKeyword: true -SpaceBeforeAssignmentOperators: true -SpaceBeforeCpp11BracedList: false -SpaceBeforeCtorInitializerColon: true -SpaceBeforeInheritanceColon: true -SpaceBeforeParens: ControlStatements -SpaceBeforeRangeBasedForLoopColon: true -SpaceInEmptyParentheses: false -SpacesBeforeTrailingComments: 1 -SpacesInAngles: false -SpacesInContainerLiterals: true -SpacesInCStyleCastParentheses: false -SpacesInParentheses: false -SpacesInSquareBrackets: false -Standard: Cpp11 -TabWidth: 8 -UseTab: Never -... diff --git a/java/src/main/native/clang-format.README b/java/src/main/native/clang-format.README deleted file mode 100644 index 6c13289720a..00000000000 --- a/java/src/main/native/clang-format.README +++ /dev/null @@ -1,13 +0,0 @@ -README -====== - -To apply code formatting to a file you are working on, currently you can do this manually using -clang-format-7: - -This will edit the file, and print to stdout: - - clang-format [file] - -This will edit the file in place, do this if you are sure of what you are doing: - - clang-format -i [file] diff --git a/java/src/main/native/include/jni_utils.hpp b/java/src/main/native/include/jni_utils.hpp index f342fca8933..96ad1f23b8c 100644 --- a/java/src/main/native/include/jni_utils.hpp +++ b/java/src/main/native/include/jni_utils.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019-2023, NVIDIA CORPORATION. + * Copyright (c) 2019-2024, NVIDIA CORPORATION. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,48 +15,48 @@ */ #pragma once -#include -#include -#include +#include + +#include #include -#include -#include +#include +#include +#include namespace cudf { namespace jni { constexpr jint MINIMUM_JNI_VERSION = JNI_VERSION_1_6; -constexpr char const *CUDA_ERROR_CLASS = "ai/rapids/cudf/CudaException"; -constexpr char const *CUDA_FATAL_ERROR_CLASS = "ai/rapids/cudf/CudaFatalException"; -constexpr char const *CUDF_ERROR_CLASS = "ai/rapids/cudf/CudfException"; -constexpr char const *CUDF_OVERFLOW_ERROR_CLASS = "ai/rapids/cudf/CudfColumnSizeOverflowException"; -constexpr char const *CUDF_DTYPE_ERROR_CLASS = "ai/rapids/cudf/CudfException"; -constexpr char const *INDEX_OOB_CLASS = "java/lang/ArrayIndexOutOfBoundsException"; -constexpr char const *ILLEGAL_ARG_CLASS = "java/lang/IllegalArgumentException"; -constexpr char const *NPE_CLASS = "java/lang/NullPointerException"; -constexpr char const *OOM_CLASS = "java/lang/OutOfMemoryError"; +constexpr char const* CUDA_ERROR_CLASS = "ai/rapids/cudf/CudaException"; +constexpr char const* CUDA_FATAL_ERROR_CLASS = "ai/rapids/cudf/CudaFatalException"; +constexpr char const* CUDF_ERROR_CLASS = "ai/rapids/cudf/CudfException"; +constexpr char const* CUDF_OVERFLOW_ERROR_CLASS = "ai/rapids/cudf/CudfColumnSizeOverflowException"; +constexpr char const* CUDF_DTYPE_ERROR_CLASS = "ai/rapids/cudf/CudfException"; +constexpr char const* INDEX_OOB_CLASS = "java/lang/ArrayIndexOutOfBoundsException"; +constexpr char const* ILLEGAL_ARG_CLASS = "java/lang/IllegalArgumentException"; +constexpr char const* NPE_CLASS = "java/lang/NullPointerException"; +constexpr char const* OOM_CLASS = "java/lang/OutOfMemoryError"; /** * @brief indicates that a JNI error of some kind was thrown and the main * function should return. */ class jni_exception : public std::runtime_error { -public: - jni_exception(char const *const message) : std::runtime_error(message) {} - jni_exception(std::string const &message) : std::runtime_error(message) {} + public: + jni_exception(char const* const message) : std::runtime_error(message) {} + jni_exception(std::string const& message) : std::runtime_error(message) {} }; /** * @brief throw a java exception and a C++ one for flow control. */ -inline void throw_java_exception(JNIEnv *const env, const char *class_name, const char *message) { +inline void throw_java_exception(JNIEnv* const env, const char* class_name, const char* message) +{ jclass ex_class = env->FindClass(class_name); - if (ex_class != NULL) { - env->ThrowNew(ex_class, message); - } + if (ex_class != NULL) { env->ThrowNew(ex_class, message); } throw jni_exception(message); } @@ -64,7 +64,8 @@ inline void throw_java_exception(JNIEnv *const env, const char *class_name, cons * @brief check if an java exceptions have been thrown and if so throw a C++ * exception so the flow control stop processing. */ -inline void check_java_exception(JNIEnv *const env) { +inline void check_java_exception(JNIEnv* const env) +{ if (env->ExceptionCheck()) { // Not going to try to get the message out of the Exception, too complex and // might fail. @@ -78,7 +79,9 @@ inline void check_java_exception(JNIEnv *const env) { * This is useful when, for instance, converting a cudf::column pointer * to a jlong, for use in JNI. */ -template jlong ptr_as_jlong(T *ptr) { +template +jlong ptr_as_jlong(T* ptr) +{ return reinterpret_cast(ptr); } @@ -86,7 +89,9 @@ template jlong ptr_as_jlong(T *ptr) { * @brief Helper to release the data held by a unique_ptr, and return * the pointer as a jlong. */ -template jlong release_as_jlong(std::unique_ptr &&ptr) { +template +jlong release_as_jlong(std::unique_ptr&& ptr) +{ return ptr_as_jlong(ptr.release()); } @@ -94,96 +99,112 @@ template jlong release_as_jlong(std::unique_ptr &&ptr) { * @brief Helper to release the data held by a unique_ptr, and return * the pointer as a jlong. */ -template jlong release_as_jlong(std::unique_ptr &ptr) { +template +jlong release_as_jlong(std::unique_ptr& ptr) +{ return release_as_jlong(std::move(ptr)); } class native_jdoubleArray_accessor { -public: - jdouble *getArrayElements(JNIEnv *const env, jdoubleArray arr) const { + public: + jdouble* getArrayElements(JNIEnv* const env, jdoubleArray arr) const + { return env->GetDoubleArrayElements(arr, NULL); } - jdoubleArray newArray(JNIEnv *const env, int len) const { return env->NewDoubleArray(len); } + jdoubleArray newArray(JNIEnv* const env, int len) const { return env->NewDoubleArray(len); } - void setArrayRegion(JNIEnv *const env, jdoubleArray jarr, int start, int len, - jdouble const *arr) const { + void setArrayRegion( + JNIEnv* const env, jdoubleArray jarr, int start, int len, jdouble const* arr) const + { env->SetDoubleArrayRegion(jarr, start, len, arr); } - void releaseArrayElements(JNIEnv *const env, jdoubleArray jarr, jdouble *arr, jint mode) const { + void releaseArrayElements(JNIEnv* const env, jdoubleArray jarr, jdouble* arr, jint mode) const + { env->ReleaseDoubleArrayElements(jarr, arr, mode); } }; class native_jlongArray_accessor { -public: - jlong *getArrayElements(JNIEnv *const env, jlongArray arr) const { + public: + jlong* getArrayElements(JNIEnv* const env, jlongArray arr) const + { return env->GetLongArrayElements(arr, NULL); } - jlongArray newArray(JNIEnv *const env, int len) const { return env->NewLongArray(len); } + jlongArray newArray(JNIEnv* const env, int len) const { return env->NewLongArray(len); } - void setArrayRegion(JNIEnv *const env, jlongArray jarr, int start, int len, - jlong const *arr) const { + void setArrayRegion( + JNIEnv* const env, jlongArray jarr, int start, int len, jlong const* arr) const + { env->SetLongArrayRegion(jarr, start, len, arr); } - void releaseArrayElements(JNIEnv *const env, jlongArray jarr, jlong *arr, jint mode) const { + void releaseArrayElements(JNIEnv* const env, jlongArray jarr, jlong* arr, jint mode) const + { env->ReleaseLongArrayElements(jarr, arr, mode); } }; class native_jintArray_accessor { -public: - jint *getArrayElements(JNIEnv *const env, jintArray arr) const { + public: + jint* getArrayElements(JNIEnv* const env, jintArray arr) const + { return env->GetIntArrayElements(arr, NULL); } - jintArray newArray(JNIEnv *const env, int len) const { return env->NewIntArray(len); } + jintArray newArray(JNIEnv* const env, int len) const { return env->NewIntArray(len); } - void setArrayRegion(JNIEnv *const env, jintArray jarr, int start, int len, - jint const *arr) const { + void setArrayRegion(JNIEnv* const env, jintArray jarr, int start, int len, jint const* arr) const + { env->SetIntArrayRegion(jarr, start, len, arr); } - void releaseArrayElements(JNIEnv *const env, jintArray jarr, jint *arr, jint mode) const { + void releaseArrayElements(JNIEnv* const env, jintArray jarr, jint* arr, jint mode) const + { env->ReleaseIntArrayElements(jarr, arr, mode); } }; class native_jbyteArray_accessor { -public: - jbyte *getArrayElements(JNIEnv *const env, jbyteArray arr) const { + public: + jbyte* getArrayElements(JNIEnv* const env, jbyteArray arr) const + { return env->GetByteArrayElements(arr, NULL); } - jbyteArray newArray(JNIEnv *const env, int len) const { return env->NewByteArray(len); } + jbyteArray newArray(JNIEnv* const env, int len) const { return env->NewByteArray(len); } - void setArrayRegion(JNIEnv *const env, jbyteArray jarr, int start, int len, - jbyte const *arr) const { + void setArrayRegion( + JNIEnv* const env, jbyteArray jarr, int start, int len, jbyte const* arr) const + { env->SetByteArrayRegion(jarr, start, len, arr); } - void releaseArrayElements(JNIEnv *const env, jbyteArray jarr, jbyte *arr, jint mode) const { + void releaseArrayElements(JNIEnv* const env, jbyteArray jarr, jbyte* arr, jint mode) const + { env->ReleaseByteArrayElements(jarr, arr, mode); } }; class native_jbooleanArray_accessor { -public: - jboolean *getArrayElements(JNIEnv *const env, jbooleanArray arr) const { + public: + jboolean* getArrayElements(JNIEnv* const env, jbooleanArray arr) const + { return env->GetBooleanArrayElements(arr, NULL); } - jbooleanArray newArray(JNIEnv *const env, int len) const { return env->NewBooleanArray(len); } + jbooleanArray newArray(JNIEnv* const env, int len) const { return env->NewBooleanArray(len); } - void setArrayRegion(JNIEnv *const env, jbooleanArray jarr, int start, int len, - jboolean const *arr) const { + void setArrayRegion( + JNIEnv* const env, jbooleanArray jarr, int start, int len, jboolean const* arr) const + { env->SetBooleanArrayRegion(jarr, start, len, arr); } - void releaseArrayElements(JNIEnv *const env, jbooleanArray jarr, jboolean *arr, jint mode) const { + void releaseArrayElements(JNIEnv* const env, jbooleanArray jarr, jboolean* arr, jint mode) const + { env->ReleaseBooleanArrayElements(jarr, arr, mode); } }; @@ -194,47 +215,52 @@ class native_jbooleanArray_accessor { * By default any changes to the array will be committed back when * the destructor is called unless cancel is called first. */ -template class native_jArray { -private: +template +class native_jArray { + private: ACCESSOR access{}; - JNIEnv *const env; + JNIEnv* const env; J_ARRAY_TYPE orig; int len; - mutable N_TYPE *data_ptr; + mutable N_TYPE* data_ptr; - void init_data_ptr() const { + void init_data_ptr() const + { if (orig != nullptr && data_ptr == nullptr) { data_ptr = access.getArrayElements(env, orig); check_java_exception(env); } } -public: - native_jArray(native_jArray const &) = delete; - native_jArray &operator=(native_jArray const &) = delete; + public: + native_jArray(native_jArray const&) = delete; + native_jArray& operator=(native_jArray const&) = delete; - native_jArray(JNIEnv *const env, J_ARRAY_TYPE orig) - : env(env), orig(orig), len(0), data_ptr(NULL) { + native_jArray(JNIEnv* const env, J_ARRAY_TYPE orig) : env(env), orig(orig), len(0), data_ptr(NULL) + { if (orig != NULL) { len = env->GetArrayLength(orig); check_java_exception(env); } } - native_jArray(JNIEnv *const env, int len) - : env(env), orig(access.newArray(env, len)), len(len), data_ptr(NULL) { + native_jArray(JNIEnv* const env, int len) + : env(env), orig(access.newArray(env, len)), len(len), data_ptr(NULL) + { check_java_exception(env); } - native_jArray(JNIEnv *const env, N_TYPE const *arr, int len) - : env(env), orig(access.newArray(env, len)), len(len), data_ptr(NULL) { + native_jArray(JNIEnv* const env, N_TYPE const* arr, int len) + : env(env), orig(access.newArray(env, len)), len(len), data_ptr(NULL) + { check_java_exception(env); access.setArrayRegion(env, orig, 0, len, arr); check_java_exception(env); } - native_jArray(JNIEnv *const env, const std::vector &arr) - : env(env), orig(access.newArray(env, arr.size())), len(arr.size()), data_ptr(NULL) { + native_jArray(JNIEnv* const env, const std::vector& arr) + : env(env), orig(access.newArray(env, arr.size())), len(arr.size()), data_ptr(NULL) + { check_java_exception(env); access.setArrayRegion(env, orig, 0, len, arr.data()); check_java_exception(env); @@ -244,43 +270,39 @@ template class nativ int size() const noexcept { return len; } - N_TYPE operator[](int index) const { - if (orig == NULL) { - throw_java_exception(env, NPE_CLASS, "pointer is NULL"); - } - if (index < 0 || index >= len) { - throw_java_exception(env, INDEX_OOB_CLASS, "NOT IN BOUNDS"); - } + N_TYPE operator[](int index) const + { + if (orig == NULL) { throw_java_exception(env, NPE_CLASS, "pointer is NULL"); } + if (index < 0 || index >= len) { throw_java_exception(env, INDEX_OOB_CLASS, "NOT IN BOUNDS"); } return data()[index]; } - N_TYPE &operator[](int index) { - if (orig == NULL) { - throw_java_exception(env, NPE_CLASS, "pointer is NULL"); - } - if (index < 0 || index >= len) { - throw_java_exception(env, INDEX_OOB_CLASS, "NOT IN BOUNDS"); - } + N_TYPE& operator[](int index) + { + if (orig == NULL) { throw_java_exception(env, NPE_CLASS, "pointer is NULL"); } + if (index < 0 || index >= len) { throw_java_exception(env, INDEX_OOB_CLASS, "NOT IN BOUNDS"); } return data()[index]; } - const N_TYPE *const data() const { + const N_TYPE* const data() const + { init_data_ptr(); return data_ptr; } - N_TYPE *data() { + N_TYPE* data() + { init_data_ptr(); return data_ptr; } - const N_TYPE *const begin() const { return data(); } + const N_TYPE* const begin() const { return data(); } - N_TYPE *begin() { return data(); } + N_TYPE* begin() { return data(); } - const N_TYPE *const end() const { return data() + size(); } + const N_TYPE* const end() const { return data() + size(); } - N_TYPE *end() { return data() + size(); } + N_TYPE* end() { return data() + size(); } const J_ARRAY_TYPE get_jArray() const { return orig; } @@ -292,7 +314,9 @@ template class nativ * @tparam target_t Target data type * @return std::vector Vector with the copied contents */ - template std::vector to_vector() const { + template + std::vector to_vector() const + { std::vector ret; ret.reserve(size()); std::copy(begin(), end(), std::back_inserter(ret)); @@ -303,14 +327,16 @@ template class nativ * @brief if data has been written back into this array, don't commit * it. */ - void cancel() { + void cancel() + { if (data_ptr != NULL && orig != NULL) { access.releaseArrayElements(env, orig, data_ptr, JNI_ABORT); data_ptr = NULL; } } - void commit() { + void commit() + { if (data_ptr != NULL && orig != NULL) { access.releaseArrayElements(env, orig, data_ptr, 0); data_ptr = NULL; @@ -321,9 +347,9 @@ template class nativ }; using native_jdoubleArray = native_jArray; -using native_jlongArray = native_jArray; -using native_jintArray = native_jArray; -using native_jbyteArray = native_jArray; +using native_jlongArray = native_jArray; +using native_jintArray = native_jArray; +using native_jbyteArray = native_jArray; /** * @brief Specialization of native_jArray for jboolean @@ -332,19 +358,23 @@ using native_jbyteArray = native_jArray { - native_jbooleanArray(JNIEnv *const env, jbooleanArray orig) - : native_jArray(env, orig) {} + : native_jArray { + native_jbooleanArray(JNIEnv* const env, jbooleanArray orig) + : native_jArray(env, orig) + { + } - native_jbooleanArray(native_jbooleanArray const &) = delete; - native_jbooleanArray &operator=(native_jbooleanArray const &) = delete; + native_jbooleanArray(native_jbooleanArray const&) = delete; + native_jbooleanArray& operator=(native_jbooleanArray const&) = delete; template - std::vector transform_if_else(target_t const &if_true, target_t const &if_false) const { + std::vector transform_if_else(target_t const& if_true, target_t const& if_false) const + { std::vector ret; ret.reserve(size()); - std::transform(begin(), end(), std::back_inserter(ret), - [&](jboolean const &b) { return b ? if_true : if_false; }); + std::transform(begin(), end(), std::back_inserter(ret), [&](jboolean const& b) { + return b ? if_true : if_false; + }); return ret; } }; @@ -355,58 +385,58 @@ struct native_jbooleanArray * By default any changes to the array will be committed back when * the destructor is called unless cancel is called first. */ -template class native_jpointerArray { -private: +template +class native_jpointerArray { + private: native_jlongArray wrapped; - JNIEnv *const env; + JNIEnv* const env; -public: - native_jpointerArray(native_jpointerArray const &) = delete; - native_jpointerArray &operator=(native_jpointerArray const &) = delete; + public: + native_jpointerArray(native_jpointerArray const&) = delete; + native_jpointerArray& operator=(native_jpointerArray const&) = delete; - native_jpointerArray(JNIEnv *const env, jlongArray orig) : wrapped(env, orig), env(env) {} + native_jpointerArray(JNIEnv* const env, jlongArray orig) : wrapped(env, orig), env(env) {} - native_jpointerArray(JNIEnv *const env, int len) : wrapped(env, len), env(env) {} + native_jpointerArray(JNIEnv* const env, int len) : wrapped(env, len), env(env) {} - native_jpointerArray(JNIEnv *const env, T *arr, int len) : wrapped(env, arr, len), env(env) {} + native_jpointerArray(JNIEnv* const env, T* arr, int len) : wrapped(env, arr, len), env(env) {} bool is_null() const noexcept { return wrapped.is_null(); } int size() const noexcept { return wrapped.size(); } - T *operator[](int index) const { - if (data() == NULL) { - throw_java_exception(env, NPE_CLASS, "pointer is NULL"); - } + T* operator[](int index) const + { + if (data() == NULL) { throw_java_exception(env, NPE_CLASS, "pointer is NULL"); } if (index < 0 || index >= wrapped.size()) { throw_java_exception(env, INDEX_OOB_CLASS, "NOT IN BOUNDS"); } return data()[index]; } - T *&operator[](int index) { - if (data() == NULL) { - throw_java_exception(env, NPE_CLASS, "pointer is NULL"); - } + T*& operator[](int index) + { + if (data() == NULL) { throw_java_exception(env, NPE_CLASS, "pointer is NULL"); } if (index < 0 || index >= wrapped.size()) { throw_java_exception(env, INDEX_OOB_CLASS, "NOT IN BOUNDS"); } return data()[index]; } - T *const *data() const { return reinterpret_cast(wrapped.data()); } + T* const* data() const { return reinterpret_cast(wrapped.data()); } - T **data() { return reinterpret_cast(wrapped.data()); } + T** data() { return reinterpret_cast(wrapped.data()); } - T *const *begin() const { return data(); } - T *const *end() const { return data() + size(); } + T* const* begin() const { return data(); } + T* const* end() const { return data() + size(); } const jlongArray get_jArray() const { return wrapped.get_jArray(); } jlongArray get_jArray() { return wrapped.get_jArray(); } - void assert_no_nulls() const { - if (std::any_of(data(), data() + size(), [](T *const ptr) { return ptr == nullptr; })) { + void assert_no_nulls() const + { + if (std::any_of(data(), data() + size(), [](T* const ptr) { return ptr == nullptr; })) { throw_java_exception(env, NPE_CLASS, "pointer is NULL"); } } @@ -414,12 +444,13 @@ template class native_jpointerArray { /** * @brief Convert from `T*[]` to `vector`. */ - std::vector get_dereferenced() const { + std::vector get_dereferenced() const + { assert_no_nulls(); auto ret = std::vector{}; ret.reserve(size()); - std::transform(data(), data() + size(), std::back_inserter(ret), - [](T *const &p) { return *p; }); + std::transform( + data(), data() + size(), std::back_inserter(ret), [](T* const& p) { return *p; }); return ret; } @@ -439,73 +470,82 @@ template class native_jpointerArray { * By default any changes to the array will be committed back when * released unless cancel is called first. */ -template > class unique_jpointerArray { -private: +template > +class unique_jpointerArray { + private: std::unique_ptr> wrapped; D del; -public: - unique_jpointerArray(unique_jpointerArray const &) = delete; - unique_jpointerArray &operator=(unique_jpointerArray const &) = delete; + public: + unique_jpointerArray(unique_jpointerArray const&) = delete; + unique_jpointerArray& operator=(unique_jpointerArray const&) = delete; - unique_jpointerArray(JNIEnv *const env, jlongArray orig) - : wrapped(new native_jpointerArray(env, orig)) {} + unique_jpointerArray(JNIEnv* const env, jlongArray orig) + : wrapped(new native_jpointerArray(env, orig)) + { + } - unique_jpointerArray(JNIEnv *const env, jlongArray orig, const D &del) - : wrapped(new native_jpointerArray(env, orig)), del(del) {} + unique_jpointerArray(JNIEnv* const env, jlongArray orig, const D& del) + : wrapped(new native_jpointerArray(env, orig)), del(del) + { + } - unique_jpointerArray(JNIEnv *const env, int len) - : wrapped(new native_jpointerArray(env, len)) {} + unique_jpointerArray(JNIEnv* const env, int len) : wrapped(new native_jpointerArray(env, len)) + { + } - unique_jpointerArray(JNIEnv *const env, int len, const D &del) - : wrapped(new native_jpointerArray(env, len)), del(del) {} + unique_jpointerArray(JNIEnv* const env, int len, const D& del) + : wrapped(new native_jpointerArray(env, len)), del(del) + { + } - unique_jpointerArray(JNIEnv *const env, T *arr, int len) - : wrapped(new native_jpointerArray(env, arr, len)) {} + unique_jpointerArray(JNIEnv* const env, T* arr, int len) + : wrapped(new native_jpointerArray(env, arr, len)) + { + } - unique_jpointerArray(JNIEnv *const env, T *arr, int len, const D &del) - : wrapped(new native_jpointerArray(env, arr, len)), del(del) {} + unique_jpointerArray(JNIEnv* const env, T* arr, int len, const D& del) + : wrapped(new native_jpointerArray(env, arr, len)), del(del) + { + } bool is_null() const noexcept { return wrapped == NULL || wrapped->is_null(); } int size() const noexcept { return wrapped == NULL ? 0 : wrapped->size(); } - void reset(int index, T *new_ptr = NULL) { - if (wrapped == NULL) { - throw std::logic_error("using unique_jpointerArray after release"); - } - T *old = (*wrapped)[index]; + void reset(int index, T* new_ptr = NULL) + { + if (wrapped == NULL) { throw std::logic_error("using unique_jpointerArray after release"); } + T* old = (*wrapped)[index]; if (old != new_ptr) { (*wrapped)[index] = new_ptr; del(old); } } - T *get(int index) { - if (wrapped == NULL) { - throw std::logic_error("using unique_jpointerArray after release"); - } + T* get(int index) + { + if (wrapped == NULL) { throw std::logic_error("using unique_jpointerArray after release"); } return (*wrapped)[index]; } - T *const *get() { - if (wrapped == NULL) { - throw std::logic_error("using unique_jpointerArray after release"); - } + T* const* get() + { + if (wrapped == NULL) { throw std::logic_error("using unique_jpointerArray after release"); } return wrapped->data(); } - jlongArray release() { - if (wrapped == NULL) { - return NULL; - } + jlongArray release() + { + if (wrapped == NULL) { return NULL; } wrapped->commit(); jlongArray ret = wrapped->get_jArray(); wrapped.reset(NULL); return ret; } - ~unique_jpointerArray() { + ~unique_jpointerArray() + { if (wrapped != NULL) { for (int i = 0; i < wrapped->size(); i++) { reset(i, NULL); @@ -518,57 +558,62 @@ template > class unique_jpointer * @brief RAII for jstring to be sure it is handled correctly. */ class native_jstring { -private: - JNIEnv *env; + private: + JNIEnv* env; jstring orig; - mutable const char *cstr; + mutable const char* cstr; mutable size_t cstr_length; - void init_cstr() const { + void init_cstr() const + { if (orig != NULL && cstr == NULL) { cstr_length = env->GetStringUTFLength(orig); - cstr = env->GetStringUTFChars(orig, 0); + cstr = env->GetStringUTFChars(orig, 0); check_java_exception(env); } } -public: - native_jstring(native_jstring const &) = delete; - native_jstring &operator=(native_jstring const &) = delete; + public: + native_jstring(native_jstring const&) = delete; + native_jstring& operator=(native_jstring const&) = delete; - native_jstring(native_jstring &&other) noexcept - : env(other.env), orig(other.orig), cstr(other.cstr), cstr_length(other.cstr_length) { + native_jstring(native_jstring&& other) noexcept + : env(other.env), orig(other.orig), cstr(other.cstr), cstr_length(other.cstr_length) + { other.cstr = NULL; } - native_jstring(JNIEnv *const env, jstring orig) - : env(env), orig(orig), cstr(NULL), cstr_length(0) {} + native_jstring(JNIEnv* const env, jstring orig) : env(env), orig(orig), cstr(NULL), cstr_length(0) + { + } - native_jstring &operator=(native_jstring const &&other) { - if (orig != NULL && cstr != NULL) { - env->ReleaseStringUTFChars(orig, cstr); - } - this->env = other.env; - this->orig = other.orig; - this->cstr = other.cstr; + native_jstring& operator=(native_jstring const&& other) + { + if (orig != NULL && cstr != NULL) { env->ReleaseStringUTFChars(orig, cstr); } + this->env = other.env; + this->orig = other.orig; + this->cstr = other.cstr; this->cstr_length = other.cstr_length; - other.cstr = NULL; + other.cstr = NULL; return *this; } bool is_null() const noexcept { return orig == NULL; } - const char *get() const { + const char* get() const + { init_cstr(); return cstr; } - size_t size_bytes() const { + size_t size_bytes() const + { init_cstr(); return cstr_length; } - bool is_empty() const { + bool is_empty() const + { if (cstr != NULL) { return cstr_length <= 0; } else if (orig != NULL) { @@ -581,24 +626,25 @@ class native_jstring { const jstring get_jstring() const { return orig; } - ~native_jstring() { - if (orig != NULL && cstr != NULL) { - env->ReleaseStringUTFChars(orig, cstr); - } + ~native_jstring() + { + if (orig != NULL && cstr != NULL) { env->ReleaseStringUTFChars(orig, cstr); } } }; /** * @brief jobjectArray wrapper to make accessing it more convenient. */ -template class native_jobjectArray { -private: - JNIEnv *const env; +template +class native_jobjectArray { + private: + JNIEnv* const env; jobjectArray orig; int len; -public: - native_jobjectArray(JNIEnv *const env, jobjectArray orig) : env(env), orig(orig), len(0) { + public: + native_jobjectArray(JNIEnv* const env, jobjectArray orig) : env(env), orig(orig), len(0) + { if (orig != NULL) { len = env->GetArrayLength(orig); check_java_exception(env); @@ -611,19 +657,17 @@ template class native_jobjectArray { T operator[](int index) const { return get(index); } - T get(int index) const { - if (orig == NULL) { - throw_java_exception(env, NPE_CLASS, "jobjectArray pointer is NULL"); - } + T get(int index) const + { + if (orig == NULL) { throw_java_exception(env, NPE_CLASS, "jobjectArray pointer is NULL"); } T ret = static_cast(env->GetObjectArrayElement(orig, index)); check_java_exception(env); return ret; } - void set(int index, const T &val) { - if (orig == NULL) { - throw_java_exception(env, NPE_CLASS, "jobjectArray pointer is NULL"); - } + void set(int index, const T& val) + { + if (orig == NULL) { throw_java_exception(env, NPE_CLASS, "jobjectArray pointer is NULL"); } env->SetObjectArrayElement(orig, index, val); check_java_exception(env); } @@ -636,14 +680,15 @@ template class native_jobjectArray { * and convenient. */ class native_jstringArray { -private: - JNIEnv *const env; + private: + JNIEnv* const env; native_jobjectArray arr; mutable std::vector cache; mutable std::vector cpp_cache; - mutable std::vector c_cache; + mutable std::vector c_cache; - void init_cache() const { + void init_cache() const + { if (!arr.is_null() && cache.empty()) { int size = this->size(); cache.reserve(size); @@ -653,7 +698,8 @@ class native_jstringArray { } } - void init_c_cache() const { + void init_c_cache() const + { if (!arr.is_null() && c_cache.empty()) { init_cache(); int size = this->size(); @@ -664,7 +710,8 @@ class native_jstringArray { } } - void init_cpp_cache() const { + void init_cpp_cache() const + { if (!arr.is_null() && cpp_cache.empty()) { init_cache(); int size = this->size(); @@ -675,32 +722,30 @@ class native_jstringArray { } } - void update_caches(int index, jstring val) { + void update_caches(int index, jstring val) + { if (!cache.empty()) { cache[index] = native_jstring(env, val); - if (!c_cache.empty()) { - c_cache[index] = cache[index].get(); - } + if (!c_cache.empty()) { c_cache[index] = cache[index].get(); } - if (!cpp_cache.empty()) { - cpp_cache[index] = cache[index].get(); - } + if (!cpp_cache.empty()) { cpp_cache[index] = cache[index].get(); } } else if (!c_cache.empty() || !cpp_cache.empty()) { // Illegal state throw std::logic_error("CACHING IS MESSED UP"); } } -public: - native_jstringArray(JNIEnv *const env, jobjectArray orig) : env(env), arr(env, orig) {} + public: + native_jstringArray(JNIEnv* const env, jobjectArray orig) : env(env), arr(env, orig) {} bool is_null() const noexcept { return arr.is_null(); } int size() const noexcept { return arr.size(); } - native_jstring &operator[](int index) const { return get(index); } + native_jstring& operator[](int index) const { return get(index); } - native_jstring &get(int index) const { + native_jstring& get(int index) const + { if (arr.is_null()) { throw_java_exception(env, cudf::jni::NPE_CLASS, "jstringArray pointer is NULL"); } @@ -708,27 +753,32 @@ class native_jstringArray { return cache[index]; } - const char **const as_c_array() const { + const char** const as_c_array() const + { init_c_cache(); return c_cache.data(); } - const std::vector as_cpp_vector() const { + const std::vector as_cpp_vector() const + { init_cpp_cache(); return cpp_cache; } - void set(int index, jstring val) { + void set(int index, jstring val) + { arr.set(index, val); update_caches(index, val); } - void set(int index, const native_jstring &val) { + void set(int index, const native_jstring& val) + { arr.set(index, val.get_jstring()); update_caches(index, val.get_jstring()); } - void set(int index, const char *val) { + void set(int index, const char* val) + { jstring str = env->NewStringUTF(val); check_java_exception(env); arr.set(index, str); @@ -739,8 +789,9 @@ class native_jstringArray { /** * @brief create a cuda exception from a given cudaError_t */ -inline jthrowable cuda_exception(JNIEnv *const env, cudaError_t status, jthrowable cause = NULL) { - const char *ex_class_name; +inline jthrowable cuda_exception(JNIEnv* const env, cudaError_t status, jthrowable cause = NULL) +{ + const char* ex_class_name; // Calls cudaGetLastError twice. It is nearly certain that a fatal error occurred if the second // call doesn't return with cudaSuccess. @@ -755,19 +806,13 @@ inline jthrowable cuda_exception(JNIEnv *const env, cudaError_t status, jthrowab } jclass ex_class = env->FindClass(ex_class_name); - if (ex_class == NULL) { - return NULL; - } + if (ex_class == NULL) { return NULL; } jmethodID ctor_id = - env->GetMethodID(ex_class, "", "(Ljava/lang/String;ILjava/lang/Throwable;)V"); - if (ctor_id == NULL) { - return NULL; - } + env->GetMethodID(ex_class, "", "(Ljava/lang/String;ILjava/lang/Throwable;)V"); + if (ctor_id == NULL) { return NULL; } jstring msg = env->NewStringUTF(cudaGetErrorString(status)); - if (msg == NULL) { - return NULL; - } + if (msg == NULL) { return NULL; } jint err_code = static_cast(status); @@ -775,168 +820,146 @@ inline jthrowable cuda_exception(JNIEnv *const env, cudaError_t status, jthrowab return (jthrowable)ret; } -inline void jni_cuda_check(JNIEnv *const env, cudaError_t cuda_status) { +inline void jni_cuda_check(JNIEnv* const env, cudaError_t cuda_status) +{ if (cudaSuccess != cuda_status) { jthrowable jt = cuda_exception(env, cuda_status); - if (jt != NULL) { - env->Throw(jt); - } + if (jt != NULL) { env->Throw(jt); } throw jni_exception(std::string("CUDA ERROR: code ") + std::to_string(static_cast(cuda_status))); } } -inline auto add_global_ref(JNIEnv *env, jobject jobj) { +inline auto add_global_ref(JNIEnv* env, jobject jobj) +{ auto new_global_ref = env->NewGlobalRef(jobj); - if (new_global_ref == nullptr) { - throw cudf::jni::jni_exception("global ref"); - } + if (new_global_ref == nullptr) { throw cudf::jni::jni_exception("global ref"); } return new_global_ref; } -inline nullptr_t del_global_ref(JNIEnv *env, jobject jobj) { - if (jobj != nullptr) { - env->DeleteGlobalRef(jobj); - } +inline nullptr_t del_global_ref(JNIEnv* env, jobject jobj) +{ + if (jobj != nullptr) { env->DeleteGlobalRef(jobj); } return nullptr; } -} // namespace jni -} // namespace cudf +} // namespace jni +} // namespace cudf -#define JNI_EXCEPTION_OCCURRED_CHECK(env, ret_val) \ - { \ - if (env->ExceptionOccurred()) { \ - return ret_val; \ - } \ +#define JNI_EXCEPTION_OCCURRED_CHECK(env, ret_val) \ + { \ + if (env->ExceptionOccurred()) { return ret_val; } \ } -#define JNI_THROW_NEW(env, class_name, message, ret_val) \ - { \ - jclass ex_class = env->FindClass(class_name); \ - if (ex_class == NULL) { \ - return ret_val; \ - } \ - env->ThrowNew(ex_class, message); \ - return ret_val; \ +#define JNI_THROW_NEW(env, class_name, message, ret_val) \ + { \ + jclass ex_class = env->FindClass(class_name); \ + if (ex_class == NULL) { return ret_val; } \ + env->ThrowNew(ex_class, message); \ + return ret_val; \ } // Throw a new exception only if one is not pending then always return with the specified value -#define JNI_CHECK_THROW_CUDF_EXCEPTION(env, class_name, message, stacktrace, ret_val) \ - { \ - JNI_EXCEPTION_OCCURRED_CHECK(env, ret_val); \ - auto const ex_class = env->FindClass(class_name); \ - if (ex_class == nullptr) { \ - return ret_val; \ - } \ - auto const ctor_id = \ - env->GetMethodID(ex_class, "", "(Ljava/lang/String;Ljava/lang/String;)V"); \ - if (ctor_id == nullptr) { \ - return ret_val; \ - } \ - auto const empty_str = std::string{""}; \ - auto const jmessage = env->NewStringUTF(message == nullptr ? empty_str.c_str() : message); \ - if (jmessage == nullptr) { \ - return ret_val; \ - } \ - auto const jstacktrace = \ - env->NewStringUTF(stacktrace == nullptr ? empty_str.c_str() : stacktrace); \ - if (jstacktrace == nullptr) { \ - return ret_val; \ - } \ - auto const jobj = env->NewObject(ex_class, ctor_id, jmessage, jstacktrace); \ - if (jobj == nullptr) { \ - return ret_val; \ - } \ - env->Throw(reinterpret_cast(jobj)); \ - return ret_val; \ +#define JNI_CHECK_THROW_CUDF_EXCEPTION(env, class_name, message, stacktrace, ret_val) \ + { \ + JNI_EXCEPTION_OCCURRED_CHECK(env, ret_val); \ + auto const ex_class = env->FindClass(class_name); \ + if (ex_class == nullptr) { return ret_val; } \ + auto const ctor_id = \ + env->GetMethodID(ex_class, "", "(Ljava/lang/String;Ljava/lang/String;)V"); \ + if (ctor_id == nullptr) { return ret_val; } \ + auto const empty_str = std::string{""}; \ + auto const jmessage = env->NewStringUTF(message == nullptr ? empty_str.c_str() : message); \ + if (jmessage == nullptr) { return ret_val; } \ + auto const jstacktrace = \ + env->NewStringUTF(stacktrace == nullptr ? empty_str.c_str() : stacktrace); \ + if (jstacktrace == nullptr) { return ret_val; } \ + auto const jobj = env->NewObject(ex_class, ctor_id, jmessage, jstacktrace); \ + if (jobj == nullptr) { return ret_val; } \ + env->Throw(reinterpret_cast(jobj)); \ + return ret_val; \ } // Throw a new exception only if one is not pending then always return with the specified value -#define JNI_CHECK_THROW_CUDA_EXCEPTION(env, class_name, message, stacktrace, error_code, ret_val) \ - { \ - JNI_EXCEPTION_OCCURRED_CHECK(env, ret_val); \ - auto const ex_class = env->FindClass(class_name); \ - if (ex_class == nullptr) { \ - return ret_val; \ - } \ - auto const ctor_id = \ - env->GetMethodID(ex_class, "", "(Ljava/lang/String;Ljava/lang/String;I)V"); \ - if (ctor_id == nullptr) { \ - return ret_val; \ - } \ - auto const empty_str = std::string{""}; \ - auto const jmessage = env->NewStringUTF(message == nullptr ? empty_str.c_str() : message); \ - if (jmessage == nullptr) { \ - return ret_val; \ - } \ - auto const jstacktrace = \ - env->NewStringUTF(stacktrace == nullptr ? empty_str.c_str() : stacktrace); \ - if (jstacktrace == nullptr) { \ - return ret_val; \ - } \ - auto const jerror_code = static_cast(error_code); \ - auto const jobj = env->NewObject(ex_class, ctor_id, jmessage, jstacktrace, jerror_code); \ - if (jobj == nullptr) { \ - return ret_val; \ - } \ - env->Throw(reinterpret_cast(jobj)); \ - return ret_val; \ - } - -#define JNI_NULL_CHECK(env, obj, error_msg, ret_val) \ - { \ - if ((obj) == 0) { \ - JNI_THROW_NEW(env, cudf::jni::NPE_CLASS, error_msg, ret_val); \ - } \ - } - -#define JNI_ARG_CHECK(env, obj, error_msg, ret_val) \ - { \ - if (!(obj)) { \ - JNI_THROW_NEW(env, cudf::jni::ILLEGAL_ARG_CLASS, error_msg, ret_val); \ - } \ - } - -#define CATCH_STD_CLASS(env, class_name, ret_val) \ - catch (const rmm::out_of_memory &e) { \ - JNI_EXCEPTION_OCCURRED_CHECK(env, ret_val); \ - auto const what = \ - std::string("Could not allocate native memory: ") + (e.what() == nullptr ? "" : e.what()); \ - JNI_THROW_NEW(env, cudf::jni::OOM_CLASS, what.c_str(), ret_val); \ - } \ - catch (const cudf::fatal_cuda_error &e) { \ - JNI_CHECK_THROW_CUDA_EXCEPTION(env, cudf::jni::CUDA_FATAL_ERROR_CLASS, e.what(), \ - e.stacktrace(), e.error_code(), ret_val); \ - } \ - catch (const cudf::cuda_error &e) { \ - JNI_CHECK_THROW_CUDA_EXCEPTION(env, cudf::jni::CUDA_ERROR_CLASS, e.what(), e.stacktrace(), \ - e.error_code(), ret_val); \ - } \ - catch (const cudf::data_type_error &e) { \ - JNI_CHECK_THROW_CUDF_EXCEPTION(env, cudf::jni::CUDF_DTYPE_ERROR_CLASS, e.what(), \ - e.stacktrace(), ret_val); \ - } \ - catch (std::overflow_error const &e) { \ - JNI_CHECK_THROW_CUDF_EXCEPTION(env, cudf::jni::CUDF_OVERFLOW_ERROR_CLASS, e.what(), \ - "No native stacktrace is available.", ret_val); \ - } \ - catch (const std::exception &e) { \ - char const *stacktrace = "No native stacktrace is available."; \ - if (auto const cudf_ex = dynamic_cast(&e); cudf_ex != nullptr) { \ - stacktrace = cudf_ex->stacktrace(); \ - } \ - /* Double check whether the thrown exception is unrecoverable CUDA error or not. */ \ - /* Like cudf::detail::throw_cuda_error, it is nearly certain that a fatal error */ \ - /* occurred if the second call doesn't return with cudaSuccess. */ \ - cudaGetLastError(); \ - auto const last = cudaFree(0); \ - if (cudaSuccess != last && last == cudaDeviceSynchronize()) { \ - /* Throw CudaFatalException since the thrown exception is unrecoverable CUDA error */ \ - JNI_CHECK_THROW_CUDA_EXCEPTION(env, cudf::jni::CUDA_FATAL_ERROR_CLASS, e.what(), stacktrace, \ - last, ret_val); \ - } \ - JNI_CHECK_THROW_CUDF_EXCEPTION(env, class_name, e.what(), stacktrace, ret_val); \ +#define JNI_CHECK_THROW_CUDA_EXCEPTION(env, class_name, message, stacktrace, error_code, ret_val) \ + { \ + JNI_EXCEPTION_OCCURRED_CHECK(env, ret_val); \ + auto const ex_class = env->FindClass(class_name); \ + if (ex_class == nullptr) { return ret_val; } \ + auto const ctor_id = \ + env->GetMethodID(ex_class, "", "(Ljava/lang/String;Ljava/lang/String;I)V"); \ + if (ctor_id == nullptr) { return ret_val; } \ + auto const empty_str = std::string{""}; \ + auto const jmessage = env->NewStringUTF(message == nullptr ? empty_str.c_str() : message); \ + if (jmessage == nullptr) { return ret_val; } \ + auto const jstacktrace = \ + env->NewStringUTF(stacktrace == nullptr ? empty_str.c_str() : stacktrace); \ + if (jstacktrace == nullptr) { return ret_val; } \ + auto const jerror_code = static_cast(error_code); \ + auto const jobj = env->NewObject(ex_class, ctor_id, jmessage, jstacktrace, jerror_code); \ + if (jobj == nullptr) { return ret_val; } \ + env->Throw(reinterpret_cast(jobj)); \ + return ret_val; \ + } + +#define JNI_NULL_CHECK(env, obj, error_msg, ret_val) \ + { \ + if ((obj) == 0) { JNI_THROW_NEW(env, cudf::jni::NPE_CLASS, error_msg, ret_val); } \ + } + +#define JNI_ARG_CHECK(env, obj, error_msg, ret_val) \ + { \ + if (!(obj)) { JNI_THROW_NEW(env, cudf::jni::ILLEGAL_ARG_CLASS, error_msg, ret_val); } \ + } + +#define CATCH_STD_CLASS(env, class_name, ret_val) \ + catch (const rmm::out_of_memory& e) \ + { \ + JNI_EXCEPTION_OCCURRED_CHECK(env, ret_val); \ + auto const what = \ + std::string("Could not allocate native memory: ") + (e.what() == nullptr ? "" : e.what()); \ + JNI_THROW_NEW(env, cudf::jni::OOM_CLASS, what.c_str(), ret_val); \ + } \ + catch (const cudf::fatal_cuda_error& e) \ + { \ + JNI_CHECK_THROW_CUDA_EXCEPTION( \ + env, cudf::jni::CUDA_FATAL_ERROR_CLASS, e.what(), e.stacktrace(), e.error_code(), ret_val); \ + } \ + catch (const cudf::cuda_error& e) \ + { \ + JNI_CHECK_THROW_CUDA_EXCEPTION( \ + env, cudf::jni::CUDA_ERROR_CLASS, e.what(), e.stacktrace(), e.error_code(), ret_val); \ + } \ + catch (const cudf::data_type_error& e) \ + { \ + JNI_CHECK_THROW_CUDF_EXCEPTION( \ + env, cudf::jni::CUDF_DTYPE_ERROR_CLASS, e.what(), e.stacktrace(), ret_val); \ + } \ + catch (std::overflow_error const& e) \ + { \ + JNI_CHECK_THROW_CUDF_EXCEPTION(env, \ + cudf::jni::CUDF_OVERFLOW_ERROR_CLASS, \ + e.what(), \ + "No native stacktrace is available.", \ + ret_val); \ + } \ + catch (const std::exception& e) \ + { \ + char const* stacktrace = "No native stacktrace is available."; \ + if (auto const cudf_ex = dynamic_cast(&e); cudf_ex != nullptr) { \ + stacktrace = cudf_ex->stacktrace(); \ + } \ + /* Double check whether the thrown exception is unrecoverable CUDA error or not. */ \ + /* Like cudf::detail::throw_cuda_error, it is nearly certain that a fatal error */ \ + /* occurred if the second call doesn't return with cudaSuccess. */ \ + cudaGetLastError(); \ + auto const last = cudaFree(0); \ + if (cudaSuccess != last && last == cudaDeviceSynchronize()) { \ + /* Throw CudaFatalException since the thrown exception is unrecoverable CUDA error */ \ + JNI_CHECK_THROW_CUDA_EXCEPTION( \ + env, cudf::jni::CUDA_FATAL_ERROR_CLASS, e.what(), stacktrace, last, ret_val); \ + } \ + JNI_CHECK_THROW_CUDF_EXCEPTION(env, class_name, e.what(), stacktrace, ret_val); \ } #define CATCH_STD(env, ret_val) CATCH_STD_CLASS(env, cudf::jni::CUDF_ERROR_CLASS, ret_val) diff --git a/java/src/main/native/include/maps_column_view.hpp b/java/src/main/native/include/maps_column_view.hpp index 7d19615053d..be25dbd2e55 100644 --- a/java/src/main/native/include/maps_column_view.hpp +++ b/java/src/main/native/include/maps_column_view.hpp @@ -19,6 +19,7 @@ #include #include #include + #include #include #include @@ -38,16 +39,16 @@ namespace jni { * retrieve the corresponding value. */ class maps_column_view { -public: - maps_column_view(lists_column_view const &lists_of_structs, + public: + maps_column_view(lists_column_view const& lists_of_structs, rmm::cuda_stream_view stream = cudf::get_default_stream()); // Rule of 5. - maps_column_view(maps_column_view const &maps_view) = default; - maps_column_view(maps_column_view &&maps_view) = default; - maps_column_view &operator=(maps_column_view const &) = default; - maps_column_view &operator=(maps_column_view &&) = default; - ~maps_column_view() = default; + maps_column_view(maps_column_view const& maps_view) = default; + maps_column_view(maps_column_view&& maps_view) = default; + maps_column_view& operator=(maps_column_view const&) = default; + maps_column_view& operator=(maps_column_view&&) = default; + ~maps_column_view() = default; /** * @brief Returns number of map rows in the column. @@ -59,14 +60,14 @@ class maps_column_view { * * Note: Keys are not deduped. Repeated keys are returned in order. */ - lists_column_view const &keys() const { return keys_; } + lists_column_view const& keys() const { return keys_; } /** * @brief Getter for values as a list column. * * Note: Values for repeated keys are not dropped. */ - lists_column_view const &values() const { return values_; } + lists_column_view const& values() const { return values_; } /** * @brief Map lookup by a column of keys. @@ -83,9 +84,10 @@ class maps_column_view { * @param mr Device memory resource used to allocate the returned column's device memory. * @return std::unique_ptr Column of values corresponding the value of the lookup key. */ - std::unique_ptr - get_values_for(column_view const &keys, rmm::cuda_stream_view stream = cudf::get_default_stream(), - rmm::device_async_resource_ref mr = rmm::mr::get_current_device_resource()) const; + std::unique_ptr get_values_for( + column_view const& keys, + rmm::cuda_stream_view stream = cudf::get_default_stream(), + rmm::device_async_resource_ref mr = rmm::mr::get_current_device_resource()) const; /** * @brief Map lookup by a scalar key. @@ -101,9 +103,10 @@ class maps_column_view { * @param mr Device memory resource used to allocate the returned column's device memory. * @return std::unique_ptr */ - std::unique_ptr - get_values_for(scalar const &key, rmm::cuda_stream_view stream = cudf::get_default_stream(), - rmm::device_async_resource_ref mr = rmm::mr::get_current_device_resource()) const; + std::unique_ptr get_values_for( + scalar const& key, + rmm::cuda_stream_view stream = cudf::get_default_stream(), + rmm::device_async_resource_ref mr = rmm::mr::get_current_device_resource()) const; /** * @brief Check if each map row contains a specified scalar key. @@ -121,9 +124,10 @@ class maps_column_view { * @param mr Device memory resource used to allocate the returned column's device memory. * @return std::unique_ptr */ - std::unique_ptr - contains(scalar const &key, rmm::cuda_stream_view stream = cudf::get_default_stream(), - rmm::device_async_resource_ref mr = rmm::mr::get_current_device_resource()) const; + std::unique_ptr contains( + scalar const& key, + rmm::cuda_stream_view stream = cudf::get_default_stream(), + rmm::device_async_resource_ref mr = rmm::mr::get_current_device_resource()) const; /** * @brief Check if each map row contains keys specified by a column @@ -142,13 +146,14 @@ class maps_column_view { * @return std::unique_ptr */ - std::unique_ptr - contains(column_view const &key, rmm::cuda_stream_view stream = cudf::get_default_stream(), - rmm::device_async_resource_ref mr = rmm::mr::get_current_device_resource()) const; + std::unique_ptr contains( + column_view const& key, + rmm::cuda_stream_view stream = cudf::get_default_stream(), + rmm::device_async_resource_ref mr = rmm::mr::get_current_device_resource()) const; -private: + private: lists_column_view keys_, values_; }; -} // namespace jni -} // namespace cudf +} // namespace jni +} // namespace cudf diff --git a/java/src/main/native/src/Aggregation128UtilsJni.cpp b/java/src/main/native/src/Aggregation128UtilsJni.cpp index 71c36cb724a..ed8a8dc1e5c 100644 --- a/java/src/main/native/src/Aggregation128UtilsJni.cpp +++ b/java/src/main/native/src/Aggregation128UtilsJni.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, NVIDIA CORPORATION. + * Copyright (c) 2022-2024, NVIDIA CORPORATION. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,11 +21,12 @@ extern "C" { JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Aggregation128Utils_extractInt32Chunk( - JNIEnv *env, jclass, jlong j_column_view, jint j_out_dtype, jint j_chunk_idx) { + JNIEnv* env, jclass, jlong j_column_view, jint j_out_dtype, jint j_chunk_idx) +{ JNI_NULL_CHECK(env, j_column_view, "column is null", 0); try { cudf::jni::auto_set_device(env); - auto cview = reinterpret_cast(j_column_view); + auto cview = reinterpret_cast(j_column_view); auto dtype = cudf::jni::make_data_type(j_out_dtype, 0); return cudf::jni::release_as_jlong(cudf::jni::extract_chunk32(*cview, dtype, j_chunk_idx)); } @@ -33,13 +34,14 @@ JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Aggregation128Utils_extractInt32Chun } JNIEXPORT jlongArray JNICALL Java_ai_rapids_cudf_Aggregation128Utils_combineInt64SumChunks( - JNIEnv *env, jclass, jlong j_table_view, jint j_dtype, jint j_scale) { + JNIEnv* env, jclass, jlong j_table_view, jint j_dtype, jint j_scale) +{ JNI_NULL_CHECK(env, j_table_view, "table is null", 0); try { cudf::jni::auto_set_device(env); - auto tview = reinterpret_cast(j_table_view); + auto tview = reinterpret_cast(j_table_view); std::unique_ptr result = - cudf::jni::assemble128_from_sum(*tview, cudf::jni::make_data_type(j_dtype, j_scale)); + cudf::jni::assemble128_from_sum(*tview, cudf::jni::make_data_type(j_dtype, j_scale)); return cudf::jni::convert_table_for_return(env, result); } CATCH_STD(env, 0); diff --git a/java/src/main/native/src/AggregationJni.cpp b/java/src/main/native/src/AggregationJni.cpp index bc62e95c36a..c40f1c55500 100644 --- a/java/src/main/native/src/AggregationJni.cpp +++ b/java/src/main/native/src/AggregationJni.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020-2023, NVIDIA CORPORATION. + * Copyright (c) 2020-2024, NVIDIA CORPORATION. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,85 +14,91 @@ * limitations under the License. */ -#include - #include "cudf_jni_apis.hpp" +#include + extern "C" { -JNIEXPORT void JNICALL Java_ai_rapids_cudf_Aggregation_close(JNIEnv *env, jclass class_object, - jlong ptr) { +JNIEXPORT void JNICALL Java_ai_rapids_cudf_Aggregation_close(JNIEnv* env, + jclass class_object, + jlong ptr) +{ try { cudf::jni::auto_set_device(env); - auto to_del = reinterpret_cast(ptr); + auto to_del = reinterpret_cast(ptr); delete to_del; } CATCH_STD(env, ); } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Aggregation_createNoParamAgg(JNIEnv *env, +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Aggregation_createNoParamAgg(JNIEnv* env, jclass class_object, - jint kind) { + jint kind) +{ try { cudf::jni::auto_set_device(env); auto ret = [&] { // These numbers come from Aggregation.java and must stay in sync switch (kind) { - case 0: // SUM + case 0: // SUM return cudf::make_sum_aggregation(); - case 1: // PRODUCT + case 1: // PRODUCT return cudf::make_product_aggregation(); - case 2: // MIN + case 2: // MIN return cudf::make_min_aggregation(); - case 3: // MAX + case 3: // MAX return cudf::make_max_aggregation(); // case 4 COUNT - case 5: // ANY + case 5: // ANY return cudf::make_any_aggregation(); - case 6: // ALL + case 6: // ALL return cudf::make_all_aggregation(); - case 7: // SUM_OF_SQUARES + case 7: // SUM_OF_SQUARES return cudf::make_sum_of_squares_aggregation(); - case 8: // MEAN + case 8: // MEAN return cudf::make_mean_aggregation(); // case 9: VARIANCE // case 10: STD - case 11: // MEDIAN + case 11: // MEDIAN return cudf::make_median_aggregation(); // case 12: QUANTILE - case 13: // ARGMAX + case 13: // ARGMAX return cudf::make_argmax_aggregation(); - case 14: // ARGMIN + case 14: // ARGMIN return cudf::make_argmin_aggregation(); // case 15: NUNIQUE // case 16: NTH_ELEMENT - case 17: // ROW_NUMBER + case 17: // ROW_NUMBER return cudf::make_row_number_aggregation(); // case 18: COLLECT_LIST // case 19: COLLECT_SET - case 20: // MERGE_LISTS + case 20: // MERGE_LISTS return cudf::make_merge_lists_aggregation(); // case 21: MERGE_SETS // case 22: LEAD // case 23: LAG // case 24: PTX // case 25: CUDA - case 26: // M2 + case 26: // M2 return cudf::make_m2_aggregation(); - case 27: // MERGE_M2 + case 27: // MERGE_M2 return cudf::make_merge_m2_aggregation(); - case 28: // RANK - return cudf::make_rank_aggregation(cudf::rank_method::MIN, {}, - cudf::null_policy::INCLUDE); - case 29: // DENSE_RANK - return cudf::make_rank_aggregation(cudf::rank_method::DENSE, {}, - cudf::null_policy::INCLUDE); - case 30: // ANSI SQL PERCENT_RANK - return cudf::make_rank_aggregation(cudf::rank_method::MIN, {}, cudf::null_policy::INCLUDE, - {}, cudf::rank_percentage::ONE_NORMALIZED); - case 33: // HISTOGRAM + case 28: // RANK + return cudf::make_rank_aggregation( + cudf::rank_method::MIN, {}, cudf::null_policy::INCLUDE); + case 29: // DENSE_RANK + return cudf::make_rank_aggregation( + cudf::rank_method::DENSE, {}, cudf::null_policy::INCLUDE); + case 30: // ANSI SQL PERCENT_RANK + return cudf::make_rank_aggregation(cudf::rank_method::MIN, + {}, + cudf::null_policy::INCLUDE, + {}, + cudf::rank_percentage::ONE_NORMALIZED); + case 33: // HISTOGRAM return cudf::make_histogram_aggregation(); - case 34: // MERGE_HISTOGRAM + case 34: // MERGE_HISTOGRAM return cudf::make_merge_histogram_aggregation(); default: throw std::logic_error("Unsupported No Parameter Aggregation Operation"); @@ -104,33 +110,36 @@ JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Aggregation_createNoParamAgg(JNIEnv CATCH_STD(env, 0); } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Aggregation_createNthAgg(JNIEnv *env, +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Aggregation_createNthAgg(JNIEnv* env, jclass class_object, jint offset, - jboolean include_nulls) { + jboolean include_nulls) +{ try { cudf::jni::auto_set_device(env); std::unique_ptr ret = cudf::make_nth_element_aggregation( - offset, include_nulls ? cudf::null_policy::INCLUDE : cudf::null_policy::EXCLUDE); + offset, include_nulls ? cudf::null_policy::INCLUDE : cudf::null_policy::EXCLUDE); return reinterpret_cast(ret.release()); } CATCH_STD(env, 0); } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Aggregation_createDdofAgg(JNIEnv *env, +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Aggregation_createDdofAgg(JNIEnv* env, jclass class_object, - jint kind, jint ddof) { + jint kind, + jint ddof) +{ try { cudf::jni::auto_set_device(env); std::unique_ptr ret; // These numbers come from Aggregation.java and must stay in sync switch (kind) { - case 9: // VARIANCE + case 9: // VARIANCE ret = cudf::make_variance_aggregation(ddof); break; - case 10: // STD + case 10: // STD ret = cudf::make_std_aggregation(ddof); break; default: throw std::logic_error("Unsupported DDOF Aggregation Operation"); @@ -140,19 +149,21 @@ JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Aggregation_createDdofAgg(JNIEnv *en CATCH_STD(env, 0); } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Aggregation_createTDigestAgg(JNIEnv *env, +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Aggregation_createTDigestAgg(JNIEnv* env, jclass class_object, - jint kind, jint delta) { + jint kind, + jint delta) +{ try { cudf::jni::auto_set_device(env); std::unique_ptr ret; // These numbers come from Aggregation.java and must stay in sync switch (kind) { - case 31: // TDIGEST + case 31: // TDIGEST ret = cudf::make_tdigest_aggregation(delta); break; - case 32: // MERGE_TDIGEST + case 32: // MERGE_TDIGEST ret = cudf::make_merge_tdigest_aggregation(delta); break; default: throw std::logic_error("Unsupported TDigest Aggregation Operation"); @@ -162,22 +173,23 @@ JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Aggregation_createTDigestAgg(JNIEnv CATCH_STD(env, 0); } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Aggregation_createCountLikeAgg(JNIEnv *env, +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Aggregation_createCountLikeAgg(JNIEnv* env, jclass class_object, jint kind, - jboolean include_nulls) { + jboolean include_nulls) +{ try { cudf::jni::auto_set_device(env); cudf::null_policy policy = - include_nulls ? cudf::null_policy::INCLUDE : cudf::null_policy::EXCLUDE; + include_nulls ? cudf::null_policy::INCLUDE : cudf::null_policy::EXCLUDE; std::unique_ptr ret; // These numbers come from Aggregation.java and must stay in sync switch (kind) { - case 4: // COUNT + case 4: // COUNT ret = cudf::make_count_aggregation(policy); break; - case 15: // NUNIQUE + case 15: // NUNIQUE ret = cudf::make_nunique_aggregation(policy); break; default: throw std::logic_error("Unsupported Count Like Aggregation Operation"); @@ -187,10 +199,11 @@ JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Aggregation_createCountLikeAgg(JNIEn CATCH_STD(env, 0); } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Aggregation_createQuantAgg(JNIEnv *env, +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Aggregation_createQuantAgg(JNIEnv* env, jclass class_object, jint j_method, - jdoubleArray j_quantiles) { + jdoubleArray j_quantiles) +{ JNI_NULL_CHECK(env, j_quantiles, "quantiles are null", 0); try { cudf::jni::auto_set_device(env); @@ -206,19 +219,21 @@ JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Aggregation_createQuantAgg(JNIEnv *e CATCH_STD(env, 0); } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Aggregation_createLeadLagAgg(JNIEnv *env, +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Aggregation_createLeadLagAgg(JNIEnv* env, jclass class_object, - jint kind, jint offset) { + jint kind, + jint offset) +{ try { cudf::jni::auto_set_device(env); std::unique_ptr ret; // These numbers come from Aggregation.java and must stay in sync switch (kind) { - case 22: // LEAD + case 22: // LEAD ret = cudf::make_lead_aggregation(offset); break; - case 23: // LAG + case 23: // LAG ret = cudf::make_lag_aggregation(offset); break; default: throw std::logic_error("Unsupported Lead/Lag Aggregation Operation"); @@ -228,53 +243,57 @@ JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Aggregation_createLeadLagAgg(JNIEnv CATCH_STD(env, 0); } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Aggregation_createCollectListAgg( - JNIEnv *env, jclass class_object, jboolean include_nulls) { +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Aggregation_createCollectListAgg(JNIEnv* env, + jclass class_object, + jboolean include_nulls) +{ try { cudf::jni::auto_set_device(env); cudf::null_policy policy = - include_nulls ? cudf::null_policy::INCLUDE : cudf::null_policy::EXCLUDE; + include_nulls ? cudf::null_policy::INCLUDE : cudf::null_policy::EXCLUDE; std::unique_ptr ret = cudf::make_collect_list_aggregation(policy); return reinterpret_cast(ret.release()); } CATCH_STD(env, 0); } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Aggregation_createCollectSetAgg(JNIEnv *env, +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Aggregation_createCollectSetAgg(JNIEnv* env, jclass class_object, jboolean include_nulls, jboolean nulls_equal, - jboolean nans_equal) { + jboolean nans_equal) +{ try { cudf::jni::auto_set_device(env); cudf::null_policy null_policy = - include_nulls ? cudf::null_policy::INCLUDE : cudf::null_policy::EXCLUDE; + include_nulls ? cudf::null_policy::INCLUDE : cudf::null_policy::EXCLUDE; cudf::null_equality null_equality = - nulls_equal ? cudf::null_equality::EQUAL : cudf::null_equality::UNEQUAL; + nulls_equal ? cudf::null_equality::EQUAL : cudf::null_equality::UNEQUAL; cudf::nan_equality nan_equality = - nans_equal ? cudf::nan_equality::ALL_EQUAL : cudf::nan_equality::UNEQUAL; + nans_equal ? cudf::nan_equality::ALL_EQUAL : cudf::nan_equality::UNEQUAL; std::unique_ptr ret = - cudf::make_collect_set_aggregation(null_policy, null_equality, nan_equality); + cudf::make_collect_set_aggregation(null_policy, null_equality, nan_equality); return reinterpret_cast(ret.release()); } CATCH_STD(env, 0); } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Aggregation_createMergeSetsAgg(JNIEnv *env, +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Aggregation_createMergeSetsAgg(JNIEnv* env, jclass class_object, jboolean nulls_equal, - jboolean nans_equal) { + jboolean nans_equal) +{ try { cudf::jni::auto_set_device(env); cudf::null_equality null_equality = - nulls_equal ? cudf::null_equality::EQUAL : cudf::null_equality::UNEQUAL; + nulls_equal ? cudf::null_equality::EQUAL : cudf::null_equality::UNEQUAL; cudf::nan_equality nan_equality = - nans_equal ? cudf::nan_equality::ALL_EQUAL : cudf::nan_equality::UNEQUAL; + nans_equal ? cudf::nan_equality::ALL_EQUAL : cudf::nan_equality::UNEQUAL; std::unique_ptr ret = - cudf::make_merge_sets_aggregation(null_equality, nan_equality); + cudf::make_merge_sets_aggregation(null_equality, nan_equality); return reinterpret_cast(ret.release()); } CATCH_STD(env, 0); } -} // extern "C" +} // extern "C" diff --git a/java/src/main/native/src/ChunkedPackJni.cpp b/java/src/main/native/src/ChunkedPackJni.cpp index 746a67e1463..2512d74a113 100644 --- a/java/src/main/native/src/ChunkedPackJni.cpp +++ b/java/src/main/native/src/ChunkedPackJni.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023, NVIDIA CORPORATION. + * Copyright (c) 2023-2024, NVIDIA CORPORATION. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,59 +17,65 @@ #include "cudf_jni_apis.hpp" extern "C" { -JNIEXPORT void JNICALL Java_ai_rapids_cudf_ChunkedPack_chunkedPackDelete(JNIEnv *env, jclass, - jlong chunked_pack) { +JNIEXPORT void JNICALL Java_ai_rapids_cudf_ChunkedPack_chunkedPackDelete(JNIEnv* env, + jclass, + jlong chunked_pack) +{ try { cudf::jni::auto_set_device(env); - auto cs = reinterpret_cast(chunked_pack); + auto cs = reinterpret_cast(chunked_pack); delete cs; } CATCH_STD(env, ); } JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ChunkedPack_chunkedPackGetTotalContiguousSize( - JNIEnv *env, jclass, jlong chunked_pack) { + JNIEnv* env, jclass, jlong chunked_pack) +{ try { cudf::jni::auto_set_device(env); - auto cs = reinterpret_cast(chunked_pack); + auto cs = reinterpret_cast(chunked_pack); return cs->get_total_contiguous_size(); } CATCH_STD(env, 0); } -JNIEXPORT jboolean JNICALL Java_ai_rapids_cudf_ChunkedPack_chunkedPackHasNext(JNIEnv *env, jclass, - jlong chunked_pack) { +JNIEXPORT jboolean JNICALL Java_ai_rapids_cudf_ChunkedPack_chunkedPackHasNext(JNIEnv* env, + jclass, + jlong chunked_pack) +{ try { cudf::jni::auto_set_device(env); - auto cs = reinterpret_cast(chunked_pack); + auto cs = reinterpret_cast(chunked_pack); return cs->has_next(); } CATCH_STD(env, 0); } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ChunkedPack_chunkedPackNext(JNIEnv *env, jclass, - jlong chunked_pack, - jlong user_ptr, - jlong user_ptr_size) { +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ChunkedPack_chunkedPackNext( + JNIEnv* env, jclass, jlong chunked_pack, jlong user_ptr, jlong user_ptr_size) +{ try { cudf::jni::auto_set_device(env); - auto cs = reinterpret_cast(chunked_pack); - auto user_buffer_span = cudf::device_span(reinterpret_cast(user_ptr), + auto cs = reinterpret_cast(chunked_pack); + auto user_buffer_span = cudf::device_span(reinterpret_cast(user_ptr), static_cast(user_ptr_size)); return cs->next(user_buffer_span); } CATCH_STD(env, 0); } -JNIEXPORT jlong JNICALL -Java_ai_rapids_cudf_ChunkedPack_chunkedPackBuildMetadata(JNIEnv *env, jclass, jlong chunked_pack) { +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ChunkedPack_chunkedPackBuildMetadata(JNIEnv* env, + jclass, + jlong chunked_pack) +{ try { cudf::jni::auto_set_device(env); - auto cs = reinterpret_cast(chunked_pack); + auto cs = reinterpret_cast(chunked_pack); std::unique_ptr> result = cs->build_metadata(); return reinterpret_cast(result.release()); } CATCH_STD(env, 0); } -} // extern "C" +} // extern "C" diff --git a/java/src/main/native/src/ChunkedReaderJni.cpp b/java/src/main/native/src/ChunkedReaderJni.cpp index 5ce23bbe712..7681008f584 100644 --- a/java/src/main/native/src/ChunkedReaderJni.cpp +++ b/java/src/main/native/src/ChunkedReaderJni.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2023, NVIDIA CORPORATION. + * Copyright (c) 2022-2024, NVIDIA CORPORATION. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,20 +14,21 @@ * limitations under the License. */ -#include -#include +#include "cudf_jni_apis.hpp" +#include "jni_utils.hpp" #include #include #include -#include "cudf_jni_apis.hpp" -#include "jni_utils.hpp" +#include +#include // This function is defined in `TableJni.cpp`. -jlongArray -cudf::jni::convert_table_for_return(JNIEnv *env, std::unique_ptr &&table_result, - std::vector> &&extra_columns); +jlongArray cudf::jni::convert_table_for_return( + JNIEnv* env, + std::unique_ptr&& table_result, + std::vector>&& extra_columns); // This file is for the code related to chunked reader (Parquet, ORC, etc.). @@ -35,18 +36,28 @@ extern "C" { // This function should take all the parameters that `Table.readParquet` takes, // plus one more parameter `long chunkSizeByteLimit`. -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ParquetChunkedReader_create( - JNIEnv *env, jclass, jlong chunk_read_limit, jlong pass_read_limit, - jobjectArray filter_col_names, jbooleanArray j_col_binary_read, jstring inp_file_path, - jlong buffer, jlong buffer_length, jint unit) { +JNIEXPORT jlong JNICALL +Java_ai_rapids_cudf_ParquetChunkedReader_create(JNIEnv* env, + jclass, + jlong chunk_read_limit, + jlong pass_read_limit, + jobjectArray filter_col_names, + jbooleanArray j_col_binary_read, + jstring inp_file_path, + jlong buffer, + jlong buffer_length, + jint unit) +{ JNI_NULL_CHECK(env, j_col_binary_read, "Null col_binary_read", 0); bool read_buffer = true; if (buffer == 0) { JNI_NULL_CHECK(env, inp_file_path, "Input file or buffer must be supplied", 0); read_buffer = false; } else if (inp_file_path != nullptr) { - JNI_THROW_NEW(env, "java/lang/IllegalArgumentException", - "Cannot pass in both a buffer and an inp_file_path", 0); + JNI_THROW_NEW(env, + "java/lang/IllegalArgumentException", + "Cannot pass in both a buffer and an inp_file_path", + 0); } else if (buffer_length <= 0) { JNI_THROW_NEW(env, "java/lang/IllegalArgumentException", "An empty buffer is not supported", 0); } @@ -66,29 +77,35 @@ JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ParquetChunkedReader_create( cudf::jni::native_jbooleanArray n_col_binary_read(env, j_col_binary_read); (void)n_col_binary_read; - auto const source = read_buffer ? - cudf::io::source_info(reinterpret_cast(buffer), - static_cast(buffer_length)) : - cudf::io::source_info(filename.get()); + auto const source = read_buffer ? cudf::io::source_info(reinterpret_cast(buffer), + static_cast(buffer_length)) + : cudf::io::source_info(filename.get()); auto opts_builder = cudf::io::parquet_reader_options::builder(source); if (n_filter_col_names.size() > 0) { opts_builder = opts_builder.columns(n_filter_col_names.as_cpp_vector()); } auto const read_opts = opts_builder.convert_strings_to_categories(false) - .timestamp_type(cudf::data_type(static_cast(unit))) - .build(); + .timestamp_type(cudf::data_type(static_cast(unit))) + .build(); return reinterpret_cast( - new cudf::io::chunked_parquet_reader(static_cast(chunk_read_limit), - static_cast(pass_read_limit), read_opts)); + new cudf::io::chunked_parquet_reader(static_cast(chunk_read_limit), + static_cast(pass_read_limit), + read_opts)); } CATCH_STD(env, 0); } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ParquetChunkedReader_createWithDataSource( - JNIEnv *env, jclass, jlong chunk_read_limit, jobjectArray filter_col_names, - jbooleanArray j_col_binary_read, jint unit, jlong ds_handle) { +JNIEXPORT jlong JNICALL +Java_ai_rapids_cudf_ParquetChunkedReader_createWithDataSource(JNIEnv* env, + jclass, + jlong chunk_read_limit, + jobjectArray filter_col_names, + jbooleanArray j_col_binary_read, + jint unit, + jlong ds_handle) +{ JNI_NULL_CHECK(env, j_col_binary_read, "Null col_binary_read", 0); JNI_NULL_CHECK(env, ds_handle, "Null DataSouurce", 0); @@ -103,7 +120,7 @@ JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ParquetChunkedReader_createWithDataS cudf::jni::native_jbooleanArray n_col_binary_read(env, j_col_binary_read); (void)n_col_binary_read; - auto ds = reinterpret_cast(ds_handle); + auto ds = reinterpret_cast(ds_handle); cudf::io::source_info source{ds}; auto opts_builder = cudf::io::parquet_reader_options::builder(source); @@ -111,49 +128,55 @@ JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ParquetChunkedReader_createWithDataS opts_builder = opts_builder.columns(n_filter_col_names.as_cpp_vector()); } auto const read_opts = opts_builder.convert_strings_to_categories(false) - .timestamp_type(cudf::data_type(static_cast(unit))) - .build(); + .timestamp_type(cudf::data_type(static_cast(unit))) + .build(); - return reinterpret_cast(new cudf::io::chunked_parquet_reader( - static_cast(chunk_read_limit), read_opts)); + return reinterpret_cast( + new cudf::io::chunked_parquet_reader(static_cast(chunk_read_limit), read_opts)); } CATCH_STD(env, 0); } -JNIEXPORT jboolean JNICALL Java_ai_rapids_cudf_ParquetChunkedReader_hasNext(JNIEnv *env, jclass, - jlong handle) { +JNIEXPORT jboolean JNICALL Java_ai_rapids_cudf_ParquetChunkedReader_hasNext(JNIEnv* env, + jclass, + jlong handle) +{ JNI_NULL_CHECK(env, handle, "handle is null", false); try { cudf::jni::auto_set_device(env); - auto const reader_ptr = reinterpret_cast(handle); + auto const reader_ptr = reinterpret_cast(handle); return reader_ptr->has_next(); } CATCH_STD(env, false); } -JNIEXPORT jlongArray JNICALL Java_ai_rapids_cudf_ParquetChunkedReader_readChunk(JNIEnv *env, jclass, - jlong handle) { +JNIEXPORT jlongArray JNICALL Java_ai_rapids_cudf_ParquetChunkedReader_readChunk(JNIEnv* env, + jclass, + jlong handle) +{ JNI_NULL_CHECK(env, handle, "handle is null", 0); try { cudf::jni::auto_set_device(env); - auto const reader_ptr = reinterpret_cast(handle); - auto chunk = reader_ptr->read_chunk(); + auto const reader_ptr = reinterpret_cast(handle); + auto chunk = reader_ptr->read_chunk(); return chunk.tbl ? cudf::jni::convert_table_for_return(env, chunk.tbl) : nullptr; } CATCH_STD(env, 0); } -JNIEXPORT void JNICALL Java_ai_rapids_cudf_ParquetChunkedReader_close(JNIEnv *env, jclass, - jlong handle) { +JNIEXPORT void JNICALL Java_ai_rapids_cudf_ParquetChunkedReader_close(JNIEnv* env, + jclass, + jlong handle) +{ JNI_NULL_CHECK(env, handle, "handle is null", ); try { cudf::jni::auto_set_device(env); - delete reinterpret_cast(handle); + delete reinterpret_cast(handle); } CATCH_STD(env, ); } -} // extern "C" +} // extern "C" diff --git a/java/src/main/native/src/ColumnVectorJni.cpp b/java/src/main/native/src/ColumnVectorJni.cpp index e8a89f82a13..30a04e37d2c 100644 --- a/java/src/main/native/src/ColumnVectorJni.cpp +++ b/java/src/main/native/src/ColumnVectorJni.cpp @@ -14,9 +14,10 @@ * limitations under the License. */ -#include +#include "cudf_jni_apis.hpp" +#include "dtype_utils.hpp" +#include "jni_utils.hpp" -#include #include #include #include @@ -33,90 +34,96 @@ #include #include #include + #include -#include "cudf_jni_apis.hpp" -#include "dtype_utils.hpp" -#include "jni_utils.hpp" +#include + +#include using cudf::jni::ptr_as_jlong; using cudf::jni::release_as_jlong; extern "C" { -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnVector_sequence(JNIEnv *env, jclass, - jlong j_initial_val, jlong j_step, - jint row_count) { +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnVector_sequence( + JNIEnv* env, jclass, jlong j_initial_val, jlong j_step, jint row_count) +{ JNI_NULL_CHECK(env, j_initial_val, "scalar is null", 0); try { cudf::jni::auto_set_device(env); - auto initial_val = reinterpret_cast(j_initial_val); - auto step = reinterpret_cast(j_step); - return release_as_jlong(step ? cudf::sequence(row_count, *initial_val, *step) : - cudf::sequence(row_count, *initial_val)); + auto initial_val = reinterpret_cast(j_initial_val); + auto step = reinterpret_cast(j_step); + return release_as_jlong(step ? cudf::sequence(row_count, *initial_val, *step) + : cudf::sequence(row_count, *initial_val)); } CATCH_STD(env, 0); } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnVector_sequences(JNIEnv *env, jclass, - jlong j_start_handle, - jlong j_size_handle, - jlong j_step_handle) { +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnVector_sequences( + JNIEnv* env, jclass, jlong j_start_handle, jlong j_size_handle, jlong j_step_handle) +{ JNI_NULL_CHECK(env, j_start_handle, "start is null", 0); JNI_NULL_CHECK(env, j_size_handle, "size is null", 0); try { cudf::jni::auto_set_device(env); - auto start = reinterpret_cast(j_start_handle); - auto size = reinterpret_cast(j_size_handle); - auto step = reinterpret_cast(j_step_handle); + auto start = reinterpret_cast(j_start_handle); + auto size = reinterpret_cast(j_size_handle); + auto step = reinterpret_cast(j_step_handle); auto ret = - step ? cudf::lists::sequences(*start, *step, *size) : cudf::lists::sequences(*start, *size); + step ? cudf::lists::sequences(*start, *step, *size) : cudf::lists::sequences(*start, *size); return release_as_jlong(ret); } CATCH_STD(env, 0); } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnVector_fromArrow( - JNIEnv *env, jclass, jint j_type, jlong j_col_length, jlong j_null_count, jobject j_data_obj, - jobject j_validity_obj, jobject j_offsets_obj) { +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnVector_fromArrow(JNIEnv* env, + jclass, + jint j_type, + jlong j_col_length, + jlong j_null_count, + jobject j_data_obj, + jobject j_validity_obj, + jobject j_offsets_obj) +{ try { cudf::jni::auto_set_device(env); cudf::type_id n_type = static_cast(j_type); // not all the buffers are used for all types - void const *data_address = 0; - int data_length = 0; + void const* data_address = 0; + int data_length = 0; if (j_data_obj != 0) { data_address = env->GetDirectBufferAddress(j_data_obj); - data_length = env->GetDirectBufferCapacity(j_data_obj); + data_length = env->GetDirectBufferCapacity(j_data_obj); } - void const *validity_address = 0; - int validity_length = 0; + void const* validity_address = 0; + int validity_length = 0; if (j_validity_obj != 0) { validity_address = env->GetDirectBufferAddress(j_validity_obj); - validity_length = env->GetDirectBufferCapacity(j_validity_obj); + validity_length = env->GetDirectBufferCapacity(j_validity_obj); } - void const *offsets_address = 0; - int offsets_length = 0; + void const* offsets_address = 0; + int offsets_length = 0; if (j_offsets_obj != 0) { offsets_address = env->GetDirectBufferAddress(j_offsets_obj); - offsets_length = env->GetDirectBufferCapacity(j_offsets_obj); + offsets_length = env->GetDirectBufferCapacity(j_offsets_obj); } auto data_buffer = - arrow::Buffer::Wrap(static_cast(data_address), static_cast(data_length)); - auto null_buffer = arrow::Buffer::Wrap(static_cast(validity_address), + arrow::Buffer::Wrap(static_cast(data_address), static_cast(data_length)); + auto null_buffer = arrow::Buffer::Wrap(static_cast(validity_address), static_cast(validity_length)); - auto offsets_buffer = arrow::Buffer::Wrap(static_cast(offsets_address), + auto offsets_buffer = arrow::Buffer::Wrap(static_cast(offsets_address), static_cast(offsets_length)); std::shared_ptr arrow_array; switch (n_type) { case cudf::type_id::DECIMAL32: - JNI_THROW_NEW(env, cudf::jni::ILLEGAL_ARG_CLASS, "Don't support converting DECIMAL32 yet", - 0); + JNI_THROW_NEW( + env, cudf::jni::ILLEGAL_ARG_CLASS, "Don't support converting DECIMAL32 yet", 0); break; case cudf::type_id::DECIMAL64: - JNI_THROW_NEW(env, cudf::jni::ILLEGAL_ARG_CLASS, "Don't support converting DECIMAL64 yet", - 0); + JNI_THROW_NEW( + env, cudf::jni::ILLEGAL_ARG_CLASS, "Don't support converting DECIMAL64 yet", 0); break; case cudf::type_id::STRUCT: JNI_THROW_NEW(env, cudf::jni::ILLEGAL_ARG_CLASS, "Don't support converting STRUCT yet", 0); @@ -125,23 +132,23 @@ JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnVector_fromArrow( JNI_THROW_NEW(env, cudf::jni::ILLEGAL_ARG_CLASS, "Don't support converting LIST yet", 0); break; case cudf::type_id::DICTIONARY32: - JNI_THROW_NEW(env, cudf::jni::ILLEGAL_ARG_CLASS, - "Don't support converting DICTIONARY32 yet", 0); + JNI_THROW_NEW( + env, cudf::jni::ILLEGAL_ARG_CLASS, "Don't support converting DICTIONARY32 yet", 0); break; case cudf::type_id::STRING: - arrow_array = std::make_shared(j_col_length, offsets_buffer, - data_buffer, null_buffer, j_null_count); + arrow_array = std::make_shared( + j_col_length, offsets_buffer, data_buffer, null_buffer, j_null_count); break; default: // this handles the primitive types - arrow_array = cudf::detail::to_arrow_array(n_type, j_col_length, data_buffer, null_buffer, - j_null_count); + arrow_array = cudf::detail::to_arrow_array( + n_type, j_col_length, data_buffer, null_buffer, j_null_count); } - auto name_and_type = arrow::field("col", arrow_array->type()); + auto name_and_type = arrow::field("col", arrow_array->type()); std::vector> fields = {name_and_type}; - std::shared_ptr schema = std::make_shared(fields); + std::shared_ptr schema = std::make_shared(fields); auto arrow_table = - arrow::Table::Make(schema, std::vector>{arrow_array}); + arrow::Table::Make(schema, std::vector>{arrow_array}); auto retCols = cudf::from_arrow(*(arrow_table))->release(); if (retCols.size() != 1) { JNI_THROW_NEW(env, "java/lang/IllegalArgumentException", "Must result in one column", 0); @@ -151,135 +158,155 @@ JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnVector_fromArrow( CATCH_STD(env, 0); } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnVector_stringConcatenation( - JNIEnv *env, jclass, jlongArray column_handles, jlong separator, jlong narep, - jboolean separate_nulls) { +JNIEXPORT jlong JNICALL +Java_ai_rapids_cudf_ColumnVector_stringConcatenation(JNIEnv* env, + jclass, + jlongArray column_handles, + jlong separator, + jlong narep, + jboolean separate_nulls) +{ JNI_NULL_CHECK(env, column_handles, "array of column handles is null", 0); JNI_NULL_CHECK(env, separator, "separator string scalar object is null", 0); JNI_NULL_CHECK(env, narep, "narep string scalar object is null", 0); try { cudf::jni::auto_set_device(env); - const auto &separator_scalar = *reinterpret_cast(separator); - const auto &narep_scalar = *reinterpret_cast(narep); - auto null_policy = separate_nulls ? cudf::strings::separator_on_nulls::YES : - cudf::strings::separator_on_nulls::NO; + const auto& separator_scalar = *reinterpret_cast(separator); + const auto& narep_scalar = *reinterpret_cast(narep); + auto null_policy = separate_nulls ? cudf::strings::separator_on_nulls::YES + : cudf::strings::separator_on_nulls::NO; cudf::jni::native_jpointerArray n_cudf_columns(env, column_handles); auto column_views = n_cudf_columns.get_dereferenced(); return release_as_jlong(cudf::strings::concatenate( - cudf::table_view(column_views), separator_scalar, narep_scalar, null_policy)); + cudf::table_view(column_views), separator_scalar, narep_scalar, null_policy)); } CATCH_STD(env, 0); } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnVector_stringConcatenationSepCol( - JNIEnv *env, jclass, jlongArray column_handles, jlong sep_handle, jlong separator_narep, - jlong col_narep, jboolean separate_nulls) { +JNIEXPORT jlong JNICALL +Java_ai_rapids_cudf_ColumnVector_stringConcatenationSepCol(JNIEnv* env, + jclass, + jlongArray column_handles, + jlong sep_handle, + jlong separator_narep, + jlong col_narep, + jboolean separate_nulls) +{ JNI_NULL_CHECK(env, column_handles, "array of column handles is null", 0); JNI_NULL_CHECK(env, sep_handle, "separator column handle is null", 0); JNI_NULL_CHECK(env, separator_narep, "separator narep string scalar object is null", 0); JNI_NULL_CHECK(env, col_narep, "column narep string scalar object is null", 0); try { cudf::jni::auto_set_device(env); - const auto &separator_narep_scalar = *reinterpret_cast(separator_narep); - const auto &col_narep_scalar = *reinterpret_cast(col_narep); - auto null_policy = separate_nulls ? cudf::strings::separator_on_nulls::YES : - cudf::strings::separator_on_nulls::NO; + const auto& separator_narep_scalar = *reinterpret_cast(separator_narep); + const auto& col_narep_scalar = *reinterpret_cast(col_narep); + auto null_policy = separate_nulls ? cudf::strings::separator_on_nulls::YES + : cudf::strings::separator_on_nulls::NO; cudf::jni::native_jpointerArray n_cudf_columns(env, column_handles); - auto column_views = n_cudf_columns.get_dereferenced(); - cudf::column_view *column = reinterpret_cast(sep_handle); + auto column_views = n_cudf_columns.get_dereferenced(); + cudf::column_view* column = reinterpret_cast(sep_handle); cudf::strings_column_view strings_column(*column); return release_as_jlong(cudf::strings::concatenate(cudf::table_view(column_views), - strings_column, separator_narep_scalar, - col_narep_scalar, null_policy)); + strings_column, + separator_narep_scalar, + col_narep_scalar, + null_policy)); } CATCH_STD(env, 0); } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnVector_concatListByRow(JNIEnv *env, jclass, +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnVector_concatListByRow(JNIEnv* env, + jclass, jlongArray column_handles, - jboolean ignore_null) { + jboolean ignore_null) +{ JNI_NULL_CHECK(env, column_handles, "array of column handles is null", 0); try { cudf::jni::auto_set_device(env); - auto null_policy = ignore_null ? cudf::lists::concatenate_null_policy::IGNORE : - cudf::lists::concatenate_null_policy::NULLIFY_OUTPUT_ROW; + auto null_policy = ignore_null ? cudf::lists::concatenate_null_policy::IGNORE + : cudf::lists::concatenate_null_policy::NULLIFY_OUTPUT_ROW; cudf::jni::native_jpointerArray n_cudf_columns(env, column_handles); auto column_views = n_cudf_columns.get_dereferenced(); return release_as_jlong( - cudf::lists::concatenate_rows(cudf::table_view(column_views), null_policy)); + cudf::lists::concatenate_rows(cudf::table_view(column_views), null_policy)); } CATCH_STD(env, 0); } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnVector_makeList(JNIEnv *env, jobject j_object, - jlongArray handles, jlong j_type, - jint scale, jlong row_count) { +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnVector_makeList( + JNIEnv* env, jobject j_object, jlongArray handles, jlong j_type, jint scale, jlong row_count) +{ using ScalarType = cudf::scalar_type_t; JNI_NULL_CHECK(env, handles, "native view handles are null", 0) try { cudf::jni::auto_set_device(env); - auto children = cudf::jni::native_jpointerArray(env, handles); + auto children = cudf::jni::native_jpointerArray(env, handles); auto children_vector = children.get_dereferenced(); - auto zero = cudf::make_numeric_scalar(cudf::data_type(cudf::type_id::INT32)); + auto zero = cudf::make_numeric_scalar(cudf::data_type(cudf::type_id::INT32)); zero->set_valid_async(true); - static_cast(zero.get())->set_value(0); + static_cast(zero.get())->set_value(0); if (children.size() == 0) { // special case because cudf::interleave_columns does not support no columns - auto offsets = cudf::make_column_from_scalar(*zero, row_count + 1); + auto offsets = cudf::make_column_from_scalar(*zero, row_count + 1); cudf::data_type n_data_type = cudf::jni::make_data_type(j_type, scale); - auto empty_col = cudf::make_empty_column(n_data_type); + auto empty_col = cudf::make_empty_column(n_data_type); return release_as_jlong(cudf::make_lists_column( - row_count, std::move(offsets), std::move(empty_col), 0, rmm::device_buffer())); + row_count, std::move(offsets), std::move(empty_col), 0, rmm::device_buffer())); } else { auto count = cudf::make_numeric_scalar(cudf::data_type(cudf::type_id::INT32)); count->set_valid_async(true); - static_cast(count.get())->set_value(children.size()); + static_cast(count.get())->set_value(children.size()); std::unique_ptr offsets = cudf::sequence(row_count + 1, *zero, *count); auto data_col = cudf::interleave_columns(cudf::table_view(children_vector)); return release_as_jlong(cudf::make_lists_column( - row_count, std::move(offsets), std::move(data_col), 0, rmm::device_buffer())); + row_count, std::move(offsets), std::move(data_col), 0, rmm::device_buffer())); } } CATCH_STD(env, 0); } JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnVector_makeListFromOffsets( - JNIEnv *env, jobject j_object, jlong child_handle, jlong offsets_handle, jlong row_count) { + JNIEnv* env, jobject j_object, jlong child_handle, jlong offsets_handle, jlong row_count) +{ JNI_NULL_CHECK(env, child_handle, "child_handle is null", 0) JNI_NULL_CHECK(env, offsets_handle, "offsets_handle is null", 0) try { cudf::jni::auto_set_device(env); - auto const child_cv = reinterpret_cast(child_handle); - auto const offsets_cv = reinterpret_cast(offsets_handle); + auto const child_cv = reinterpret_cast(child_handle); + auto const offsets_cv = reinterpret_cast(offsets_handle); CUDF_EXPECTS(offsets_cv->type().id() == cudf::type_id::INT32, "Input offsets does not have type INT32."); - return release_as_jlong(cudf::make_lists_column( - static_cast(row_count), std::make_unique(*offsets_cv), - std::make_unique(*child_cv), 0, {})); + return release_as_jlong(cudf::make_lists_column(static_cast(row_count), + std::make_unique(*offsets_cv), + std::make_unique(*child_cv), + 0, + {})); } CATCH_STD(env, 0); } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnVector_fromScalar(JNIEnv *env, jclass, +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnVector_fromScalar(JNIEnv* env, + jclass, jlong j_scalar, - jint row_count) { + jint row_count) +{ JNI_NULL_CHECK(env, j_scalar, "scalar is null", 0); try { cudf::jni::auto_set_device(env); - auto scalar_val = reinterpret_cast(j_scalar); + auto scalar_val = reinterpret_cast(j_scalar); if (scalar_val->type().id() == cudf::type_id::STRUCT && row_count == 0) { // Specialize the creation of empty struct column, since libcudf doesn't support it. - auto struct_scalar = reinterpret_cast(j_scalar); - auto children = cudf::empty_like(struct_scalar->view())->release(); - auto mask_buffer = cudf::create_null_mask(0, cudf::mask_state::UNALLOCATED); + auto struct_scalar = reinterpret_cast(j_scalar); + auto children = cudf::empty_like(struct_scalar->view())->release(); + auto mask_buffer = cudf::create_null_mask(0, cudf::mask_state::UNALLOCATED); return release_as_jlong( - cudf::make_structs_column(0, std::move(children), 0, std::move(mask_buffer))); + cudf::make_structs_column(0, std::move(children), 0, std::move(mask_buffer))); } else { return release_as_jlong(cudf::make_column_from_scalar(*scalar_val, row_count)); } @@ -287,31 +314,36 @@ JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnVector_fromScalar(JNIEnv *env, CATCH_STD(env, 0); } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnVector_concatenate(JNIEnv *env, jclass clazz, - jlongArray column_handles) { +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnVector_concatenate(JNIEnv* env, + jclass clazz, + jlongArray column_handles) +{ JNI_NULL_CHECK(env, column_handles, "input columns are null", 0); using cudf::column; using cudf::column_view; try { cudf::jni::auto_set_device(env); auto columns = - cudf::jni::native_jpointerArray{env, column_handles}.get_dereferenced(); + cudf::jni::native_jpointerArray{env, column_handles}.get_dereferenced(); auto const is_lists_column = columns[0].type().id() == cudf::type_id::LIST; return release_as_jlong( - is_lists_column ? cudf::lists::detail::concatenate(columns, cudf::get_default_stream(), - rmm::mr::get_current_device_resource()) : - cudf::concatenate(columns)); + is_lists_column + ? cudf::lists::detail::concatenate( + columns, cudf::get_default_stream(), rmm::mr::get_current_device_resource()) + : cudf::concatenate(columns)); } CATCH_STD(env, 0); } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnVector_md5(JNIEnv *env, jobject j_object, - jlongArray column_handles) { +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnVector_md5(JNIEnv* env, + jobject j_object, + jlongArray column_handles) +{ JNI_NULL_CHECK(env, column_handles, "array of column handles is null", 0); try { auto column_views = - cudf::jni::native_jpointerArray{env, column_handles}.get_dereferenced(); + cudf::jni::native_jpointerArray{env, column_handles}.get_dereferenced(); return release_as_jlong(cudf::hashing::md5(cudf::table_view{column_views})); } CATCH_STD(env, 0); @@ -323,46 +355,50 @@ JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnVector_md5(JNIEnv *env, jobjec // only be called from the CudfColumn child class. //////// -JNIEXPORT void JNICALL Java_ai_rapids_cudf_ColumnVector_deleteCudfColumn(JNIEnv *env, +JNIEXPORT void JNICALL Java_ai_rapids_cudf_ColumnVector_deleteCudfColumn(JNIEnv* env, jobject j_object, - jlong handle) { + jlong handle) +{ JNI_NULL_CHECK(env, handle, "column handle is null", ); try { cudf::jni::auto_set_device(env); - delete reinterpret_cast(handle); + delete reinterpret_cast(handle); } CATCH_STD(env, ) } -JNIEXPORT void JNICALL Java_ai_rapids_cudf_ColumnVector_setNativeNullCountColumn(JNIEnv *env, +JNIEXPORT void JNICALL Java_ai_rapids_cudf_ColumnVector_setNativeNullCountColumn(JNIEnv* env, jobject j_object, jlong handle, - jint null_count) { + jint null_count) +{ JNI_NULL_CHECK(env, handle, "native handle is null", ); try { cudf::jni::auto_set_device(env); - cudf::column *column = reinterpret_cast(handle); + cudf::column* column = reinterpret_cast(handle); column->set_null_count(null_count); } CATCH_STD(env, ); } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnVector_getNativeColumnView(JNIEnv *env, +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnVector_getNativeColumnView(JNIEnv* env, jobject j_object, - jlong handle) { + jlong handle) +{ JNI_NULL_CHECK(env, handle, "native handle is null", 0); try { cudf::jni::auto_set_device(env); - cudf::column *column = reinterpret_cast(handle); + cudf::column* column = reinterpret_cast(handle); return ptr_as_jlong(new cudf::column_view{*column}); } CATCH_STD(env, 0); } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnVector_makeEmptyCudfColumn(JNIEnv *env, jclass, +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnVector_makeEmptyCudfColumn(JNIEnv* env, + jclass, jint j_type, - jint scale) { - + jint scale) +{ try { cudf::jni::auto_set_device(env); cudf::data_type n_data_type = cudf::jni::make_data_type(j_type, scale); @@ -371,15 +407,16 @@ JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnVector_makeEmptyCudfColumn(JNI CATCH_STD(env, 0); } -JNIEXPORT jint JNICALL Java_ai_rapids_cudf_ColumnVector_getNativeNullCountColumn(JNIEnv *env, +JNIEXPORT jint JNICALL Java_ai_rapids_cudf_ColumnVector_getNativeNullCountColumn(JNIEnv* env, jobject j_object, - jlong handle) { + jlong handle) +{ JNI_NULL_CHECK(env, handle, "native handle is null", 0); try { cudf::jni::auto_set_device(env); - cudf::column *column = reinterpret_cast(handle); + cudf::column* column = reinterpret_cast(handle); return static_cast(column->null_count()); } CATCH_STD(env, 0); } -} // extern "C" +} // extern "C" diff --git a/java/src/main/native/src/ColumnViewJni.cpp b/java/src/main/native/src/ColumnViewJni.cpp index dd3859a4160..086d4672788 100644 --- a/java/src/main/native/src/ColumnViewJni.cpp +++ b/java/src/main/native/src/ColumnViewJni.cpp @@ -15,9 +15,11 @@ */ #include "ColumnViewJni.hpp" -#include -#include +#include "cudf_jni_apis.hpp" +#include "dtype_utils.hpp" +#include "jni_utils.hpp" +#include "maps_column_view.hpp" #include #include @@ -81,17 +83,17 @@ #include #include -#include "cudf_jni_apis.hpp" -#include "dtype_utils.hpp" -#include "jni_utils.hpp" -#include "maps_column_view.hpp" +#include + +#include using cudf::jni::ptr_as_jlong; using cudf::jni::release_as_jlong; namespace { -std::size_t pad_size(std::size_t size, bool const should_pad_for_cpu) { +std::size_t pad_size(std::size_t size, bool const should_pad_for_cpu) +{ if (should_pad_for_cpu) { constexpr std::size_t ALIGN = sizeof(std::max_align_t); return (size + (ALIGN - 1)) & ~(ALIGN - 1); @@ -100,9 +102,10 @@ std::size_t pad_size(std::size_t size, bool const should_pad_for_cpu) { } } -std::size_t calc_device_memory_size(cudf::column_view const &view, bool const pad_for_cpu) { +std::size_t calc_device_memory_size(cudf::column_view const& view, bool const pad_for_cpu) +{ std::size_t total = 0; - auto row_count = view.size(); + auto row_count = view.size(); if (view.nullable()) { total += pad_size(cudf::bitmask_allocation_size_bytes(row_count), pad_for_cpu); @@ -116,249 +119,274 @@ std::size_t calc_device_memory_size(cudf::column_view const &view, bool const pa total += pad_size(scv.chars_size(cudf::get_default_stream()), pad_for_cpu); } - return std::accumulate(view.child_begin(), view.child_end(), total, - [pad_for_cpu](std::size_t t, cudf::column_view const &v) { + return std::accumulate(view.child_begin(), + view.child_end(), + total, + [pad_for_cpu](std::size_t t, cudf::column_view const& v) { return t + calc_device_memory_size(v, pad_for_cpu); }); } -} // anonymous namespace +} // anonymous namespace extern "C" { -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_upperStrings(JNIEnv *env, jobject j_object, - jlong handle) { +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_upperStrings(JNIEnv* env, + jobject j_object, + jlong handle) +{ JNI_NULL_CHECK(env, handle, "column is null", 0); try { cudf::jni::auto_set_device(env); - cudf::column_view *column = reinterpret_cast(handle); + cudf::column_view* column = reinterpret_cast(handle); cudf::strings_column_view strings_column(*column); return release_as_jlong(cudf::strings::to_upper(strings_column)); } CATCH_STD(env, 0); } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_lowerStrings(JNIEnv *env, jobject j_object, - jlong handle) { +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_lowerStrings(JNIEnv* env, + jobject j_object, + jlong handle) +{ JNI_NULL_CHECK(env, handle, "column is null", 0); try { cudf::jni::auto_set_device(env); - cudf::column_view *column = reinterpret_cast(handle); + cudf::column_view* column = reinterpret_cast(handle); cudf::strings_column_view strings_column(*column); return release_as_jlong(cudf::strings::to_lower(strings_column)); } CATCH_STD(env, 0); } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_replaceNullsScalar(JNIEnv *env, jclass, +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_replaceNullsScalar(JNIEnv* env, + jclass, jlong j_col, - jlong j_scalar) { + jlong j_scalar) +{ JNI_NULL_CHECK(env, j_col, "column is null", 0); JNI_NULL_CHECK(env, j_scalar, "scalar is null", 0); try { cudf::jni::auto_set_device(env); - cudf::column_view col = *reinterpret_cast(j_col); - auto val = reinterpret_cast(j_scalar); + cudf::column_view col = *reinterpret_cast(j_col); + auto val = reinterpret_cast(j_scalar); return release_as_jlong(cudf::replace_nulls(col, *val)); } CATCH_STD(env, 0); } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_replaceNullsColumn(JNIEnv *env, jclass, +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_replaceNullsColumn(JNIEnv* env, + jclass, jlong j_col, - jlong j_replace_col) { + jlong j_replace_col) +{ JNI_NULL_CHECK(env, j_col, "column is null", 0); JNI_NULL_CHECK(env, j_replace_col, "replacement column is null", 0); try { cudf::jni::auto_set_device(env); - auto col = reinterpret_cast(j_col); - auto replacements = reinterpret_cast(j_replace_col); + auto col = reinterpret_cast(j_col); + auto replacements = reinterpret_cast(j_replace_col); return release_as_jlong(cudf::replace_nulls(*col, *replacements)); } CATCH_STD(env, 0); } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_replaceNullsPolicy(JNIEnv *env, jclass, +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_replaceNullsPolicy(JNIEnv* env, + jclass, jlong j_col, - jboolean is_preceding) { + jboolean is_preceding) +{ JNI_NULL_CHECK(env, j_col, "column is null", 0); try { cudf::jni::auto_set_device(env); - cudf::column_view col = *reinterpret_cast(j_col); + cudf::column_view col = *reinterpret_cast(j_col); return release_as_jlong(cudf::replace_nulls( - col, is_preceding ? cudf::replace_policy::PRECEDING : cudf::replace_policy::FOLLOWING)); + col, is_preceding ? cudf::replace_policy::PRECEDING : cudf::replace_policy::FOLLOWING)); } CATCH_STD(env, 0); } -JNIEXPORT jint JNICALL Java_ai_rapids_cudf_ColumnView_distinctCount(JNIEnv *env, jclass, +JNIEXPORT jint JNICALL Java_ai_rapids_cudf_ColumnView_distinctCount(JNIEnv* env, + jclass, jlong j_col, - jboolean nulls_included) { + jboolean nulls_included) +{ JNI_NULL_CHECK(env, j_col, "column is null", 0); try { cudf::jni::auto_set_device(env); - cudf::column_view col = *reinterpret_cast(j_col); + cudf::column_view col = *reinterpret_cast(j_col); return cudf::distinct_count( - col, nulls_included ? cudf::null_policy::INCLUDE : cudf::null_policy::EXCLUDE, - cudf::nan_policy::NAN_IS_VALID); + col, + nulls_included ? cudf::null_policy::INCLUDE : cudf::null_policy::EXCLUDE, + cudf::nan_policy::NAN_IS_VALID); } CATCH_STD(env, 0); } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_ifElseVV(JNIEnv *env, jclass, - jlong j_pred_vec, jlong j_true_vec, - jlong j_false_vec) { +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_ifElseVV( + JNIEnv* env, jclass, jlong j_pred_vec, jlong j_true_vec, jlong j_false_vec) +{ JNI_NULL_CHECK(env, j_pred_vec, "predicate column is null", 0); JNI_NULL_CHECK(env, j_true_vec, "true column is null", 0); JNI_NULL_CHECK(env, j_false_vec, "false column is null", 0); try { cudf::jni::auto_set_device(env); - auto pred_vec = reinterpret_cast(j_pred_vec); - auto true_vec = reinterpret_cast(j_true_vec); - auto false_vec = reinterpret_cast(j_false_vec); + auto pred_vec = reinterpret_cast(j_pred_vec); + auto true_vec = reinterpret_cast(j_true_vec); + auto false_vec = reinterpret_cast(j_false_vec); return release_as_jlong(cudf::copy_if_else(*true_vec, *false_vec, *pred_vec)); } CATCH_STD(env, 0); } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_ifElseVS(JNIEnv *env, jclass, - jlong j_pred_vec, jlong j_true_vec, - jlong j_false_scalar) { +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_ifElseVS( + JNIEnv* env, jclass, jlong j_pred_vec, jlong j_true_vec, jlong j_false_scalar) +{ JNI_NULL_CHECK(env, j_pred_vec, "predicate column is null", 0); JNI_NULL_CHECK(env, j_true_vec, "true column is null", 0); JNI_NULL_CHECK(env, j_false_scalar, "false scalar is null", 0); try { cudf::jni::auto_set_device(env); - auto pred_vec = reinterpret_cast(j_pred_vec); - auto true_vec = reinterpret_cast(j_true_vec); - auto false_scalar = reinterpret_cast(j_false_scalar); + auto pred_vec = reinterpret_cast(j_pred_vec); + auto true_vec = reinterpret_cast(j_true_vec); + auto false_scalar = reinterpret_cast(j_false_scalar); return release_as_jlong(cudf::copy_if_else(*true_vec, *false_scalar, *pred_vec)); } CATCH_STD(env, 0); } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_ifElseSV(JNIEnv *env, jclass, - jlong j_pred_vec, - jlong j_true_scalar, - jlong j_false_vec) { +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_ifElseSV( + JNIEnv* env, jclass, jlong j_pred_vec, jlong j_true_scalar, jlong j_false_vec) +{ JNI_NULL_CHECK(env, j_pred_vec, "predicate column is null", 0); JNI_NULL_CHECK(env, j_true_scalar, "true scalar is null", 0); JNI_NULL_CHECK(env, j_false_vec, "false column is null", 0); try { cudf::jni::auto_set_device(env); - auto pred_vec = reinterpret_cast(j_pred_vec); - auto true_scalar = reinterpret_cast(j_true_scalar); - auto false_vec = reinterpret_cast(j_false_vec); + auto pred_vec = reinterpret_cast(j_pred_vec); + auto true_scalar = reinterpret_cast(j_true_scalar); + auto false_vec = reinterpret_cast(j_false_vec); return release_as_jlong(cudf::copy_if_else(*true_scalar, *false_vec, *pred_vec)); } CATCH_STD(env, 0); } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_ifElseSS(JNIEnv *env, jclass, - jlong j_pred_vec, - jlong j_true_scalar, - jlong j_false_scalar) { +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_ifElseSS( + JNIEnv* env, jclass, jlong j_pred_vec, jlong j_true_scalar, jlong j_false_scalar) +{ JNI_NULL_CHECK(env, j_pred_vec, "predicate column is null", 0); JNI_NULL_CHECK(env, j_true_scalar, "true scalar is null", 0); JNI_NULL_CHECK(env, j_false_scalar, "false scalar is null", 0); try { cudf::jni::auto_set_device(env); - auto pred_vec = reinterpret_cast(j_pred_vec); - auto true_scalar = reinterpret_cast(j_true_scalar); - auto false_scalar = reinterpret_cast(j_false_scalar); + auto pred_vec = reinterpret_cast(j_pred_vec); + auto true_scalar = reinterpret_cast(j_true_scalar); + auto false_scalar = reinterpret_cast(j_false_scalar); return release_as_jlong(cudf::copy_if_else(*true_scalar, *false_scalar, *pred_vec)); } CATCH_STD(env, 0); } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_getElement(JNIEnv *env, jclass, jlong from, - jint index) { +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_getElement(JNIEnv* env, + jclass, + jlong from, + jint index) +{ JNI_NULL_CHECK(env, from, "from column is null", 0); try { cudf::jni::auto_set_device(env); - auto from_vec = reinterpret_cast(from); + auto from_vec = reinterpret_cast(from); return release_as_jlong(cudf::get_element(*from_vec, index)); } CATCH_STD(env, 0); } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_reduce(JNIEnv *env, jclass, jlong j_col_view, - jlong j_agg, jint j_dtype, - jint scale) { +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_reduce( + JNIEnv* env, jclass, jlong j_col_view, jlong j_agg, jint j_dtype, jint scale) +{ JNI_NULL_CHECK(env, j_col_view, "column view is null", 0); JNI_NULL_CHECK(env, j_agg, "aggregation is null", 0); try { cudf::jni::auto_set_device(env); - auto col = reinterpret_cast(j_col_view); - auto agg = reinterpret_cast(j_agg); + auto col = reinterpret_cast(j_col_view); + auto agg = reinterpret_cast(j_agg); cudf::data_type out_dtype = cudf::jni::make_data_type(j_dtype, scale); return release_as_jlong( - cudf::reduce(*col, *dynamic_cast(agg), out_dtype)); + cudf::reduce(*col, *dynamic_cast(agg), out_dtype)); } CATCH_STD(env, 0); } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_segmentedReduce( - JNIEnv *env, jclass, jlong j_data_view, jlong j_offsets_view, jlong j_agg, - jboolean include_nulls, jint j_dtype, jint scale) { +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_segmentedReduce(JNIEnv* env, + jclass, + jlong j_data_view, + jlong j_offsets_view, + jlong j_agg, + jboolean include_nulls, + jint j_dtype, + jint scale) +{ JNI_NULL_CHECK(env, j_data_view, "data column view is null", 0); JNI_NULL_CHECK(env, j_offsets_view, "offsets column view is null", 0); JNI_NULL_CHECK(env, j_agg, "aggregation is null", 0); try { cudf::jni::auto_set_device(env); - auto data = reinterpret_cast(j_data_view); - auto offsets = reinterpret_cast(j_offsets_view); - auto agg = reinterpret_cast(j_agg); - auto s_agg = dynamic_cast(agg); + auto data = reinterpret_cast(j_data_view); + auto offsets = reinterpret_cast(j_offsets_view); + auto agg = reinterpret_cast(j_agg); + auto s_agg = dynamic_cast(agg); JNI_ARG_CHECK(env, s_agg != nullptr, "agg is not a cudf::segmented_reduce_aggregation", 0) auto null_policy = include_nulls ? cudf::null_policy::INCLUDE : cudf::null_policy::EXCLUDE; cudf::data_type out_dtype = cudf::jni::make_data_type(j_dtype, scale); return release_as_jlong( - cudf::segmented_reduce(*data, *offsets, *s_agg, out_dtype, null_policy)); + cudf::segmented_reduce(*data, *offsets, *s_agg, out_dtype, null_policy)); } CATCH_STD(env, 0); } JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_segmentedGather( - JNIEnv *env, jclass, jlong source_column, jlong gather_map_list, jboolean nullify_out_bounds) { + JNIEnv* env, jclass, jlong source_column, jlong gather_map_list, jboolean nullify_out_bounds) +{ JNI_NULL_CHECK(env, source_column, "source column view is null", 0); JNI_NULL_CHECK(env, gather_map_list, "gather map is null", 0); try { cudf::jni::auto_set_device(env); - auto const &src_col = - cudf::lists_column_view(*reinterpret_cast(source_column)); - auto const &gather_map = - cudf::lists_column_view(*reinterpret_cast(gather_map_list)); - auto out_bounds_policy = nullify_out_bounds ? cudf::out_of_bounds_policy::NULLIFY : - cudf::out_of_bounds_policy::DONT_CHECK; + auto const& src_col = + cudf::lists_column_view(*reinterpret_cast(source_column)); + auto const& gather_map = + cudf::lists_column_view(*reinterpret_cast(gather_map_list)); + auto out_bounds_policy = nullify_out_bounds ? cudf::out_of_bounds_policy::NULLIFY + : cudf::out_of_bounds_policy::DONT_CHECK; return release_as_jlong(cudf::lists::segmented_gather(src_col, gather_map, out_bounds_policy)); } CATCH_STD(env, 0); } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_scan(JNIEnv *env, jclass, jlong j_col_view, - jlong j_agg, jboolean is_inclusive, - jboolean include_nulls) { +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_scan( + JNIEnv* env, jclass, jlong j_col_view, jlong j_agg, jboolean is_inclusive, jboolean include_nulls) +{ JNI_NULL_CHECK(env, j_col_view, "column view is null", 0); JNI_NULL_CHECK(env, j_agg, "aggregation is null", 0); try { cudf::jni::auto_set_device(env); - auto col = reinterpret_cast(j_col_view); - auto agg = reinterpret_cast(j_agg); - auto scan_type = is_inclusive ? cudf::scan_type::INCLUSIVE : cudf::scan_type::EXCLUSIVE; + auto col = reinterpret_cast(j_col_view); + auto agg = reinterpret_cast(j_agg); + auto scan_type = is_inclusive ? cudf::scan_type::INCLUSIVE : cudf::scan_type::EXCLUSIVE; auto null_policy = include_nulls ? cudf::null_policy::INCLUDE : cudf::null_policy::EXCLUDE; return release_as_jlong( - cudf::scan(*col, *dynamic_cast(agg), scan_type, null_policy)); + cudf::scan(*col, *dynamic_cast(agg), scan_type, null_policy)); } CATCH_STD(env, 0); } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_approxPercentile(JNIEnv *env, jclass clazz, +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_approxPercentile(JNIEnv* env, + jclass clazz, jlong input_column, - jlong percentiles_column) { + jlong percentiles_column) +{ JNI_NULL_CHECK(env, input_column, "input_column native handle is null", 0); JNI_NULL_CHECK(env, percentiles_column, "percentiles_column native handle is null", 0); try { @@ -366,63 +394,70 @@ JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_approxPercentile(JNIEnv * using tdigest_column_view = cudf::tdigest::tdigest_column_view; jni::auto_set_device(env); auto const tdigest_view = - tdigest_column_view{structs_column_view{*reinterpret_cast(input_column)}}; - auto const p_percentiles = reinterpret_cast(percentiles_column); + tdigest_column_view{structs_column_view{*reinterpret_cast(input_column)}}; + auto const p_percentiles = reinterpret_cast(percentiles_column); return release_as_jlong(percentile_approx(tdigest_view, *p_percentiles)); } CATCH_STD(env, 0); } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_quantile(JNIEnv *env, jclass clazz, - jlong input_column, - jint quantile_method, - jdoubleArray jquantiles) { +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_quantile( + JNIEnv* env, jclass clazz, jlong input_column, jint quantile_method, jdoubleArray jquantiles) +{ JNI_NULL_CHECK(env, input_column, "native handle is null", 0); try { cudf::jni::auto_set_device(env); cudf::jni::native_jdoubleArray native_quantiles(env, jquantiles); std::vector quantiles(native_quantiles.data(), native_quantiles.data() + native_quantiles.size()); - cudf::column_view *n_input_column = reinterpret_cast(input_column); + cudf::column_view* n_input_column = reinterpret_cast(input_column); cudf::interpolation n_quantile_method = static_cast(quantile_method); return release_as_jlong(cudf::quantile(*n_input_column, quantiles, n_quantile_method)); } CATCH_STD(env, 0); } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_rollingWindow( - JNIEnv *env, jclass clazz, jlong input_col, jlong default_output_col, jint min_periods, - jlong agg_ptr, jint preceding, jint following, jlong preceding_col, jlong following_col) { - +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_rollingWindow(JNIEnv* env, + jclass clazz, + jlong input_col, + jlong default_output_col, + jint min_periods, + jlong agg_ptr, + jint preceding, + jint following, + jlong preceding_col, + jlong following_col) +{ JNI_NULL_CHECK(env, input_col, "native handle is null", 0); JNI_NULL_CHECK(env, agg_ptr, "aggregation handle is null", 0); try { cudf::jni::auto_set_device(env); - cudf::column_view *n_input_col = reinterpret_cast(input_col); - cudf::column_view *n_default_output_col = - reinterpret_cast(default_output_col); - cudf::column_view *n_preceding_col = reinterpret_cast(preceding_col); - cudf::column_view *n_following_col = reinterpret_cast(following_col); - cudf::rolling_aggregation *agg = - dynamic_cast(reinterpret_cast(agg_ptr)); + cudf::column_view* n_input_col = reinterpret_cast(input_col); + cudf::column_view* n_default_output_col = + reinterpret_cast(default_output_col); + cudf::column_view* n_preceding_col = reinterpret_cast(preceding_col); + cudf::column_view* n_following_col = reinterpret_cast(following_col); + cudf::rolling_aggregation* agg = + dynamic_cast(reinterpret_cast(agg_ptr)); JNI_ARG_CHECK(env, agg != nullptr, "aggregation is not an instance of rolling_aggregation", 0); std::unique_ptr ret; if (n_default_output_col != nullptr) { if (n_preceding_col != nullptr && n_following_col != nullptr) { - CUDF_FAIL("A default output column is not currently supported with variable length " - "preceding and following"); + CUDF_FAIL( + "A default output column is not currently supported with variable length " + "preceding and following"); // ret = cudf::rolling_window(*n_input_col, *n_default_output_col, // *n_preceding_col, *n_following_col, min_periods, agg); } else { - ret = cudf::rolling_window(*n_input_col, *n_default_output_col, preceding, following, - min_periods, *agg); + ret = cudf::rolling_window( + *n_input_col, *n_default_output_col, preceding, following, min_periods, *agg); } } else { if (n_preceding_col != nullptr && n_following_col != nullptr) { - ret = cudf::rolling_window(*n_input_col, *n_preceding_col, *n_following_col, min_periods, - *agg); + ret = + cudf::rolling_window(*n_input_col, *n_preceding_col, *n_following_col, min_periods, *agg); } else { ret = cudf::rolling_window(*n_input_col, preceding, following, min_periods, *agg); } @@ -432,301 +467,336 @@ JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_rollingWindow( CATCH_STD(env, 0); } -JNIEXPORT jlongArray JNICALL Java_ai_rapids_cudf_ColumnView_slice(JNIEnv *env, jclass clazz, +JNIEXPORT jlongArray JNICALL Java_ai_rapids_cudf_ColumnView_slice(JNIEnv* env, + jclass clazz, jlong input_column, - jintArray slice_indices) { + jintArray slice_indices) +{ JNI_NULL_CHECK(env, input_column, "native handle is null", 0); JNI_NULL_CHECK(env, slice_indices, "slice indices are null", 0); try { cudf::jni::auto_set_device(env); - cudf::column_view *n_column = reinterpret_cast(input_column); + cudf::column_view* n_column = reinterpret_cast(input_column); cudf::jni::native_jintArray n_slice_indices(env, slice_indices); std::vector indices(n_slice_indices.begin(), n_slice_indices.end()); std::vector result = cudf::slice(*n_column, indices); cudf::jni::native_jlongArray n_result(env, result.size()); - std::transform(result.begin(), result.end(), n_result.begin(), - [](cudf::column_view const &result_col) { - return ptr_as_jlong(new cudf::column{result_col}); - }); + std::transform( + result.begin(), result.end(), n_result.begin(), [](cudf::column_view const& result_col) { + return ptr_as_jlong(new cudf::column{result_col}); + }); return n_result.get_jArray(); } CATCH_STD(env, NULL); } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_extractListElement(JNIEnv *env, jclass, +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_extractListElement(JNIEnv* env, + jclass, jlong column_view, - jint index) { + jint index) +{ JNI_NULL_CHECK(env, column_view, "column is null", 0); try { cudf::jni::auto_set_device(env); - cudf::column_view *cv = reinterpret_cast(column_view); + cudf::column_view* cv = reinterpret_cast(column_view); cudf::lists_column_view lcv(*cv); return release_as_jlong(cudf::lists::extract_list_element(lcv, index)); } CATCH_STD(env, 0); } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_extractListElementV(JNIEnv *env, jclass, +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_extractListElementV(JNIEnv* env, + jclass, jlong column_view, - jlong indices_view) { + jlong indices_view) +{ JNI_NULL_CHECK(env, column_view, "column is null", 0); JNI_NULL_CHECK(env, indices_view, "indices is null", 0); try { cudf::jni::auto_set_device(env); - cudf::column_view *indices = reinterpret_cast(indices_view); - cudf::column_view *cv = reinterpret_cast(column_view); + cudf::column_view* indices = reinterpret_cast(indices_view); + cudf::column_view* cv = reinterpret_cast(column_view); cudf::lists_column_view lcv(*cv); return release_as_jlong(cudf::lists::extract_list_element(lcv, *indices)); } CATCH_STD(env, 0); } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_dropListDuplicates(JNIEnv *env, jclass, - jlong column_view) { +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_dropListDuplicates(JNIEnv* env, + jclass, + jlong column_view) +{ JNI_NULL_CHECK(env, column_view, "column is null", 0); try { cudf::jni::auto_set_device(env); - auto const input_cv = reinterpret_cast(column_view); + auto const input_cv = reinterpret_cast(column_view); return release_as_jlong(cudf::lists::distinct(cudf::lists_column_view{*input_cv})); } CATCH_STD(env, 0); } JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_dropListDuplicatesWithKeysValues( - JNIEnv *env, jclass, jlong keys_vals_handle) { + JNIEnv* env, jclass, jlong keys_vals_handle) +{ JNI_NULL_CHECK(env, keys_vals_handle, "keys_vals_handle is null", 0); try { cudf::jni::auto_set_device(env); - auto const input_cv = reinterpret_cast(keys_vals_handle); - JNI_ARG_CHECK(env, input_cv->type().id() == cudf::type_id::LIST, - "Input column is not a lists column.", 0); + auto const input_cv = reinterpret_cast(keys_vals_handle); + JNI_ARG_CHECK( + env, input_cv->type().id() == cudf::type_id::LIST, "Input column is not a lists column.", 0); auto const lists_keys_vals = cudf::lists_column_view(*input_cv); - auto const keys_vals = lists_keys_vals.child(); - JNI_ARG_CHECK(env, keys_vals.type().id() == cudf::type_id::STRUCT, - "Input column has child that is not a structs column.", 0); - JNI_ARG_CHECK(env, keys_vals.num_children() == 2, - "Input column has child that does not have 2 children.", 0); + auto const keys_vals = lists_keys_vals.child(); + JNI_ARG_CHECK(env, + keys_vals.type().id() == cudf::type_id::STRUCT, + "Input column has child that is not a structs column.", + 0); + JNI_ARG_CHECK(env, + keys_vals.num_children() == 2, + "Input column has child that does not have 2 children.", + 0); return release_as_jlong( - cudf::jni::lists_distinct_by_key(lists_keys_vals, cudf::get_default_stream())); + cudf::jni::lists_distinct_by_key(lists_keys_vals, cudf::get_default_stream())); } CATCH_STD(env, 0); } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_flattenLists(JNIEnv *env, jclass, +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_flattenLists(JNIEnv* env, + jclass, jlong input_handle, - jboolean ignore_null) { + jboolean ignore_null) +{ JNI_NULL_CHECK(env, input_handle, "input_handle is null", 0); try { cudf::jni::auto_set_device(env); - auto const null_policy = ignore_null ? cudf::lists::concatenate_null_policy::IGNORE : - cudf::lists::concatenate_null_policy::NULLIFY_OUTPUT_ROW; - auto const input_cv = reinterpret_cast(input_handle); + auto const null_policy = ignore_null ? cudf::lists::concatenate_null_policy::IGNORE + : cudf::lists::concatenate_null_policy::NULLIFY_OUTPUT_ROW; + auto const input_cv = reinterpret_cast(input_handle); return release_as_jlong(cudf::lists::concatenate_list_elements(*input_cv, null_policy)); } CATCH_STD(env, 0); } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_listContains(JNIEnv *env, jclass, +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_listContains(JNIEnv* env, + jclass, jlong column_view, - jlong lookup_key) { + jlong lookup_key) +{ JNI_NULL_CHECK(env, column_view, "column is null", 0); JNI_NULL_CHECK(env, lookup_key, "lookup scalar is null", 0); try { cudf::jni::auto_set_device(env); - cudf::column_view *cv = reinterpret_cast(column_view); + cudf::column_view* cv = reinterpret_cast(column_view); cudf::lists_column_view lcv(*cv); - cudf::scalar *lookup_scalar = reinterpret_cast(lookup_key); + cudf::scalar* lookup_scalar = reinterpret_cast(lookup_key); return release_as_jlong(cudf::lists::contains(lcv, *lookup_scalar)); } CATCH_STD(env, 0); } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_listContainsNulls(JNIEnv *env, jclass, - jlong column_view) { +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_listContainsNulls(JNIEnv* env, + jclass, + jlong column_view) +{ JNI_NULL_CHECK(env, column_view, "column is null", 0); try { cudf::jni::auto_set_device(env); - auto cv = reinterpret_cast(column_view); + auto cv = reinterpret_cast(column_view); auto lcv = cudf::lists_column_view{*cv}; return release_as_jlong(cudf::lists::contains_nulls(lcv)); } CATCH_STD(env, 0); } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_listContainsColumn(JNIEnv *env, jclass, +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_listContainsColumn(JNIEnv* env, + jclass, jlong column_view, - jlong lookup_key_cv) { + jlong lookup_key_cv) +{ JNI_NULL_CHECK(env, column_view, "column is null", 0); JNI_NULL_CHECK(env, lookup_key_cv, "lookup column is null", 0); try { cudf::jni::auto_set_device(env); - cudf::column_view *cv = reinterpret_cast(column_view); + cudf::column_view* cv = reinterpret_cast(column_view); cudf::lists_column_view lcv(*cv); - cudf::column_view *lookup_cv = reinterpret_cast(lookup_key_cv); + cudf::column_view* lookup_cv = reinterpret_cast(lookup_key_cv); return release_as_jlong(cudf::lists::contains(lcv, *lookup_cv)); } CATCH_STD(env, 0); } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_listIndexOfScalar(JNIEnv *env, jclass, - jlong column_view, - jlong lookup_key, - jboolean is_find_first) { +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_listIndexOfScalar( + JNIEnv* env, jclass, jlong column_view, jlong lookup_key, jboolean is_find_first) +{ JNI_NULL_CHECK(env, column_view, "column is null", 0); JNI_NULL_CHECK(env, lookup_key, "lookup scalar is null", 0); try { cudf::jni::auto_set_device(env); - auto const cv = reinterpret_cast(column_view); - auto const lcv = cudf::lists_column_view{*cv}; - auto const lookup_key_scalar = reinterpret_cast(lookup_key); - auto const find_option = is_find_first ? cudf::lists::duplicate_find_option::FIND_FIRST : - cudf::lists::duplicate_find_option::FIND_LAST; + auto const cv = reinterpret_cast(column_view); + auto const lcv = cudf::lists_column_view{*cv}; + auto const lookup_key_scalar = reinterpret_cast(lookup_key); + auto const find_option = is_find_first ? cudf::lists::duplicate_find_option::FIND_FIRST + : cudf::lists::duplicate_find_option::FIND_LAST; return release_as_jlong(cudf::lists::index_of(lcv, *lookup_key_scalar, find_option)); } CATCH_STD(env, 0); } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_listIndexOfColumn(JNIEnv *env, jclass, - jlong column_view, - jlong lookup_keys, - jboolean is_find_first) { +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_listIndexOfColumn( + JNIEnv* env, jclass, jlong column_view, jlong lookup_keys, jboolean is_find_first) +{ JNI_NULL_CHECK(env, column_view, "column is null", 0); JNI_NULL_CHECK(env, lookup_keys, "lookup key column is null", 0); try { cudf::jni::auto_set_device(env); - auto const cv = reinterpret_cast(column_view); - auto const lcv = cudf::lists_column_view{*cv}; - auto const lookup_key_column = reinterpret_cast(lookup_keys); - auto const find_option = is_find_first ? cudf::lists::duplicate_find_option::FIND_FIRST : - cudf::lists::duplicate_find_option::FIND_LAST; + auto const cv = reinterpret_cast(column_view); + auto const lcv = cudf::lists_column_view{*cv}; + auto const lookup_key_column = reinterpret_cast(lookup_keys); + auto const find_option = is_find_first ? cudf::lists::duplicate_find_option::FIND_FIRST + : cudf::lists::duplicate_find_option::FIND_LAST; return release_as_jlong(cudf::lists::index_of(lcv, *lookup_key_column, find_option)); } CATCH_STD(env, 0); } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_listSortRows(JNIEnv *env, jclass, - jlong column_view, - jboolean is_descending, - jboolean is_null_smallest) { +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_listSortRows( + JNIEnv* env, jclass, jlong column_view, jboolean is_descending, jboolean is_null_smallest) +{ JNI_NULL_CHECK(env, column_view, "column is null", 0); try { cudf::jni::auto_set_device(env); auto sort_order = is_descending ? cudf::order::DESCENDING : cudf::order::ASCENDING; auto null_order = is_null_smallest ? cudf::null_order::BEFORE : cudf::null_order::AFTER; - auto *cv = reinterpret_cast(column_view); + auto* cv = reinterpret_cast(column_view); return release_as_jlong( - cudf::lists::sort_lists(cudf::lists_column_view(*cv), sort_order, null_order)); + cudf::lists::sort_lists(cudf::lists_column_view(*cv), sort_order, null_order)); } CATCH_STD(env, 0); } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_generateListOffsets(JNIEnv *env, jclass, - jlong handle) { +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_generateListOffsets(JNIEnv* env, + jclass, + jlong handle) +{ JNI_NULL_CHECK(env, handle, "handle is null", 0) try { cudf::jni::auto_set_device(env); - auto const cv = reinterpret_cast(handle); + auto const cv = reinterpret_cast(handle); return release_as_jlong(cudf::jni::generate_list_offsets(*cv)); } CATCH_STD(env, 0); } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_listsHaveOverlap(JNIEnv *env, jclass, +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_listsHaveOverlap(JNIEnv* env, + jclass, jlong lhs_handle, - jlong rhs_handle) { + jlong rhs_handle) +{ JNI_NULL_CHECK(env, lhs_handle, "lhs_handle is null", 0) JNI_NULL_CHECK(env, rhs_handle, "rhs_handle is null", 0) try { cudf::jni::auto_set_device(env); - auto const lhs = reinterpret_cast(lhs_handle); - auto const rhs = reinterpret_cast(rhs_handle); - auto overlap_result = - cudf::lists::have_overlap(cudf::lists_column_view{*lhs}, cudf::lists_column_view{*rhs}, - cudf::null_equality::UNEQUAL, cudf::nan_equality::ALL_EQUAL); + auto const lhs = reinterpret_cast(lhs_handle); + auto const rhs = reinterpret_cast(rhs_handle); + auto overlap_result = cudf::lists::have_overlap(cudf::lists_column_view{*lhs}, + cudf::lists_column_view{*rhs}, + cudf::null_equality::UNEQUAL, + cudf::nan_equality::ALL_EQUAL); cudf::jni::post_process_list_overlap(*lhs, *rhs, overlap_result); return release_as_jlong(overlap_result); } CATCH_STD(env, 0); } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_listsIntersectDistinct(JNIEnv *env, jclass, +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_listsIntersectDistinct(JNIEnv* env, + jclass, jlong lhs_handle, - jlong rhs_handle) { + jlong rhs_handle) +{ JNI_NULL_CHECK(env, lhs_handle, "lhs_handle is null", 0) JNI_NULL_CHECK(env, rhs_handle, "rhs_handle is null", 0) try { cudf::jni::auto_set_device(env); - auto const lhs = reinterpret_cast(lhs_handle); - auto const rhs = reinterpret_cast(rhs_handle); - return release_as_jlong(cudf::lists::intersect_distinct( - cudf::lists_column_view{*lhs}, cudf::lists_column_view{*rhs}, cudf::null_equality::EQUAL, - cudf::nan_equality::ALL_EQUAL)); + auto const lhs = reinterpret_cast(lhs_handle); + auto const rhs = reinterpret_cast(rhs_handle); + return release_as_jlong(cudf::lists::intersect_distinct(cudf::lists_column_view{*lhs}, + cudf::lists_column_view{*rhs}, + cudf::null_equality::EQUAL, + cudf::nan_equality::ALL_EQUAL)); } CATCH_STD(env, 0); } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_listsUnionDistinct(JNIEnv *env, jclass, +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_listsUnionDistinct(JNIEnv* env, + jclass, jlong lhs_handle, - jlong rhs_handle) { + jlong rhs_handle) +{ JNI_NULL_CHECK(env, lhs_handle, "lhs_handle is null", 0) JNI_NULL_CHECK(env, rhs_handle, "rhs_handle is null", 0) try { cudf::jni::auto_set_device(env); - auto const lhs = reinterpret_cast(lhs_handle); - auto const rhs = reinterpret_cast(rhs_handle); - return release_as_jlong( - cudf::lists::union_distinct(cudf::lists_column_view{*lhs}, cudf::lists_column_view{*rhs}, - cudf::null_equality::EQUAL, cudf::nan_equality::ALL_EQUAL)); + auto const lhs = reinterpret_cast(lhs_handle); + auto const rhs = reinterpret_cast(rhs_handle); + return release_as_jlong(cudf::lists::union_distinct(cudf::lists_column_view{*lhs}, + cudf::lists_column_view{*rhs}, + cudf::null_equality::EQUAL, + cudf::nan_equality::ALL_EQUAL)); } CATCH_STD(env, 0); } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_listsDifferenceDistinct(JNIEnv *env, jclass, +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_listsDifferenceDistinct(JNIEnv* env, + jclass, jlong lhs_handle, - jlong rhs_handle) { + jlong rhs_handle) +{ JNI_NULL_CHECK(env, lhs_handle, "lhs_handle is null", 0) JNI_NULL_CHECK(env, rhs_handle, "rhs_handle is null", 0) try { cudf::jni::auto_set_device(env); - auto const lhs = reinterpret_cast(lhs_handle); - auto const rhs = reinterpret_cast(rhs_handle); - return release_as_jlong(cudf::lists::difference_distinct( - cudf::lists_column_view{*lhs}, cudf::lists_column_view{*rhs}, cudf::null_equality::EQUAL, - cudf::nan_equality::ALL_EQUAL)); + auto const lhs = reinterpret_cast(lhs_handle); + auto const rhs = reinterpret_cast(rhs_handle); + return release_as_jlong(cudf::lists::difference_distinct(cudf::lists_column_view{*lhs}, + cudf::lists_column_view{*rhs}, + cudf::null_equality::EQUAL, + cudf::nan_equality::ALL_EQUAL)); } CATCH_STD(env, 0); } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_reverseStringsOrLists(JNIEnv *env, jclass, - jlong input_handle) { +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_reverseStringsOrLists(JNIEnv* env, + jclass, + jlong input_handle) +{ JNI_NULL_CHECK(env, input_handle, "input_handle is null", 0) try { cudf::jni::auto_set_device(env); - auto const input = reinterpret_cast(input_handle); + auto const input = reinterpret_cast(input_handle); switch (input->type().id()) { case cudf::type_id::STRING: return release_as_jlong(cudf::strings::reverse(cudf::strings_column_view{*input})); case cudf::type_id::LIST: return release_as_jlong(cudf::lists::reverse(cudf::lists_column_view{*input})); default: - JNI_THROW_NEW(env, "java/lang/IllegalArgumentException", - "A column of type string or list is required for reverse()", 0); + JNI_THROW_NEW(env, + "java/lang/IllegalArgumentException", + "A column of type string or list is required for reverse()", + 0); } } CATCH_STD(env, 0); } -JNIEXPORT jlongArray JNICALL Java_ai_rapids_cudf_ColumnView_stringSplit(JNIEnv *env, jclass, - jlong input_handle, - jstring delimiter_obj, - jint limit) { +JNIEXPORT jlongArray JNICALL Java_ai_rapids_cudf_ColumnView_stringSplit( + JNIEnv* env, jclass, jlong input_handle, jstring delimiter_obj, jint limit) +{ JNI_NULL_CHECK(env, input_handle, "input_handle is null", 0); if (limit == 0 || limit == 1) { @@ -734,26 +804,31 @@ JNIEXPORT jlongArray JNICALL Java_ai_rapids_cudf_ColumnView_stringSplit(JNIEnv * // This is because cudf operates on a different parameter (`max_split`) which is converted from // limit. When limit == 0 or limit == 1, max_split will be non-positive and will result in an // unlimited split. - JNI_THROW_NEW(env, "java/lang/IllegalArgumentException", - "limit == 0 and limit == 1 are not supported", 0); + JNI_THROW_NEW( + env, "java/lang/IllegalArgumentException", "limit == 0 and limit == 1 are not supported", 0); } try { cudf::jni::auto_set_device(env); - auto const input = reinterpret_cast(input_handle); + auto const input = reinterpret_cast(input_handle); auto const strings_column = cudf::strings_column_view{*input}; auto const delimiter_jstr = cudf::jni::native_jstring(env, delimiter_obj); - auto const delimiter = std::string(delimiter_jstr.get(), delimiter_jstr.size_bytes()); - auto const max_split = limit > 1 ? limit - 1 : limit; + auto const delimiter = std::string(delimiter_jstr.get(), delimiter_jstr.size_bytes()); + auto const max_split = limit > 1 ? limit - 1 : limit; auto result = cudf::strings::split(strings_column, cudf::string_scalar{delimiter}, max_split); return cudf::jni::convert_table_for_return(env, std::move(result)); } CATCH_STD(env, 0); } -JNIEXPORT jlongArray JNICALL Java_ai_rapids_cudf_ColumnView_stringSplitRe( - JNIEnv *env, jclass, jlong input_handle, jstring pattern_obj, jint regex_flags, - jint capture_groups, jint limit) { +JNIEXPORT jlongArray JNICALL Java_ai_rapids_cudf_ColumnView_stringSplitRe(JNIEnv* env, + jclass, + jlong input_handle, + jstring pattern_obj, + jint regex_flags, + jint capture_groups, + jint limit) +{ JNI_NULL_CHECK(env, input_handle, "input_handle is null", 0); if (limit == 0 || limit == 1) { @@ -761,30 +836,29 @@ JNIEXPORT jlongArray JNICALL Java_ai_rapids_cudf_ColumnView_stringSplitRe( // This is because cudf operates on a different parameter (`max_split`) which is converted from // limit. When limit == 0 or limit == 1, max_split will be non-positive and will result in an // unlimited split. - JNI_THROW_NEW(env, "java/lang/IllegalArgumentException", - "limit == 0 and limit == 1 are not supported", 0); + JNI_THROW_NEW( + env, "java/lang/IllegalArgumentException", "limit == 0 and limit == 1 are not supported", 0); } try { cudf::jni::auto_set_device(env); - auto const input = reinterpret_cast(input_handle); + auto const input = reinterpret_cast(input_handle); auto const strings_column = cudf::strings_column_view{*input}; - auto const pattern_jstr = cudf::jni::native_jstring(env, pattern_obj); - auto const pattern = std::string(pattern_jstr.get(), pattern_jstr.size_bytes()); - auto const max_split = limit > 1 ? limit - 1 : limit; - auto const flags = static_cast(regex_flags); - auto const groups = static_cast(capture_groups); - auto const regex_prog = cudf::strings::regex_program::create(pattern, flags, groups); - auto result = cudf::strings::split_re(strings_column, *regex_prog, max_split); + auto const pattern_jstr = cudf::jni::native_jstring(env, pattern_obj); + auto const pattern = std::string(pattern_jstr.get(), pattern_jstr.size_bytes()); + auto const max_split = limit > 1 ? limit - 1 : limit; + auto const flags = static_cast(regex_flags); + auto const groups = static_cast(capture_groups); + auto const regex_prog = cudf::strings::regex_program::create(pattern, flags, groups); + auto result = cudf::strings::split_re(strings_column, *regex_prog, max_split); return cudf::jni::convert_table_for_return(env, std::move(result)); } CATCH_STD(env, 0); } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_stringSplitRecord(JNIEnv *env, jclass, - jlong input_handle, - jstring delimiter_obj, - jint limit) { +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_stringSplitRecord( + JNIEnv* env, jclass, jlong input_handle, jstring delimiter_obj, jint limit) +{ JNI_NULL_CHECK(env, input_handle, "input_handle is null", 0); if (limit == 0 || limit == 1) { @@ -792,27 +866,32 @@ JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_stringSplitRecord(JNIEnv // This is because cudf operates on a different parameter (`max_split`) which is converted from // limit. When limit == 0 or limit == 1, max_split will be non-positive and will result in an // unlimited split. - JNI_THROW_NEW(env, "java/lang/IllegalArgumentException", - "limit == 0 and limit == 1 are not supported", 0); + JNI_THROW_NEW( + env, "java/lang/IllegalArgumentException", "limit == 0 and limit == 1 are not supported", 0); } try { cudf::jni::auto_set_device(env); - auto const input = reinterpret_cast(input_handle); + auto const input = reinterpret_cast(input_handle); auto const strings_column = cudf::strings_column_view{*input}; auto const delimiter_jstr = cudf::jni::native_jstring(env, delimiter_obj); - auto const delimiter = std::string(delimiter_jstr.get(), delimiter_jstr.size_bytes()); - auto const max_split = limit > 1 ? limit - 1 : limit; + auto const delimiter = std::string(delimiter_jstr.get(), delimiter_jstr.size_bytes()); + auto const max_split = limit > 1 ? limit - 1 : limit; auto result = - cudf::strings::split_record(strings_column, cudf::string_scalar{delimiter}, max_split); + cudf::strings::split_record(strings_column, cudf::string_scalar{delimiter}, max_split); return release_as_jlong(result); } CATCH_STD(env, 0); } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_stringSplitRecordRe( - JNIEnv *env, jclass, jlong input_handle, jstring pattern_obj, jint regex_flags, - jint capture_groups, jint limit) { +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_stringSplitRecordRe(JNIEnv* env, + jclass, + jlong input_handle, + jstring pattern_obj, + jint regex_flags, + jint capture_groups, + jint limit) +{ JNI_NULL_CHECK(env, input_handle, "input_handle is null", 0); if (limit == 0 || limit == 1) { @@ -820,99 +899,108 @@ JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_stringSplitRecordRe( // This is because cudf operates on a different parameter (`max_split`) which is converted from // limit. When limit == 0 or limit == 1, max_split will be non-positive and will result in an // unlimited split. - JNI_THROW_NEW(env, "java/lang/IllegalArgumentException", - "limit == 0 and limit == 1 are not supported", 0); + JNI_THROW_NEW( + env, "java/lang/IllegalArgumentException", "limit == 0 and limit == 1 are not supported", 0); } try { cudf::jni::auto_set_device(env); - auto const input = reinterpret_cast(input_handle); + auto const input = reinterpret_cast(input_handle); auto const strings_column = cudf::strings_column_view{*input}; - auto const pattern_jstr = cudf::jni::native_jstring(env, pattern_obj); - auto const pattern = std::string(pattern_jstr.get(), pattern_jstr.size_bytes()); - auto const max_split = limit > 1 ? limit - 1 : limit; - auto const flags = static_cast(regex_flags); - auto const groups = static_cast(capture_groups); - auto const regex_prog = cudf::strings::regex_program::create(pattern, flags, groups); + auto const pattern_jstr = cudf::jni::native_jstring(env, pattern_obj); + auto const pattern = std::string(pattern_jstr.get(), pattern_jstr.size_bytes()); + auto const max_split = limit > 1 ? limit - 1 : limit; + auto const flags = static_cast(regex_flags); + auto const groups = static_cast(capture_groups); + auto const regex_prog = cudf::strings::regex_program::create(pattern, flags, groups); auto result = cudf::strings::split_record_re(strings_column, *regex_prog, max_split); return release_as_jlong(result); } CATCH_STD(env, 0); } -JNIEXPORT jlongArray JNICALL Java_ai_rapids_cudf_ColumnView_split(JNIEnv *env, jclass clazz, +JNIEXPORT jlongArray JNICALL Java_ai_rapids_cudf_ColumnView_split(JNIEnv* env, + jclass clazz, jlong input_column, - jintArray split_indices) { + jintArray split_indices) +{ JNI_NULL_CHECK(env, input_column, "native handle is null", 0); JNI_NULL_CHECK(env, split_indices, "split indices are null", 0); try { cudf::jni::auto_set_device(env); - cudf::column_view *n_column = reinterpret_cast(input_column); + cudf::column_view* n_column = reinterpret_cast(input_column); cudf::jni::native_jintArray n_split_indices(env, split_indices); std::vector indices(n_split_indices.begin(), n_split_indices.end()); std::vector result = cudf::split(*n_column, indices); cudf::jni::native_jlongArray n_result(env, result.size()); - std::transform(result.begin(), result.end(), n_result.begin(), - [](cudf::column_view const &result_col) { - return ptr_as_jlong(new cudf::column_view{result_col}); - }); + std::transform( + result.begin(), result.end(), n_result.begin(), [](cudf::column_view const& result_col) { + return ptr_as_jlong(new cudf::column_view{result_col}); + }); return n_result.get_jArray(); } CATCH_STD(env, NULL); } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_countElements(JNIEnv *env, jclass clazz, - jlong view_handle) { +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_countElements(JNIEnv* env, + jclass clazz, + jlong view_handle) +{ JNI_NULL_CHECK(env, view_handle, "input column is null", 0); try { cudf::jni::auto_set_device(env); - cudf::column_view *n_column = reinterpret_cast(view_handle); + cudf::column_view* n_column = reinterpret_cast(view_handle); return release_as_jlong(cudf::lists::count_elements(cudf::lists_column_view(*n_column))); } CATCH_STD(env, 0); } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_charLengths(JNIEnv *env, jclass clazz, - jlong view_handle) { +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_charLengths(JNIEnv* env, + jclass clazz, + jlong view_handle) +{ JNI_NULL_CHECK(env, view_handle, "input column is null", 0); try { cudf::jni::auto_set_device(env); - cudf::column_view *n_column = reinterpret_cast(view_handle); + cudf::column_view* n_column = reinterpret_cast(view_handle); return release_as_jlong(cudf::strings::count_characters(cudf::strings_column_view(*n_column))); } CATCH_STD(env, 0); } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_byteCount(JNIEnv *env, jclass clazz, - jlong view_handle) { +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_byteCount(JNIEnv* env, + jclass clazz, + jlong view_handle) +{ JNI_NULL_CHECK(env, view_handle, "input column is null", 0); try { cudf::jni::auto_set_device(env); - cudf::column_view *n_column = reinterpret_cast(view_handle); + cudf::column_view* n_column = reinterpret_cast(view_handle); return release_as_jlong(cudf::strings::count_bytes(cudf::strings_column_view(*n_column))); } CATCH_STD(env, 0); } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_codePoints(JNIEnv *env, jclass clazz, - jlong view_handle) { +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_codePoints(JNIEnv* env, + jclass clazz, + jlong view_handle) +{ JNI_NULL_CHECK(env, view_handle, "input column is null", 0); try { cudf::jni::auto_set_device(env); - auto const input = reinterpret_cast(view_handle); + auto const input = reinterpret_cast(view_handle); return release_as_jlong(cudf::strings::code_points(cudf::strings_column_view{*input})); } CATCH_STD(env, 0); } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_findAndReplaceAll(JNIEnv *env, jclass clazz, - jlong old_values_handle, - jlong new_values_handle, - jlong input_handle) { +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_findAndReplaceAll( + JNIEnv* env, jclass clazz, jlong old_values_handle, jlong new_values_handle, jlong input_handle) +{ JNI_NULL_CHECK(env, old_values_handle, "values column is null", 0); JNI_NULL_CHECK(env, new_values_handle, "replace column is null", 0); JNI_NULL_CHECK(env, input_handle, "input column is null", 0); @@ -922,230 +1010,253 @@ JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_findAndReplaceAll(JNIEnv try { cudf::jni::auto_set_device(env); - column_view *input_column = reinterpret_cast(input_handle); - column_view *old_values_column = reinterpret_cast(old_values_handle); - column_view *new_values_column = reinterpret_cast(new_values_handle); + column_view* input_column = reinterpret_cast(input_handle); + column_view* old_values_column = reinterpret_cast(old_values_handle); + column_view* new_values_column = reinterpret_cast(new_values_handle); return release_as_jlong( - cudf::find_and_replace_all(*input_column, *old_values_column, *new_values_column)); + cudf::find_and_replace_all(*input_column, *old_values_column, *new_values_column)); } CATCH_STD(env, 0); } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_isNullNative(JNIEnv *env, jclass, - jlong handle) { +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_isNullNative(JNIEnv* env, + jclass, + jlong handle) +{ JNI_NULL_CHECK(env, handle, "input column is null", 0); try { cudf::jni::auto_set_device(env); - const cudf::column_view *input = reinterpret_cast(handle); + const cudf::column_view* input = reinterpret_cast(handle); return release_as_jlong(cudf::is_null(*input)); } CATCH_STD(env, 0); } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_isNotNullNative(JNIEnv *env, jclass, - jlong handle) { +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_isNotNullNative(JNIEnv* env, + jclass, + jlong handle) +{ JNI_NULL_CHECK(env, handle, "input column is null", 0); try { cudf::jni::auto_set_device(env); - const cudf::column_view *input = reinterpret_cast(handle); + const cudf::column_view* input = reinterpret_cast(handle); return release_as_jlong(cudf::is_valid(*input)); } CATCH_STD(env, 0); } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_isNanNative(JNIEnv *env, jclass, - jlong handle) { +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_isNanNative(JNIEnv* env, + jclass, + jlong handle) +{ JNI_NULL_CHECK(env, handle, "input column is null", 0); try { cudf::jni::auto_set_device(env); - const cudf::column_view *input = reinterpret_cast(handle); + const cudf::column_view* input = reinterpret_cast(handle); return release_as_jlong(cudf::is_nan(*input)); } CATCH_STD(env, 0); } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_isNotNanNative(JNIEnv *env, jclass, - jlong handle) { +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_isNotNanNative(JNIEnv* env, + jclass, + jlong handle) +{ JNI_NULL_CHECK(env, handle, "input column is null", 0); try { cudf::jni::auto_set_device(env); - const cudf::column_view *input = reinterpret_cast(handle); + const cudf::column_view* input = reinterpret_cast(handle); return release_as_jlong(cudf::is_not_nan(*input)); } CATCH_STD(env, 0); } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_unaryOperation(JNIEnv *env, jclass, +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_unaryOperation(JNIEnv* env, + jclass, jlong input_ptr, - jint int_op) { + jint int_op) +{ JNI_NULL_CHECK(env, input_ptr, "input is null", 0); try { cudf::jni::auto_set_device(env); - cudf::column_view *input = reinterpret_cast(input_ptr); - cudf::unary_operator op = static_cast(int_op); + cudf::column_view* input = reinterpret_cast(input_ptr); + cudf::unary_operator op = static_cast(int_op); return release_as_jlong(cudf::unary_operation(*input, op)); } CATCH_STD(env, 0); } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_round(JNIEnv *env, jclass, jlong input_ptr, - jint decimal_places, - jint rounding_method) { +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_round( + JNIEnv* env, jclass, jlong input_ptr, jint decimal_places, jint rounding_method) +{ JNI_NULL_CHECK(env, input_ptr, "input is null", 0); try { cudf::jni::auto_set_device(env); - cudf::column_view *input = reinterpret_cast(input_ptr); + cudf::column_view* input = reinterpret_cast(input_ptr); cudf::rounding_method method = static_cast(rounding_method); return release_as_jlong(cudf::round(*input, decimal_places, method)); } CATCH_STD(env, 0); } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_year(JNIEnv *env, jclass, jlong input_ptr) { +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_year(JNIEnv* env, jclass, jlong input_ptr) +{ JNI_NULL_CHECK(env, input_ptr, "input is null", 0); try { cudf::jni::auto_set_device(env); - const cudf::column_view *input = reinterpret_cast(input_ptr); + const cudf::column_view* input = reinterpret_cast(input_ptr); return release_as_jlong(cudf::datetime::extract_year(*input)); } CATCH_STD(env, 0); } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_month(JNIEnv *env, jclass, jlong input_ptr) { +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_month(JNIEnv* env, jclass, jlong input_ptr) +{ JNI_NULL_CHECK(env, input_ptr, "input is null", 0); try { cudf::jni::auto_set_device(env); - const cudf::column_view *input = reinterpret_cast(input_ptr); + const cudf::column_view* input = reinterpret_cast(input_ptr); return release_as_jlong(cudf::datetime::extract_month(*input)); } CATCH_STD(env, 0); } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_day(JNIEnv *env, jclass, jlong input_ptr) { +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_day(JNIEnv* env, jclass, jlong input_ptr) +{ JNI_NULL_CHECK(env, input_ptr, "input is null", 0); try { cudf::jni::auto_set_device(env); - const cudf::column_view *input = reinterpret_cast(input_ptr); + const cudf::column_view* input = reinterpret_cast(input_ptr); return release_as_jlong(cudf::datetime::extract_day(*input)); } CATCH_STD(env, 0); } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_hour(JNIEnv *env, jclass, jlong input_ptr) { +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_hour(JNIEnv* env, jclass, jlong input_ptr) +{ JNI_NULL_CHECK(env, input_ptr, "input is null", 0); try { cudf::jni::auto_set_device(env); - const cudf::column_view *input = reinterpret_cast(input_ptr); + const cudf::column_view* input = reinterpret_cast(input_ptr); return release_as_jlong(cudf::datetime::extract_hour(*input)); } CATCH_STD(env, 0); } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_minute(JNIEnv *env, jclass, - jlong input_ptr) { +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_minute(JNIEnv* env, jclass, jlong input_ptr) +{ JNI_NULL_CHECK(env, input_ptr, "input is null", 0); try { cudf::jni::auto_set_device(env); - const cudf::column_view *input = reinterpret_cast(input_ptr); + const cudf::column_view* input = reinterpret_cast(input_ptr); return release_as_jlong(cudf::datetime::extract_minute(*input)); } CATCH_STD(env, 0); } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_second(JNIEnv *env, jclass, - jlong input_ptr) { +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_second(JNIEnv* env, jclass, jlong input_ptr) +{ JNI_NULL_CHECK(env, input_ptr, "input is null", 0); try { cudf::jni::auto_set_device(env); - const cudf::column_view *input = reinterpret_cast(input_ptr); + const cudf::column_view* input = reinterpret_cast(input_ptr); return release_as_jlong(cudf::datetime::extract_second(*input)); } CATCH_STD(env, 0); } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_weekDay(JNIEnv *env, jclass, - jlong input_ptr) { +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_weekDay(JNIEnv* env, jclass, jlong input_ptr) +{ JNI_NULL_CHECK(env, input_ptr, "input is null", 0); try { cudf::jni::auto_set_device(env); - const cudf::column_view *input = reinterpret_cast(input_ptr); + const cudf::column_view* input = reinterpret_cast(input_ptr); return release_as_jlong(cudf::datetime::extract_weekday(*input)); } CATCH_STD(env, 0); } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_lastDayOfMonth(JNIEnv *env, jclass, - jlong input_ptr) { +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_lastDayOfMonth(JNIEnv* env, + jclass, + jlong input_ptr) +{ JNI_NULL_CHECK(env, input_ptr, "input is null", 0); try { cudf::jni::auto_set_device(env); - const cudf::column_view *input = reinterpret_cast(input_ptr); + const cudf::column_view* input = reinterpret_cast(input_ptr); return release_as_jlong(cudf::datetime::last_day_of_month(*input)); } CATCH_STD(env, 0); } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_dayOfYear(JNIEnv *env, jclass, - jlong input_ptr) { +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_dayOfYear(JNIEnv* env, + jclass, + jlong input_ptr) +{ JNI_NULL_CHECK(env, input_ptr, "input is null", 0); try { cudf::jni::auto_set_device(env); - const cudf::column_view *input = reinterpret_cast(input_ptr); + const cudf::column_view* input = reinterpret_cast(input_ptr); return release_as_jlong(cudf::datetime::day_of_year(*input)); } CATCH_STD(env, 0); } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_quarterOfYear(JNIEnv *env, jclass, - jlong input_ptr) { +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_quarterOfYear(JNIEnv* env, + jclass, + jlong input_ptr) +{ JNI_NULL_CHECK(env, input_ptr, "input is null", 0); try { cudf::jni::auto_set_device(env); - const cudf::column_view *input = reinterpret_cast(input_ptr); + const cudf::column_view* input = reinterpret_cast(input_ptr); return release_as_jlong(cudf::datetime::extract_quarter(*input)); } CATCH_STD(env, 0); } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_addCalendricalMonths(JNIEnv *env, jclass, +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_addCalendricalMonths(JNIEnv* env, + jclass, jlong ts_ptr, - jlong months_ptr) { + jlong months_ptr) +{ JNI_NULL_CHECK(env, ts_ptr, "ts is null", 0); JNI_NULL_CHECK(env, months_ptr, "months is null", 0); try { cudf::jni::auto_set_device(env); - const cudf::column_view *ts = reinterpret_cast(ts_ptr); - const cudf::column_view *months = reinterpret_cast(months_ptr); + const cudf::column_view* ts = reinterpret_cast(ts_ptr); + const cudf::column_view* months = reinterpret_cast(months_ptr); return release_as_jlong(cudf::datetime::add_calendrical_months(*ts, *months)); } CATCH_STD(env, 0); } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_isLeapYear(JNIEnv *env, jclass, - jlong input_ptr) { +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_isLeapYear(JNIEnv* env, + jclass, + jlong input_ptr) +{ JNI_NULL_CHECK(env, input_ptr, "input is null", 0); try { cudf::jni::auto_set_device(env); - const cudf::column_view *input = reinterpret_cast(input_ptr); + const cudf::column_view* input = reinterpret_cast(input_ptr); return release_as_jlong(cudf::datetime::is_leap_year(*input)); } CATCH_STD(env, 0); } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_castTo(JNIEnv *env, jclass, jlong handle, - jint type, jint scale) { +JNIEXPORT jlong JNICALL +Java_ai_rapids_cudf_ColumnView_castTo(JNIEnv* env, jclass, jlong handle, jint type, jint scale) +{ JNI_NULL_CHECK(env, handle, "native handle is null", 0); try { cudf::jni::auto_set_device(env); - cudf::column_view *column = reinterpret_cast(handle); + cudf::column_view* column = reinterpret_cast(handle); cudf::data_type n_data_type = cudf::jni::make_data_type(type, scale); - if (n_data_type == column->type()) { - return ptr_as_jlong(new cudf::column(*column)); - } + if (n_data_type == column->type()) { return ptr_as_jlong(new cudf::column(*column)); } if (n_data_type.id() == cudf::type_id::STRING) { switch (column->type().id()) { case cudf::type_id::BOOL8: { - auto const true_scalar = cudf::string_scalar("true"); + auto const true_scalar = cudf::string_scalar("true"); auto const false_scalar = cudf::string_scalar("false"); return release_as_jlong(cudf::strings::from_booleans(*column, true_scalar, false_scalar)); } @@ -1195,26 +1306,30 @@ JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_castTo(JNIEnv *env, jclas // "reinterpret" casting will be supported via https://github.com/rapidsai/cudf/pull/5358 if (n_data_type.id() == cudf::type_id::TIMESTAMP_DAYS) { if (column->type().id() != cudf::type_id::INT32) { - JNI_THROW_NEW(env, "java/lang/IllegalArgumentException", - "Numeric cast to TIMESTAMP_DAYS requires INT32", 0); + JNI_THROW_NEW(env, + "java/lang/IllegalArgumentException", + "Numeric cast to TIMESTAMP_DAYS requires INT32", + 0); } } else { if (column->type().id() != cudf::type_id::INT64) { - JNI_THROW_NEW(env, "java/lang/IllegalArgumentException", - "Numeric cast to non-day timestamp requires INT64", 0); + JNI_THROW_NEW(env, + "java/lang/IllegalArgumentException", + "Numeric cast to non-day timestamp requires INT64", + 0); } } - cudf::data_type duration_type = cudf::jni::timestamp_to_duration(n_data_type); + cudf::data_type duration_type = cudf::jni::timestamp_to_duration(n_data_type); cudf::column_view duration_view = cudf::column_view( - duration_type, column->size(), column->head(), column->null_mask(), column->null_count()); + duration_type, column->size(), column->head(), column->null_mask(), column->null_count()); return release_as_jlong(cudf::cast(duration_view, n_data_type)); } else if (cudf::is_timestamp(column->type()) && cudf::is_numeric(n_data_type)) { // This is a temporary workaround to allow Java to cast from timestamp types to integral types // without forcing an intermediate duration column to be manifested. Ultimately this style of // "reinterpret" casting will be supported via https://github.com/rapidsai/cudf/pull/5358 - cudf::data_type duration_type = cudf::jni::timestamp_to_duration(column->type()); + cudf::data_type duration_type = cudf::jni::timestamp_to_duration(column->type()); cudf::column_view duration_view = cudf::column_view( - duration_type, column->size(), column->head(), column->null_mask(), column->null_count()); + duration_type, column->size(), column->head(), column->null_mask(), column->null_count()); return release_as_jlong(cudf::cast(duration_view, n_data_type)); } else { return release_as_jlong(cudf::cast(*column, n_data_type)); @@ -1223,25 +1338,28 @@ JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_castTo(JNIEnv *env, jclas CATCH_STD(env, 0); } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_bitCastTo(JNIEnv *env, jclass, jlong handle, - jint type, jint scale) { +JNIEXPORT jlong JNICALL +Java_ai_rapids_cudf_ColumnView_bitCastTo(JNIEnv* env, jclass, jlong handle, jint type, jint scale) +{ JNI_NULL_CHECK(env, handle, "native handle is null", 0); try { cudf::jni::auto_set_device(env); - cudf::column_view *column = reinterpret_cast(handle); + cudf::column_view* column = reinterpret_cast(handle); cudf::data_type n_data_type = cudf::jni::make_data_type(type, scale); return ptr_as_jlong(new cudf::column_view{cudf::bit_cast(*column, n_data_type)}); } CATCH_STD(env, 0); } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_byteListCast(JNIEnv *env, jobject j_object, +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_byteListCast(JNIEnv* env, + jobject j_object, jlong handle, - jboolean endianness_config) { + jboolean endianness_config) +{ JNI_NULL_CHECK(env, handle, "native handle is null", 0); try { cudf::jni::auto_set_device(env); - cudf::column_view *column = reinterpret_cast(handle); + cudf::column_view* column = reinterpret_cast(handle); cudf::flip_endianness config(static_cast(endianness_config)); return release_as_jlong(byte_cast(*column, config)); } @@ -1249,78 +1367,86 @@ JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_byteListCast(JNIEnv *env, } JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_stringTimestampToTimestamp( - JNIEnv *env, jobject j_object, jlong handle, jint time_unit, jstring formatObj) { + JNIEnv* env, jobject j_object, jlong handle, jint time_unit, jstring formatObj) +{ JNI_NULL_CHECK(env, handle, "column is null", 0); JNI_NULL_CHECK(env, formatObj, "format is null", 0); try { cudf::jni::auto_set_device(env); cudf::jni::native_jstring format(env, formatObj); - cudf::column_view *column = reinterpret_cast(handle); + cudf::column_view* column = reinterpret_cast(handle); cudf::strings_column_view strings_column(*column); return release_as_jlong(cudf::strings::to_timestamps( - strings_column, cudf::data_type(static_cast(time_unit)), format.get())); + strings_column, cudf::data_type(static_cast(time_unit)), format.get())); } CATCH_STD(env, 0); } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_isTimestamp(JNIEnv *env, jclass, +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_isTimestamp(JNIEnv* env, + jclass, jlong handle, - jstring formatObj) { + jstring formatObj) +{ JNI_NULL_CHECK(env, handle, "column is null", 0); JNI_NULL_CHECK(env, formatObj, "format is null", 0); try { cudf::jni::auto_set_device(env); cudf::jni::native_jstring format(env, formatObj); - cudf::column_view *column = reinterpret_cast(handle); + cudf::column_view* column = reinterpret_cast(handle); cudf::strings_column_view strings_column(*column); return release_as_jlong(cudf::strings::is_timestamp(strings_column, format.get())); } CATCH_STD(env, 0); } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_timestampToStringTimestamp( - JNIEnv *env, jobject j_object, jlong handle, jstring j_format) { +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_timestampToStringTimestamp(JNIEnv* env, + jobject j_object, + jlong handle, + jstring j_format) +{ JNI_NULL_CHECK(env, handle, "column is null", 0); JNI_NULL_CHECK(env, j_format, "format is null", 0); try { cudf::jni::auto_set_device(env); cudf::jni::native_jstring format(env, j_format); - cudf::column_view *column = reinterpret_cast(handle); + cudf::column_view* column = reinterpret_cast(handle); return release_as_jlong(cudf::strings::from_timestamps(*column, format.get())); } CATCH_STD(env, 0); } -JNIEXPORT jboolean JNICALL Java_ai_rapids_cudf_ColumnView_containsScalar(JNIEnv *env, +JNIEXPORT jboolean JNICALL Java_ai_rapids_cudf_ColumnView_containsScalar(JNIEnv* env, jobject j_object, jlong j_view_handle, - jlong j_scalar_handle) { + jlong j_scalar_handle) +{ JNI_NULL_CHECK(env, j_view_handle, "haystack vector is null", false); JNI_NULL_CHECK(env, j_scalar_handle, "scalar needle is null", false); try { cudf::jni::auto_set_device(env); - cudf::column_view *column_view = reinterpret_cast(j_view_handle); - cudf::scalar *scalar = reinterpret_cast(j_scalar_handle); + cudf::column_view* column_view = reinterpret_cast(j_view_handle); + cudf::scalar* scalar = reinterpret_cast(j_scalar_handle); return cudf::contains(*column_view, *scalar); } CATCH_STD(env, 0); } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_containsVector(JNIEnv *env, jobject j_object, +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_containsVector(JNIEnv* env, + jobject j_object, jlong j_values_handle, - jlong j_search_space_handle) { + jlong j_search_space_handle) +{ JNI_NULL_CHECK(env, j_values_handle, "values vector is null", false); JNI_NULL_CHECK(env, j_search_space_handle, "search_space vector is null", false); try { cudf::jni::auto_set_device(env); - auto const search_space_ptr = - reinterpret_cast(j_search_space_handle); - auto const values_ptr = reinterpret_cast(j_values_handle); + auto const search_space_ptr = reinterpret_cast(j_search_space_handle); + auto const values_ptr = reinterpret_cast(j_values_handle); // The C++ API `cudf::contains` requires that the search space is the first parameter. return release_as_jlong(cudf::contains(*search_space_ptr, *values_ptr)); @@ -1328,141 +1454,149 @@ JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_containsVector(JNIEnv *en CATCH_STD(env, 0); } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_transform(JNIEnv *env, jobject j_object, - jlong handle, jstring j_udf, - jboolean j_is_ptx) { +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_transform( + JNIEnv* env, jobject j_object, jlong handle, jstring j_udf, jboolean j_is_ptx) +{ try { cudf::jni::auto_set_device(env); - cudf::column_view *column = reinterpret_cast(handle); + cudf::column_view* column = reinterpret_cast(handle); cudf::jni::native_jstring n_j_udf(env, j_udf); std::string n_udf(n_j_udf.get()); return release_as_jlong( - cudf::transform(*column, n_udf, cudf::data_type(cudf::type_id::INT32), j_is_ptx)); + cudf::transform(*column, n_udf, cudf::data_type(cudf::type_id::INT32), j_is_ptx)); } CATCH_STD(env, 0); } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_stringStartWith(JNIEnv *env, +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_stringStartWith(JNIEnv* env, jobject j_object, jlong j_view_handle, - jlong comp_string) { + jlong comp_string) +{ JNI_NULL_CHECK(env, j_view_handle, "column is null", false); JNI_NULL_CHECK(env, comp_string, "comparison string scalar is null", false); try { cudf::jni::auto_set_device(env); - cudf::column_view *column_view = reinterpret_cast(j_view_handle); + cudf::column_view* column_view = reinterpret_cast(j_view_handle); cudf::strings_column_view strings_column(*column_view); - cudf::string_scalar *comp_scalar = reinterpret_cast(comp_string); + cudf::string_scalar* comp_scalar = reinterpret_cast(comp_string); return release_as_jlong(cudf::strings::starts_with(strings_column, *comp_scalar)); } CATCH_STD(env, 0); } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_stringEndWith(JNIEnv *env, jobject j_object, +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_stringEndWith(JNIEnv* env, + jobject j_object, jlong j_view_handle, - jlong comp_string) { + jlong comp_string) +{ JNI_NULL_CHECK(env, j_view_handle, "column is null", false); JNI_NULL_CHECK(env, comp_string, "comparison string scalar is null", false); try { cudf::jni::auto_set_device(env); - cudf::column_view *column_view = reinterpret_cast(j_view_handle); + cudf::column_view* column_view = reinterpret_cast(j_view_handle); cudf::strings_column_view strings_column(*column_view); - cudf::string_scalar *comp_scalar = reinterpret_cast(comp_string); + cudf::string_scalar* comp_scalar = reinterpret_cast(comp_string); return release_as_jlong(cudf::strings::ends_with(strings_column, *comp_scalar)); } CATCH_STD(env, 0); } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_stringContains(JNIEnv *env, jobject j_object, +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_stringContains(JNIEnv* env, + jobject j_object, jlong j_view_handle, - jlong comp_string) { + jlong comp_string) +{ JNI_NULL_CHECK(env, j_view_handle, "column is null", false); JNI_NULL_CHECK(env, comp_string, "comparison string scalar is null", false); try { cudf::jni::auto_set_device(env); - cudf::column_view *column_view = reinterpret_cast(j_view_handle); + cudf::column_view* column_view = reinterpret_cast(j_view_handle); cudf::strings_column_view strings_column(*column_view); - cudf::string_scalar *comp_scalar = reinterpret_cast(comp_string); + cudf::string_scalar* comp_scalar = reinterpret_cast(comp_string); return release_as_jlong(cudf::strings::contains(strings_column, *comp_scalar)); } CATCH_STD(env, 0); } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_matchesRe(JNIEnv *env, jobject j_object, +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_matchesRe(JNIEnv* env, + jobject j_object, jlong j_view_handle, jstring pattern_obj, jint regex_flags, - jint capture_groups) { + jint capture_groups) +{ JNI_NULL_CHECK(env, j_view_handle, "column is null", false); JNI_NULL_CHECK(env, pattern_obj, "pattern is null", false); try { cudf::jni::auto_set_device(env); - auto const column_view = reinterpret_cast(j_view_handle); + auto const column_view = reinterpret_cast(j_view_handle); auto const strings_column = cudf::strings_column_view{*column_view}; - auto const pattern = cudf::jni::native_jstring(env, pattern_obj); - auto const flags = static_cast(regex_flags); - auto const groups = static_cast(capture_groups); - auto const regex_prog = cudf::strings::regex_program::create(pattern.get(), flags, groups); + auto const pattern = cudf::jni::native_jstring(env, pattern_obj); + auto const flags = static_cast(regex_flags); + auto const groups = static_cast(capture_groups); + auto const regex_prog = cudf::strings::regex_program::create(pattern.get(), flags, groups); return release_as_jlong(cudf::strings::matches_re(strings_column, *regex_prog)); } CATCH_STD(env, 0); } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_containsRe(JNIEnv *env, jobject j_object, +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_containsRe(JNIEnv* env, + jobject j_object, jlong j_view_handle, jstring pattern_obj, jint regex_flags, - jint capture_groups) { + jint capture_groups) +{ JNI_NULL_CHECK(env, j_view_handle, "column is null", false); JNI_NULL_CHECK(env, pattern_obj, "pattern is null", false); try { cudf::jni::auto_set_device(env); - auto const column_view = reinterpret_cast(j_view_handle); + auto const column_view = reinterpret_cast(j_view_handle); auto const strings_column = cudf::strings_column_view{*column_view}; - auto const pattern = cudf::jni::native_jstring(env, pattern_obj); - auto const flags = static_cast(regex_flags); - auto const capture = static_cast(capture_groups); - auto const regex_prog = cudf::strings::regex_program::create(pattern.get(), flags, capture); + auto const pattern = cudf::jni::native_jstring(env, pattern_obj); + auto const flags = static_cast(regex_flags); + auto const capture = static_cast(capture_groups); + auto const regex_prog = cudf::strings::regex_program::create(pattern.get(), flags, capture); return release_as_jlong(cudf::strings::contains_re(strings_column, *regex_prog)); } CATCH_STD(env, 0); } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_like(JNIEnv *env, jobject j_object, - jlong j_view_handle, jlong pattern, - jlong escapeChar) { +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_like( + JNIEnv* env, jobject j_object, jlong j_view_handle, jlong pattern, jlong escapeChar) +{ JNI_NULL_CHECK(env, j_view_handle, "column is null", false); JNI_NULL_CHECK(env, pattern, "pattern is null", false); JNI_NULL_CHECK(env, escapeChar, "escape character is null", false); try { cudf::jni::auto_set_device(env); - auto const column_view = reinterpret_cast(j_view_handle); + auto const column_view = reinterpret_cast(j_view_handle); auto const strings_column = cudf::strings_column_view{*column_view}; - auto const pattern_scalar = reinterpret_cast(pattern); - auto const escape_scalar = reinterpret_cast(escapeChar); + auto const pattern_scalar = reinterpret_cast(pattern); + auto const escape_scalar = reinterpret_cast(escapeChar); return release_as_jlong(cudf::strings::like(strings_column, *pattern_scalar, *escape_scalar)); } CATCH_STD(env, 0); } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_binaryOpVV(JNIEnv *env, jclass, - jlong lhs_view, jlong rhs_view, - jint int_op, jint out_dtype, - jint scale) { +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_binaryOpVV( + JNIEnv* env, jclass, jlong lhs_view, jlong rhs_view, jint int_op, jint out_dtype, jint scale) +{ JNI_NULL_CHECK(env, lhs_view, "lhs is null", 0); JNI_NULL_CHECK(env, rhs_view, "rhs is null", 0); try { cudf::jni::auto_set_device(env); - auto lhs = reinterpret_cast(lhs_view); - auto rhs = reinterpret_cast(rhs_view); + auto lhs = reinterpret_cast(lhs_view); + auto rhs = reinterpret_cast(rhs_view); cudf::data_type n_data_type = cudf::jni::make_data_type(out_dtype, scale); - cudf::binary_operator op = static_cast(int_op); + cudf::binary_operator op = static_cast(int_op); if (lhs->type().id() == cudf::type_id::STRUCT) { auto out = make_fixed_width_column(n_data_type, lhs->size(), cudf::mask_state::UNALLOCATED); @@ -1476,7 +1610,7 @@ JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_binaryOpVV(JNIEnv *env, j auto out_view = out->mutable_view(); cudf::binops::compiled::detail::apply_sorting_struct_binary_op( - out_view, *lhs, *rhs, false, false, op, cudf::get_default_stream()); + out_view, *lhs, *rhs, false, false, op, cudf::get_default_stream()); return release_as_jlong(out); } @@ -1485,30 +1619,28 @@ JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_binaryOpVV(JNIEnv *env, j CATCH_STD(env, 0); } -JNIEXPORT jint JNICALL Java_ai_rapids_cudf_ColumnView_fixedPointOutputScale(JNIEnv *env, jclass, - jint int_op, - jint lhs_scale, - jint rhs_scale) { +JNIEXPORT jint JNICALL Java_ai_rapids_cudf_ColumnView_fixedPointOutputScale( + JNIEnv* env, jclass, jint int_op, jint lhs_scale, jint rhs_scale) +{ try { // we just return the scale as the types will be the same as the lhs input - return cudf::binary_operation_fixed_point_scale(static_cast(int_op), - lhs_scale, rhs_scale); + return cudf::binary_operation_fixed_point_scale( + static_cast(int_op), lhs_scale, rhs_scale); } CATCH_STD(env, 0); } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_binaryOpVS(JNIEnv *env, jclass, - jlong lhs_view, jlong rhs_ptr, - jint int_op, jint out_dtype, - jint scale) { +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_binaryOpVS( + JNIEnv* env, jclass, jlong lhs_view, jlong rhs_ptr, jint int_op, jint out_dtype, jint scale) +{ JNI_NULL_CHECK(env, lhs_view, "lhs is null", 0); JNI_NULL_CHECK(env, rhs_ptr, "rhs is null", 0); try { cudf::jni::auto_set_device(env); - auto lhs = reinterpret_cast(lhs_view); - cudf::scalar *rhs = reinterpret_cast(rhs_ptr); + auto lhs = reinterpret_cast(lhs_view); + cudf::scalar* rhs = reinterpret_cast(rhs_ptr); cudf::data_type n_data_type = cudf::jni::make_data_type(out_dtype, scale); - cudf::binary_operator op = static_cast(int_op); + cudf::binary_operator op = static_cast(int_op); if (lhs->type().id() == cudf::type_id::STRUCT) { auto out = make_fixed_width_column(n_data_type, lhs->size(), cudf::mask_state::UNALLOCATED); @@ -1520,10 +1652,10 @@ JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_binaryOpVS(JNIEnv *env, j out->set_null_mask(std::move(new_mask), new_null_count); } - auto rhsv = cudf::make_column_from_scalar(*rhs, 1); + auto rhsv = cudf::make_column_from_scalar(*rhs, 1); auto out_view = out->mutable_view(); cudf::binops::compiled::detail::apply_sorting_struct_binary_op( - out_view, *lhs, rhsv->view(), false, true, op, cudf::get_default_stream()); + out_view, *lhs, rhsv->view(), false, true, op, cudf::get_default_stream()); return release_as_jlong(out); } @@ -1532,233 +1664,251 @@ JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_binaryOpVS(JNIEnv *env, j CATCH_STD(env, 0); } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_substringS(JNIEnv *env, jclass, - jlong cv_handle, jint start) { +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_substringS(JNIEnv* env, + jclass, + jlong cv_handle, + jint start) +{ JNI_NULL_CHECK(env, cv_handle, "column is null", 0); try { cudf::jni::auto_set_device(env); - auto const cv = reinterpret_cast(cv_handle); + auto const cv = reinterpret_cast(cv_handle); auto const scv = cudf::strings_column_view{*cv}; return release_as_jlong(cudf::strings::slice_strings(scv, start)); } CATCH_STD(env, 0); } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_substring(JNIEnv *env, jclass, - jlong column_view, jint start, - jint end) { +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_substring( + JNIEnv* env, jclass, jlong column_view, jint start, jint end) +{ JNI_NULL_CHECK(env, column_view, "column is null", 0); try { cudf::jni::auto_set_device(env); - cudf::column_view *cv = reinterpret_cast(column_view); + cudf::column_view* cv = reinterpret_cast(column_view); cudf::strings_column_view scv(*cv); return release_as_jlong(cudf::strings::slice_strings(scv, start, end)); } CATCH_STD(env, 0); } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_substringColumn(JNIEnv *env, jclass, - jlong column_view, - jlong start_column, - jlong end_column) { +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_substringColumn( + JNIEnv* env, jclass, jlong column_view, jlong start_column, jlong end_column) +{ JNI_NULL_CHECK(env, column_view, "column is null", 0); JNI_NULL_CHECK(env, start_column, "column is null", 0); JNI_NULL_CHECK(env, end_column, "column is null", 0); try { cudf::jni::auto_set_device(env); - cudf::column_view *cv = reinterpret_cast(column_view); + cudf::column_view* cv = reinterpret_cast(column_view); cudf::strings_column_view scv(*cv); - cudf::column_view *sc = reinterpret_cast(start_column); - cudf::column_view *ec = reinterpret_cast(end_column); + cudf::column_view* sc = reinterpret_cast(start_column); + cudf::column_view* ec = reinterpret_cast(end_column); return release_as_jlong(cudf::strings::slice_strings(scv, *sc, *ec)); } CATCH_STD(env, 0); } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_substringLocate(JNIEnv *env, jclass, - jlong column_view, - jlong substring, jint start, - jint end) { +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_substringLocate( + JNIEnv* env, jclass, jlong column_view, jlong substring, jint start, jint end) +{ JNI_NULL_CHECK(env, column_view, "column is null", 0); JNI_NULL_CHECK(env, substring, "target string scalar is null", 0); try { cudf::jni::auto_set_device(env); - cudf::column_view *cv = reinterpret_cast(column_view); + cudf::column_view* cv = reinterpret_cast(column_view); cudf::strings_column_view scv(*cv); - cudf::string_scalar *ss_scalar = reinterpret_cast(substring); + cudf::string_scalar* ss_scalar = reinterpret_cast(substring); return release_as_jlong(cudf::strings::find(scv, *ss_scalar, start, end)); } CATCH_STD(env, 0); } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_stringReplace(JNIEnv *env, jclass, - jlong column_view, - jlong target, jlong replace) { +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_stringReplace( + JNIEnv* env, jclass, jlong column_view, jlong target, jlong replace) +{ JNI_NULL_CHECK(env, column_view, "column is null", 0); JNI_NULL_CHECK(env, target, "target string scalar is null", 0); JNI_NULL_CHECK(env, replace, "replace string scalar is null", 0); try { cudf::jni::auto_set_device(env); - cudf::column_view *cv = reinterpret_cast(column_view); + cudf::column_view* cv = reinterpret_cast(column_view); cudf::strings_column_view scv(*cv); - cudf::string_scalar *ss_target = reinterpret_cast(target); - cudf::string_scalar *ss_replace = reinterpret_cast(replace); + cudf::string_scalar* ss_target = reinterpret_cast(target); + cudf::string_scalar* ss_replace = reinterpret_cast(replace); return release_as_jlong(cudf::strings::replace(scv, *ss_target, *ss_replace)); } CATCH_STD(env, 0); } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_stringReplaceMulti(JNIEnv *env, jclass, - jlong inputs_cv, - jlong targets_cv, - jlong repls_cv) { +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_stringReplaceMulti( + JNIEnv* env, jclass, jlong inputs_cv, jlong targets_cv, jlong repls_cv) +{ JNI_NULL_CHECK(env, inputs_cv, "column is null", 0); JNI_NULL_CHECK(env, targets_cv, "targets string column view is null", 0); JNI_NULL_CHECK(env, repls_cv, "repls string column view is null", 0); try { cudf::jni::auto_set_device(env); - cudf::column_view *cv = reinterpret_cast(inputs_cv); + cudf::column_view* cv = reinterpret_cast(inputs_cv); cudf::strings_column_view scv(*cv); - cudf::column_view *cvtargets = reinterpret_cast(targets_cv); + cudf::column_view* cvtargets = reinterpret_cast(targets_cv); cudf::strings_column_view scvtargets(*cvtargets); - cudf::column_view *cvrepls = reinterpret_cast(repls_cv); + cudf::column_view* cvrepls = reinterpret_cast(repls_cv); cudf::strings_column_view scvrepls(*cvrepls); return release_as_jlong(cudf::strings::replace(scv, scvtargets, scvrepls)); } CATCH_STD(env, 0); } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_mapLookupForKeys(JNIEnv *env, jclass, +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_mapLookupForKeys(JNIEnv* env, + jclass, jlong map_column_view, - jlong lookup_keys) { + jlong lookup_keys) +{ JNI_NULL_CHECK(env, map_column_view, "column is null", 0); JNI_NULL_CHECK(env, lookup_keys, "lookup key is null", 0); try { cudf::jni::auto_set_device(env); - auto const *cv = reinterpret_cast(map_column_view); - auto const *column_keys = reinterpret_cast(lookup_keys); - auto const maps_view = cudf::jni::maps_column_view{*cv}; + auto const* cv = reinterpret_cast(map_column_view); + auto const* column_keys = reinterpret_cast(lookup_keys); + auto const maps_view = cudf::jni::maps_column_view{*cv}; return release_as_jlong(maps_view.get_values_for(*column_keys)); } CATCH_STD(env, 0); } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_mapLookup(JNIEnv *env, jclass, +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_mapLookup(JNIEnv* env, + jclass, jlong map_column_view, - jlong lookup_key) { + jlong lookup_key) +{ JNI_NULL_CHECK(env, map_column_view, "column is null", 0); JNI_NULL_CHECK(env, lookup_key, "lookup key is null", 0); try { cudf::jni::auto_set_device(env); - auto const *cv = reinterpret_cast(map_column_view); - auto const *scalar_key = reinterpret_cast(lookup_key); - auto const maps_view = cudf::jni::maps_column_view{*cv}; + auto const* cv = reinterpret_cast(map_column_view); + auto const* scalar_key = reinterpret_cast(lookup_key); + auto const maps_view = cudf::jni::maps_column_view{*cv}; return release_as_jlong(maps_view.get_values_for(*scalar_key)); } CATCH_STD(env, 0); } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_mapContainsKeys(JNIEnv *env, jclass, +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_mapContainsKeys(JNIEnv* env, + jclass, jlong map_column_view, - jlong lookup_keys) { + jlong lookup_keys) +{ JNI_NULL_CHECK(env, map_column_view, "column is null", 0); JNI_NULL_CHECK(env, lookup_keys, "lookup key is null", 0); try { cudf::jni::auto_set_device(env); - auto const *cv = reinterpret_cast(map_column_view); - auto const *column_key = reinterpret_cast(lookup_keys); - auto const maps_view = cudf::jni::maps_column_view{*cv}; + auto const* cv = reinterpret_cast(map_column_view); + auto const* column_key = reinterpret_cast(lookup_keys); + auto const maps_view = cudf::jni::maps_column_view{*cv}; return release_as_jlong(maps_view.contains(*column_key)); } CATCH_STD(env, 0); } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_mapContains(JNIEnv *env, jclass, +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_mapContains(JNIEnv* env, + jclass, jlong map_column_view, - jlong lookup_key) { + jlong lookup_key) +{ JNI_NULL_CHECK(env, map_column_view, "column is null", 0); JNI_NULL_CHECK(env, lookup_key, "lookup key is null", 0); try { cudf::jni::auto_set_device(env); - auto const *cv = reinterpret_cast(map_column_view); - auto const *scalar_key = reinterpret_cast(lookup_key); - auto const maps_view = cudf::jni::maps_column_view{*cv}; + auto const* cv = reinterpret_cast(map_column_view); + auto const* scalar_key = reinterpret_cast(lookup_key); + auto const maps_view = cudf::jni::maps_column_view{*cv}; return release_as_jlong(maps_view.contains(*scalar_key)); } CATCH_STD(env, 0); } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_replaceRegex( - JNIEnv *env, jclass, jlong j_column_view, jstring j_pattern, jint regex_flags, - jint capture_groups, jlong j_repl, jlong j_maxrepl) { - +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_replaceRegex(JNIEnv* env, + jclass, + jlong j_column_view, + jstring j_pattern, + jint regex_flags, + jint capture_groups, + jlong j_repl, + jlong j_maxrepl) +{ JNI_NULL_CHECK(env, j_column_view, "column is null", 0); JNI_NULL_CHECK(env, j_pattern, "pattern string is null", 0); JNI_NULL_CHECK(env, j_repl, "replace scalar is null", 0); try { cudf::jni::auto_set_device(env); - auto const cv = reinterpret_cast(j_column_view); + auto const cv = reinterpret_cast(j_column_view); auto const strings_column = cudf::strings_column_view{*cv}; - auto const pattern = cudf::jni::native_jstring(env, j_pattern); - auto const flags = static_cast(regex_flags); - auto const groups = static_cast(capture_groups); - auto const regex_prog = cudf::strings::regex_program::create(pattern.get(), flags, groups); - auto const repl = reinterpret_cast(j_repl); + auto const pattern = cudf::jni::native_jstring(env, j_pattern); + auto const flags = static_cast(regex_flags); + auto const groups = static_cast(capture_groups); + auto const regex_prog = cudf::strings::regex_program::create(pattern.get(), flags, groups); + auto const repl = reinterpret_cast(j_repl); return release_as_jlong( - cudf::strings::replace_re(strings_column, *regex_prog, *repl, j_maxrepl)); + cudf::strings::replace_re(strings_column, *regex_prog, *repl, j_maxrepl)); } CATCH_STD(env, 0); } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_replaceMultiRegex(JNIEnv *env, jclass, - jlong j_column_view, - jobjectArray j_patterns, - jlong j_repls) { - +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_replaceMultiRegex( + JNIEnv* env, jclass, jlong j_column_view, jobjectArray j_patterns, jlong j_repls) +{ JNI_NULL_CHECK(env, j_column_view, "column is null", 0); JNI_NULL_CHECK(env, j_patterns, "patterns is null", 0); JNI_NULL_CHECK(env, j_repls, "repls is null", 0); try { cudf::jni::auto_set_device(env); - auto cv = reinterpret_cast(j_column_view); + auto cv = reinterpret_cast(j_column_view); cudf::strings_column_view scv(*cv); cudf::jni::native_jstringArray patterns(env, j_patterns); - auto repl_cv = reinterpret_cast(j_repls); + auto repl_cv = reinterpret_cast(j_repls); cudf::strings_column_view repl_scv(*repl_cv); return release_as_jlong(cudf::strings::replace_re(scv, patterns.as_cpp_vector(), repl_scv)); } CATCH_STD(env, 0); } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_stringReplaceWithBackrefs( - JNIEnv *env, jclass, jlong j_column_view, jstring pattern_obj, jint regex_flags, - jint capture_groups, jstring replace_obj) { - +JNIEXPORT jlong JNICALL +Java_ai_rapids_cudf_ColumnView_stringReplaceWithBackrefs(JNIEnv* env, + jclass, + jlong j_column_view, + jstring pattern_obj, + jint regex_flags, + jint capture_groups, + jstring replace_obj) +{ JNI_NULL_CHECK(env, j_column_view, "column is null", 0); JNI_NULL_CHECK(env, pattern_obj, "pattern string is null", 0); JNI_NULL_CHECK(env, replace_obj, "replace string is null", 0); try { cudf::jni::auto_set_device(env); - auto const cv = reinterpret_cast(j_column_view); + auto const cv = reinterpret_cast(j_column_view); auto const strings_column = cudf::strings_column_view{*cv}; - auto const pattern = cudf::jni::native_jstring(env, pattern_obj); - auto const flags = static_cast(regex_flags); - auto const groups = static_cast(capture_groups); - auto const regex_prog = cudf::strings::regex_program::create(pattern.get(), flags, groups); + auto const pattern = cudf::jni::native_jstring(env, pattern_obj); + auto const flags = static_cast(regex_flags); + auto const groups = static_cast(capture_groups); + auto const regex_prog = cudf::strings::regex_program::create(pattern.get(), flags, groups); cudf::jni::native_jstring ss_replace(env, replace_obj); return release_as_jlong( - cudf::strings::replace_with_backrefs(strings_column, *regex_prog, ss_replace.get())); + cudf::strings::replace_with_backrefs(strings_column, *regex_prog, ss_replace.get())); } CATCH_STD(env, 0); } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_zfill(JNIEnv *env, jclass, jlong column_view, - jint j_width) { - +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_zfill(JNIEnv* env, + jclass, + jlong column_view, + jint j_width) +{ JNI_NULL_CHECK(env, column_view, "column is null", 0); try { cudf::jni::auto_set_device(env); - cudf::column_view *cv = reinterpret_cast(column_view); + cudf::column_view* cv = reinterpret_cast(column_view); cudf::strings_column_view scv(*cv); cudf::size_type width = reinterpret_cast(j_width); return release_as_jlong(cudf::strings::zfill(scv, width)); @@ -1766,17 +1916,16 @@ JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_zfill(JNIEnv *env, jclass CATCH_STD(env, 0); } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_pad(JNIEnv *env, jclass, jlong column_view, - jint j_width, jint j_side, - jstring fill_char) { - +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_pad( + JNIEnv* env, jclass, jlong column_view, jint j_width, jint j_side, jstring fill_char) +{ JNI_NULL_CHECK(env, column_view, "column is null", 0); JNI_NULL_CHECK(env, fill_char, "fill_char is null", 0); try { cudf::jni::auto_set_device(env); - cudf::column_view *cv = reinterpret_cast(column_view); + cudf::column_view* cv = reinterpret_cast(column_view); cudf::strings_column_view scv(*cv); - cudf::size_type width = reinterpret_cast(j_width); + cudf::size_type width = reinterpret_cast(j_width); cudf::strings::side_type side = static_cast(j_side); cudf::jni::native_jstring ss_fill(env, fill_char); return release_as_jlong(cudf::strings::pad(scv, width, side, ss_fill.get())); @@ -1784,113 +1933,125 @@ JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_pad(JNIEnv *env, jclass, CATCH_STD(env, 0); } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_stringStrip(JNIEnv *env, jclass, - jlong column_view, - jint strip_type, - jlong to_strip) { +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_stringStrip( + JNIEnv* env, jclass, jlong column_view, jint strip_type, jlong to_strip) +{ JNI_NULL_CHECK(env, column_view, "column is null", 0); JNI_NULL_CHECK(env, to_strip, "to_strip scalar is null", 0); try { cudf::jni::auto_set_device(env); - cudf::column_view *cv = reinterpret_cast(column_view); + cudf::column_view* cv = reinterpret_cast(column_view); cudf::strings_column_view scv(*cv); cudf::strings::side_type s_striptype = static_cast(strip_type); - cudf::string_scalar *ss_tostrip = reinterpret_cast(to_strip); + cudf::string_scalar* ss_tostrip = reinterpret_cast(to_strip); return release_as_jlong(cudf::strings::strip(scv, s_striptype, *ss_tostrip)); } CATCH_STD(env, 0); } -JNIEXPORT jlongArray JNICALL Java_ai_rapids_cudf_ColumnView_extractRe(JNIEnv *env, jclass, +JNIEXPORT jlongArray JNICALL Java_ai_rapids_cudf_ColumnView_extractRe(JNIEnv* env, + jclass, jlong j_view_handle, jstring pattern_obj, jint regex_flags, - jint capture_groups) { + jint capture_groups) +{ JNI_NULL_CHECK(env, j_view_handle, "column is null", nullptr); JNI_NULL_CHECK(env, pattern_obj, "pattern is null", nullptr); try { cudf::jni::auto_set_device(env); - auto const column_view = reinterpret_cast(j_view_handle); + auto const column_view = reinterpret_cast(j_view_handle); auto const strings_column = cudf::strings_column_view{*column_view}; - auto const pattern = cudf::jni::native_jstring(env, pattern_obj); - auto const flags = static_cast(regex_flags); - auto const groups = static_cast(capture_groups); - auto const regex_prog = cudf::strings::regex_program::create(pattern.get(), flags, groups); + auto const pattern = cudf::jni::native_jstring(env, pattern_obj); + auto const flags = static_cast(regex_flags); + auto const groups = static_cast(capture_groups); + auto const regex_prog = cudf::strings::regex_program::create(pattern.get(), flags, groups); return cudf::jni::convert_table_for_return(env, cudf::strings::extract(strings_column, *regex_prog)); } CATCH_STD(env, 0); } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_extractAllRecord( - JNIEnv *env, jclass, jlong j_view_handle, jstring pattern_obj, jint regex_flags, - jint capture_groups, jint idx) { +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_extractAllRecord(JNIEnv* env, + jclass, + jlong j_view_handle, + jstring pattern_obj, + jint regex_flags, + jint capture_groups, + jint idx) +{ JNI_NULL_CHECK(env, j_view_handle, "column is null", 0); JNI_NULL_CHECK(env, pattern_obj, "pattern is null", 0); try { cudf::jni::auto_set_device(env); - auto const column_view = reinterpret_cast(j_view_handle); + auto const column_view = reinterpret_cast(j_view_handle); auto const strings_column = cudf::strings_column_view{*column_view}; - auto const pattern = cudf::jni::native_jstring(env, pattern_obj); - auto const flags = static_cast(regex_flags); - auto const groups = static_cast(capture_groups); - auto const regex_prog = cudf::strings::regex_program::create(pattern.get(), flags, groups); - auto result = (idx == 0) ? cudf::strings::findall(strings_column, *regex_prog) : - cudf::strings::extract_all_record(strings_column, *regex_prog); + auto const pattern = cudf::jni::native_jstring(env, pattern_obj); + auto const flags = static_cast(regex_flags); + auto const groups = static_cast(capture_groups); + auto const regex_prog = cudf::strings::regex_program::create(pattern.get(), flags, groups); + auto result = (idx == 0) ? cudf::strings::findall(strings_column, *regex_prog) + : cudf::strings::extract_all_record(strings_column, *regex_prog); return release_as_jlong(result); } CATCH_STD(env, 0); } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_urlDecode(JNIEnv *env, jclass, - jlong j_view_handle) { +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_urlDecode(JNIEnv* env, + jclass, + jlong j_view_handle) +{ JNI_NULL_CHECK(env, j_view_handle, "column is null", 0); try { cudf::jni::auto_set_device(env); - auto view_ptr = reinterpret_cast(j_view_handle); + auto view_ptr = reinterpret_cast(j_view_handle); cudf::strings_column_view strings_view(*view_ptr); return release_as_jlong(cudf::strings::url_decode(strings_view)); } CATCH_STD(env, 0); } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_urlEncode(JNIEnv *env, jclass, - jlong j_view_handle) { +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_urlEncode(JNIEnv* env, + jclass, + jlong j_view_handle) +{ JNI_NULL_CHECK(env, j_view_handle, "column is null", 0); try { cudf::jni::auto_set_device(env); - auto view_ptr = reinterpret_cast(j_view_handle); + auto view_ptr = reinterpret_cast(j_view_handle); cudf::strings_column_view strings_view(*view_ptr); return release_as_jlong(cudf::strings::url_encode(strings_view)); } CATCH_STD(env, 0); } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_normalizeNANsAndZeros(JNIEnv *env, +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_normalizeNANsAndZeros(JNIEnv* env, jclass clazz, - jlong input_column) { + jlong input_column) +{ using cudf::column_view; JNI_NULL_CHECK(env, input_column, "Input column is null", 0); try { cudf::jni::auto_set_device(env); return release_as_jlong( - cudf::normalize_nans_and_zeros(*reinterpret_cast(input_column))); + cudf::normalize_nans_and_zeros(*reinterpret_cast(input_column))); } CATCH_STD(env, 0); } JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_bitwiseMergeAndSetValidity( - JNIEnv *env, jobject j_object, jlong base_column, jlongArray column_handles, jint bin_op) { + JNIEnv* env, jobject j_object, jlong base_column, jlongArray column_handles, jint bin_op) +{ JNI_NULL_CHECK(env, base_column, "base column native handle is null", 0); JNI_NULL_CHECK(env, column_handles, "array of column handles is null", 0); try { cudf::jni::auto_set_device(env); - cudf::column_view *original_column = reinterpret_cast(base_column); + cudf::column_view* original_column = reinterpret_cast(base_column); std::unique_ptr copy(new cudf::column(*original_column)); cudf::jni::native_jpointerArray n_cudf_columns(env, column_handles); @@ -1904,7 +2065,7 @@ JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_bitwiseMergeAndSetValidit case cudf::binary_operator::BITWISE_AND: { auto cols = n_cudf_columns.get_dereferenced(); cols.push_back(copy->view()); - auto table_view = cudf::table_view{cols}; + auto table_view = cudf::table_view{cols}; auto [new_bitmask, null_count] = cudf::bitmask_and(table_view); copy->set_null_mask(std::move(new_bitmask), null_count); break; @@ -1922,9 +2083,7 @@ JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_bitwiseMergeAndSetValidit default: JNI_THROW_NEW(env, cudf::jni::ILLEGAL_ARG_CLASS, "Unsupported merge operation", 0); } auto const copy_cv = copy->view(); - if (cudf::has_nonempty_nulls(copy_cv)) { - copy = cudf::purge_nonempty_nulls(copy_cv); - } + if (cudf::has_nonempty_nulls(copy_cv)) { copy = cudf::purge_nonempty_nulls(copy_cv); } return release_as_jlong(copy); } @@ -1932,15 +2091,16 @@ JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_bitwiseMergeAndSetValidit } JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_copyWithBooleanColumnAsValidity( - JNIEnv *env, jobject j_object, jlong exemplar_handle, jlong validity_column_handle) { + JNIEnv* env, jobject j_object, jlong exemplar_handle, jlong validity_column_handle) +{ JNI_NULL_CHECK(env, exemplar_handle, "ColumnView handle is null", 0); JNI_NULL_CHECK(env, validity_column_handle, "Validity column handle is null", 0); try { cudf::jni::auto_set_device(env); - auto const exemplar = *reinterpret_cast(exemplar_handle); - auto const validity = *reinterpret_cast(validity_column_handle); + auto const exemplar = *reinterpret_cast(exemplar_handle); + auto const validity = *reinterpret_cast(validity_column_handle); return release_as_jlong( - cudf::jni::new_column_with_boolean_column_as_validity(exemplar, validity)); + cudf::jni::new_column_with_boolean_column_as_validity(exemplar, validity)); } CATCH_STD(env, 0); } @@ -1950,23 +2110,29 @@ JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_copyWithBooleanColumnAsVa // should typically only be called from the CudfColumn inner class. //////// -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_makeCudfColumnView( - JNIEnv *env, jclass, jint j_type, jint scale, jlong j_data, jlong j_data_size, jlong j_offset, - jlong j_valid, jint j_null_count, jint size, jlongArray j_children) { - +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_makeCudfColumnView(JNIEnv* env, + jclass, + jint j_type, + jint scale, + jlong j_data, + jlong j_data_size, + jlong j_offset, + jlong j_valid, + jint j_null_count, + jint size, + jlongArray j_children) +{ try { using cudf::column_view; cudf::jni::auto_set_device(env); - cudf::type_id n_type = static_cast(j_type); + cudf::type_id n_type = static_cast(j_type); cudf::data_type n_data_type = cudf::jni::make_data_type(j_type, scale); - void *data = reinterpret_cast(j_data); - cudf::bitmask_type *valid = reinterpret_cast(j_valid); - if (valid == nullptr) { - j_null_count = 0; - } + void* data = reinterpret_cast(j_data); + cudf::bitmask_type* valid = reinterpret_cast(j_valid); + if (valid == nullptr) { j_null_count = 0; } - if (j_null_count < 0) { // Check for unknown null count. + if (j_null_count < 0) { // Check for unknown null count. // Calculate concrete null count. j_null_count = cudf::null_count(valid, 0, size); } @@ -1974,37 +2140,51 @@ JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_makeCudfColumnView( if (n_type == cudf::type_id::STRING) { if (size == 0) { return ptr_as_jlong( - new cudf::column_view(cudf::data_type{cudf::type_id::STRING}, 0, nullptr, nullptr, 0)); + new cudf::column_view(cudf::data_type{cudf::type_id::STRING}, 0, nullptr, nullptr, 0)); } else { JNI_NULL_CHECK(env, j_offset, "offset is null", 0); - cudf::size_type *offsets = reinterpret_cast(j_offset); - cudf::column_view offsets_column(cudf::data_type{cudf::type_id::INT32}, size + 1, offsets, - nullptr, 0); - return ptr_as_jlong(new cudf::column_view(cudf::data_type{cudf::type_id::STRING}, size, - data, valid, j_null_count, 0, {offsets_column})); + cudf::size_type* offsets = reinterpret_cast(j_offset); + cudf::column_view offsets_column( + cudf::data_type{cudf::type_id::INT32}, size + 1, offsets, nullptr, 0); + return ptr_as_jlong(new cudf::column_view(cudf::data_type{cudf::type_id::STRING}, + size, + data, + valid, + j_null_count, + 0, + {offsets_column})); } } else if (n_type == cudf::type_id::LIST) { JNI_NULL_CHECK(env, j_children, "children of a list are null", 0); cudf::jni::native_jpointerArray children(env, j_children); JNI_ARG_CHECK(env, (children.size() == 1), "LIST children size is not 1", 0); cudf::size_type offsets_size = 0; - cudf::size_type *offsets = nullptr; + cudf::size_type* offsets = nullptr; if (size != 0) { JNI_NULL_CHECK(env, j_offset, "offset is null", 0); offsets_size = size + 1; - offsets = reinterpret_cast(j_offset); + offsets = reinterpret_cast(j_offset); } - cudf::column_view offsets_column(cudf::data_type{cudf::type_id::INT32}, offsets_size, offsets, - nullptr, 0); - return ptr_as_jlong(new cudf::column_view(cudf::data_type{cudf::type_id::LIST}, size, nullptr, - valid, j_null_count, 0, + cudf::column_view offsets_column( + cudf::data_type{cudf::type_id::INT32}, offsets_size, offsets, nullptr, 0); + return ptr_as_jlong(new cudf::column_view(cudf::data_type{cudf::type_id::LIST}, + size, + nullptr, + valid, + j_null_count, + 0, {offsets_column, *children[0]})); } else if (n_type == cudf::type_id::STRUCT) { JNI_NULL_CHECK(env, j_children, "children of a struct are null", 0); cudf::jni::native_jpointerArray children(env, j_children); std::vector children_vector = children.get_dereferenced(); - return ptr_as_jlong(new cudf::column_view(cudf::data_type{cudf::type_id::STRUCT}, size, - nullptr, valid, j_null_count, 0, children_vector)); + return ptr_as_jlong(new cudf::column_view(cudf::data_type{cudf::type_id::STRUCT}, + size, + nullptr, + valid, + j_null_count, + 0, + children_vector)); } else { return ptr_as_jlong(new cudf::column_view(n_data_type, size, data, valid, j_null_count)); } @@ -2012,69 +2192,79 @@ JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_makeCudfColumnView( CATCH_STD(env, 0); } -JNIEXPORT jint JNICALL Java_ai_rapids_cudf_ColumnView_getNativeTypeId(JNIEnv *env, jobject j_object, - jlong handle) { +JNIEXPORT jint JNICALL Java_ai_rapids_cudf_ColumnView_getNativeTypeId(JNIEnv* env, + jobject j_object, + jlong handle) +{ JNI_NULL_CHECK(env, handle, "native handle is null", 0); try { cudf::jni::auto_set_device(env); - cudf::column_view *column = reinterpret_cast(handle); + cudf::column_view* column = reinterpret_cast(handle); return static_cast(column->type().id()); } CATCH_STD(env, 0); } -JNIEXPORT jint JNICALL Java_ai_rapids_cudf_ColumnView_getNativeTypeScale(JNIEnv *env, jclass, - jlong handle) { +JNIEXPORT jint JNICALL Java_ai_rapids_cudf_ColumnView_getNativeTypeScale(JNIEnv* env, + jclass, + jlong handle) +{ JNI_NULL_CHECK(env, handle, "native handle is null", 0); try { cudf::jni::auto_set_device(env); - cudf::column_view *column = reinterpret_cast(handle); + cudf::column_view* column = reinterpret_cast(handle); return column->type().scale(); } CATCH_STD(env, 0); } -JNIEXPORT jint JNICALL Java_ai_rapids_cudf_ColumnView_getNativeRowCount(JNIEnv *env, jclass, - jlong handle) { +JNIEXPORT jint JNICALL Java_ai_rapids_cudf_ColumnView_getNativeRowCount(JNIEnv* env, + jclass, + jlong handle) +{ JNI_NULL_CHECK(env, handle, "native handle is null", 0); try { cudf::jni::auto_set_device(env); - cudf::column_view *column = reinterpret_cast(handle); + cudf::column_view* column = reinterpret_cast(handle); return static_cast(column->size()); } CATCH_STD(env, 0); } -JNIEXPORT jint JNICALL Java_ai_rapids_cudf_ColumnView_getNativeNullCount(JNIEnv *env, +JNIEXPORT jint JNICALL Java_ai_rapids_cudf_ColumnView_getNativeNullCount(JNIEnv* env, jobject j_object, - jlong handle) { + jlong handle) +{ JNI_NULL_CHECK(env, handle, "native handle is null", 0); try { cudf::jni::auto_set_device(env); - cudf::column_view *column = reinterpret_cast(handle); + cudf::column_view* column = reinterpret_cast(handle); return static_cast(column->null_count()); } CATCH_STD(env, 0); } -JNIEXPORT void JNICALL Java_ai_rapids_cudf_ColumnView_deleteColumnView(JNIEnv *env, +JNIEXPORT void JNICALL Java_ai_rapids_cudf_ColumnView_deleteColumnView(JNIEnv* env, jobject j_object, - jlong handle) { + jlong handle) +{ try { cudf::jni::auto_set_device(env); - cudf::column_view *view = reinterpret_cast(handle); + cudf::column_view* view = reinterpret_cast(handle); delete view; } CATCH_STD(env, ); } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_getNativeDataAddress(JNIEnv *env, jclass, - jlong handle) { +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_getNativeDataAddress(JNIEnv* env, + jclass, + jlong handle) +{ JNI_NULL_CHECK(env, handle, "native handle is null", 0); try { cudf::jni::auto_set_device(env); - jlong result = 0; - cudf::column_view *column = reinterpret_cast(handle); + jlong result = 0; + cudf::column_view* column = reinterpret_cast(handle); if (column->type().id() == cudf::type_id::STRING) { if (column->size() > 0) { cudf::strings_column_view view = cudf::strings_column_view(*column); @@ -2089,17 +2279,19 @@ JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_getNativeDataAddress(JNIE CATCH_STD(env, 0); } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_getNativeDataLength(JNIEnv *env, jclass, - jlong handle) { +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_getNativeDataLength(JNIEnv* env, + jclass, + jlong handle) +{ JNI_NULL_CHECK(env, handle, "native handle is null", 0); try { cudf::jni::auto_set_device(env); - jlong result = 0; - cudf::column_view *column = reinterpret_cast(handle); + jlong result = 0; + cudf::column_view* column = reinterpret_cast(handle); if (column->type().id() == cudf::type_id::STRING) { if (column->size() > 0) { cudf::strings_column_view view = cudf::strings_column_view(*column); - result = view.chars_size(cudf::get_default_stream()); + result = view.chars_size(cudf::get_default_stream()); } } else if (column->type().id() != cudf::type_id::LIST && column->type().id() != cudf::type_id::STRUCT) { @@ -2110,14 +2302,14 @@ JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_getNativeDataLength(JNIEn CATCH_STD(env, 0); } -JNIEXPORT jint JNICALL Java_ai_rapids_cudf_ColumnView_getNativeNumChildren(JNIEnv *env, +JNIEXPORT jint JNICALL Java_ai_rapids_cudf_ColumnView_getNativeNumChildren(JNIEnv* env, jobject j_object, - jlong handle) { - + jlong handle) +{ JNI_NULL_CHECK(env, handle, "native handle is null", 0); try { cudf::jni::auto_set_device(env); - cudf::column_view *column = reinterpret_cast(handle); + cudf::column_view* column = reinterpret_cast(handle); // Strings has children(offsets and chars) but not a nested child() we care about here. if (column->type().id() == cudf::type_id::STRING) { return 0; @@ -2133,53 +2325,57 @@ JNIEXPORT jint JNICALL Java_ai_rapids_cudf_ColumnView_getNativeNumChildren(JNIEn CATCH_STD(env, 0); } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_getChildCvPointer(JNIEnv *env, +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_getChildCvPointer(JNIEnv* env, jobject j_object, jlong handle, - jint child_index) { + jint child_index) +{ JNI_NULL_CHECK(env, handle, "native handle is null", 0); try { cudf::jni::auto_set_device(env); - cudf::column_view *column = reinterpret_cast(handle); - auto const is_list = column->type().id() == cudf::type_id::LIST; - auto const child = column->child(child_index + (is_list ? 1 : 0)); + cudf::column_view* column = reinterpret_cast(handle); + auto const is_list = column->type().id() == cudf::type_id::LIST; + auto const child = column->child(child_index + (is_list ? 1 : 0)); return ptr_as_jlong(new cudf::column_view(child)); } CATCH_STD(env, 0); } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_getListOffsetCvPointer(JNIEnv *env, +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_getListOffsetCvPointer(JNIEnv* env, jobject j_object, - jlong handle) { + jlong handle) +{ JNI_NULL_CHECK(env, handle, "native handle is null", 0); try { cudf::jni::auto_set_device(env); - cudf::column_view *column = reinterpret_cast(handle); - cudf::lists_column_view view = cudf::lists_column_view(*column); + cudf::column_view* column = reinterpret_cast(handle); + cudf::lists_column_view view = cudf::lists_column_view(*column); cudf::column_view offsets_view = view.offsets(); return ptr_as_jlong(new cudf::column_view(offsets_view)); } CATCH_STD(env, 0); } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_getNativeOffsetsAddress(JNIEnv *env, jclass, - jlong handle) { +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_getNativeOffsetsAddress(JNIEnv* env, + jclass, + jlong handle) +{ JNI_NULL_CHECK(env, handle, "native handle is null", 0); try { cudf::jni::auto_set_device(env); - jlong result = 0; - cudf::column_view *column = reinterpret_cast(handle); + jlong result = 0; + cudf::column_view* column = reinterpret_cast(handle); if (column->type().id() == cudf::type_id::STRING) { if (column->size() > 0) { cudf::strings_column_view view = cudf::strings_column_view(*column); cudf::column_view offsets_view = view.offsets(); - result = ptr_as_jlong(offsets_view.data()); + result = ptr_as_jlong(offsets_view.data()); } } else if (column->type().id() == cudf::type_id::LIST) { if (column->size() > 0) { - cudf::lists_column_view view = cudf::lists_column_view(*column); + cudf::lists_column_view view = cudf::lists_column_view(*column); cudf::column_view offsets_view = view.offsets(); - result = ptr_as_jlong(offsets_view.data()); + result = ptr_as_jlong(offsets_view.data()); } } return result; @@ -2187,24 +2383,26 @@ JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_getNativeOffsetsAddress(J CATCH_STD(env, 0); } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_getNativeOffsetsLength(JNIEnv *env, jclass, - jlong handle) { +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_getNativeOffsetsLength(JNIEnv* env, + jclass, + jlong handle) +{ JNI_NULL_CHECK(env, handle, "native handle is null", 0); try { cudf::jni::auto_set_device(env); - jlong result = 0; - cudf::column_view *column = reinterpret_cast(handle); + jlong result = 0; + cudf::column_view* column = reinterpret_cast(handle); if (column->type().id() == cudf::type_id::STRING) { if (column->size() > 0) { cudf::strings_column_view view = cudf::strings_column_view(*column); cudf::column_view offsets_view = view.offsets(); - result = sizeof(int) * offsets_view.size(); + result = sizeof(int) * offsets_view.size(); } } else if (column->type().id() == cudf::type_id::LIST) { if (column->size() > 0) { - cudf::lists_column_view view = cudf::lists_column_view(*column); + cudf::lists_column_view view = cudf::lists_column_view(*column); cudf::column_view offsets_view = view.offsets(); - result = sizeof(int) * offsets_view.size(); + result = sizeof(int) * offsets_view.size(); } } return result; @@ -2212,24 +2410,28 @@ JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_getNativeOffsetsLength(JN CATCH_STD(env, 0); } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_getNativeValidityAddress(JNIEnv *env, jclass, - jlong handle) { +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_getNativeValidityAddress(JNIEnv* env, + jclass, + jlong handle) +{ JNI_NULL_CHECK(env, handle, "native handle is null", 0); try { cudf::jni::auto_set_device(env); - cudf::column_view *column = reinterpret_cast(handle); + cudf::column_view* column = reinterpret_cast(handle); return ptr_as_jlong(column->null_mask()); } CATCH_STD(env, 0); } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_getNativeValidityLength(JNIEnv *env, jclass, - jlong handle) { +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_getNativeValidityLength(JNIEnv* env, + jclass, + jlong handle) +{ JNI_NULL_CHECK(env, handle, "native handle is null", 0); try { cudf::jni::auto_set_device(env); - cudf::column_view *column = reinterpret_cast(handle); - jlong result = 0; + cudf::column_view* column = reinterpret_cast(handle); + jlong result = 0; if (column->null_mask() != nullptr) { result = cudf::bitmask_allocation_size_bytes(column->size()); } @@ -2238,28 +2440,33 @@ JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_getNativeValidityLength(J CATCH_STD(env, 0); } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_getDeviceMemorySize(JNIEnv *env, jclass, +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_getDeviceMemorySize(JNIEnv* env, + jclass, jlong handle, - jboolean pad_for_cpu) { + jboolean pad_for_cpu) +{ JNI_NULL_CHECK(env, handle, "native handle is null", 0); try { cudf::jni::auto_set_device(env); - auto view = reinterpret_cast(handle); + auto view = reinterpret_cast(handle); return calc_device_memory_size(*view, pad_for_cpu); } CATCH_STD(env, 0); } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_hostPaddingSizeInBytes(JNIEnv *env, jclass) { +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_hostPaddingSizeInBytes(JNIEnv* env, jclass) +{ return sizeof(std::max_align_t); } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_clamper(JNIEnv *env, jobject j_object, - jlong handle, jlong j_lo_scalar, +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_clamper(JNIEnv* env, + jobject j_object, + jlong handle, + jlong j_lo_scalar, jlong j_lo_replace_scalar, jlong j_hi_scalar, - jlong j_hi_replace_scalar) { - + jlong j_hi_replace_scalar) +{ JNI_NULL_CHECK(env, handle, "native view handle is null", 0) JNI_NULL_CHECK(env, j_lo_scalar, "lo scalar is null", 0) JNI_NULL_CHECK(env, j_lo_replace_scalar, "lo scalar replace value is null", 0) @@ -2268,96 +2475,103 @@ JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_clamper(JNIEnv *env, jobj using cudf::clamp; try { cudf::jni::auto_set_device(env); - cudf::column_view *column_view = reinterpret_cast(handle); - cudf::scalar *lo_scalar = reinterpret_cast(j_lo_scalar); - cudf::scalar *lo_replace_scalar = reinterpret_cast(j_lo_replace_scalar); - cudf::scalar *hi_scalar = reinterpret_cast(j_hi_scalar); - cudf::scalar *hi_replace_scalar = reinterpret_cast(j_hi_replace_scalar); + cudf::column_view* column_view = reinterpret_cast(handle); + cudf::scalar* lo_scalar = reinterpret_cast(j_lo_scalar); + cudf::scalar* lo_replace_scalar = reinterpret_cast(j_lo_replace_scalar); + cudf::scalar* hi_scalar = reinterpret_cast(j_hi_scalar); + cudf::scalar* hi_replace_scalar = reinterpret_cast(j_hi_replace_scalar); return release_as_jlong( - clamp(*column_view, *lo_scalar, *lo_replace_scalar, *hi_scalar, *hi_replace_scalar)); + clamp(*column_view, *lo_scalar, *lo_replace_scalar, *hi_scalar, *hi_replace_scalar)); } CATCH_STD(env, 0); } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_title(JNIEnv *env, jobject j_object, - jlong handle) { - +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_title(JNIEnv* env, + jobject j_object, + jlong handle) +{ JNI_NULL_CHECK(env, handle, "native view handle is null", 0) try { cudf::jni::auto_set_device(env); - cudf::column_view *view = reinterpret_cast(handle); + cudf::column_view* view = reinterpret_cast(handle); return release_as_jlong(cudf::strings::title(*view)); } CATCH_STD(env, 0); } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_capitalize(JNIEnv *env, jobject j_object, +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_capitalize(JNIEnv* env, + jobject j_object, jlong strs_handle, - jlong delimiters_handle) { - + jlong delimiters_handle) +{ JNI_NULL_CHECK(env, strs_handle, "native view handle is null", 0) JNI_NULL_CHECK(env, delimiters_handle, "delimiters scalar handle is null", 0) try { cudf::jni::auto_set_device(env); - cudf::column_view *view = reinterpret_cast(strs_handle); - cudf::string_scalar *deli = reinterpret_cast(delimiters_handle); + cudf::column_view* view = reinterpret_cast(strs_handle); + cudf::string_scalar* deli = reinterpret_cast(delimiters_handle); return release_as_jlong(cudf::strings::capitalize(*view, *deli)); } CATCH_STD(env, 0); } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_joinStrings(JNIEnv *env, jobject j_object, - jlong strs_handle, - jlong separator_handle, - jlong narep_handle) { - +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_joinStrings( + JNIEnv* env, jobject j_object, jlong strs_handle, jlong separator_handle, jlong narep_handle) +{ JNI_NULL_CHECK(env, strs_handle, "native view handle is null", 0) JNI_NULL_CHECK(env, separator_handle, "separator scalar handle is null", 0) JNI_NULL_CHECK(env, narep_handle, "narep scalar handle is null", 0) try { cudf::jni::auto_set_device(env); - cudf::column_view *view = reinterpret_cast(strs_handle); - cudf::string_scalar *sep = reinterpret_cast(separator_handle); - cudf::string_scalar *narep = reinterpret_cast(narep_handle); + cudf::column_view* view = reinterpret_cast(strs_handle); + cudf::string_scalar* sep = reinterpret_cast(separator_handle); + cudf::string_scalar* narep = reinterpret_cast(narep_handle); return release_as_jlong(cudf::strings::join_strings(*view, *sep, *narep)); } CATCH_STD(env, 0); } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_makeStructView(JNIEnv *env, jobject j_object, +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_makeStructView(JNIEnv* env, + jobject j_object, jlongArray handles, - jlong row_count) { - + jlong row_count) +{ JNI_NULL_CHECK(env, handles, "native view handles are null", 0) try { cudf::jni::auto_set_device(env); - auto children = cudf::jni::native_jpointerArray{env, handles}; + auto children = cudf::jni::native_jpointerArray{env, handles}; auto children_vector = children.get_dereferenced(); - return ptr_as_jlong(new cudf::column_view(cudf::data_type{cudf::type_id::STRUCT}, row_count, - nullptr, nullptr, 0, 0, children_vector)); + return ptr_as_jlong(new cudf::column_view( + cudf::data_type{cudf::type_id::STRUCT}, row_count, nullptr, nullptr, 0, 0, children_vector)); } CATCH_STD(env, 0); } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_nansToNulls(JNIEnv *env, jobject j_object, - jlong handle) { - +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_nansToNulls(JNIEnv* env, + jobject j_object, + jlong handle) +{ JNI_NULL_CHECK(env, handle, "native view handle is null", 0) try { cudf::jni::auto_set_device(env); - auto const input = *reinterpret_cast(handle); + auto const input = *reinterpret_cast(handle); // get a new null mask by setting all the nans to null auto [new_nullmask, new_null_count] = cudf::nans_to_nulls(input); // create a column_view which is a no-copy wrapper around the original column without the null // mask - auto const input_without_nullmask = cudf::column_view( - input.type(), input.size(), input.head(), nullptr, 0, input.offset(), - std::vector{input.child_begin(), input.child_end()}); + auto const input_without_nullmask = + cudf::column_view(input.type(), + input.size(), + input.head(), + nullptr, + 0, + input.offset(), + std::vector{input.child_begin(), input.child_end()}); // create a column by deep copying `input_without_nullmask`. auto deep_copy = std::make_unique(input_without_nullmask); deep_copy->set_null_mask(std::move(*new_nullmask), new_null_count); @@ -2366,99 +2580,106 @@ JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_nansToNulls(JNIEnv *env, CATCH_STD(env, 0) } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_isFloat(JNIEnv *env, jobject j_object, - jlong handle) { - +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_isFloat(JNIEnv* env, + jobject j_object, + jlong handle) +{ JNI_NULL_CHECK(env, handle, "native view handle is null", 0) try { cudf::jni::auto_set_device(env); - cudf::column_view *view = reinterpret_cast(handle); + cudf::column_view* view = reinterpret_cast(handle); return release_as_jlong(cudf::strings::is_float(*view)); } CATCH_STD(env, 0) } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_isInteger(JNIEnv *env, jobject j_object, - jlong handle) { - +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_isInteger(JNIEnv* env, + jobject j_object, + jlong handle) +{ JNI_NULL_CHECK(env, handle, "native view handle is null", 0) try { cudf::jni::auto_set_device(env); - cudf::column_view *view = reinterpret_cast(handle); + cudf::column_view* view = reinterpret_cast(handle); return release_as_jlong(cudf::strings::is_integer(*view)); } CATCH_STD(env, 0) } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_isFixedPoint(JNIEnv *env, jobject, - jlong handle, jint j_dtype, - jint scale) { - +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_isFixedPoint( + JNIEnv* env, jobject, jlong handle, jint j_dtype, jint scale) +{ JNI_NULL_CHECK(env, handle, "native view handle is null", 0) try { cudf::jni::auto_set_device(env); - cudf::column_view *view = reinterpret_cast(handle); + cudf::column_view* view = reinterpret_cast(handle); cudf::data_type fp_dtype = cudf::jni::make_data_type(j_dtype, scale); return release_as_jlong(cudf::strings::is_fixed_point(*view, fp_dtype)); } CATCH_STD(env, 0) } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_isIntegerWithType(JNIEnv *env, jobject, - jlong handle, jint j_dtype, - jint scale) { - +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_isIntegerWithType( + JNIEnv* env, jobject, jlong handle, jint j_dtype, jint scale) +{ JNI_NULL_CHECK(env, handle, "native view handle is null", 0) try { cudf::jni::auto_set_device(env); - cudf::column_view *view = reinterpret_cast(handle); + cudf::column_view* view = reinterpret_cast(handle); cudf::data_type int_dtype = cudf::jni::make_data_type(j_dtype, scale); return release_as_jlong(cudf::strings::is_integer(*view, int_dtype)); } CATCH_STD(env, 0) } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_copyColumnViewToCV(JNIEnv *env, +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_copyColumnViewToCV(JNIEnv* env, jobject j_object, - jlong handle) { - + jlong handle) +{ JNI_NULL_CHECK(env, handle, "native view handle is null", 0) try { cudf::jni::auto_set_device(env); - cudf::column_view *view = reinterpret_cast(handle); + cudf::column_view* view = reinterpret_cast(handle); return ptr_as_jlong(new cudf::column(*view)); } CATCH_STD(env, 0) } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_getJSONObject( - JNIEnv *env, jclass, jlong j_view_handle, jlong j_scalar_handle, jboolean allow_single_quotes, - jboolean strip_quotes_from_single_strings, jboolean missing_fields_as_nulls) { - +JNIEXPORT jlong JNICALL +Java_ai_rapids_cudf_ColumnView_getJSONObject(JNIEnv* env, + jclass, + jlong j_view_handle, + jlong j_scalar_handle, + jboolean allow_single_quotes, + jboolean strip_quotes_from_single_strings, + jboolean missing_fields_as_nulls) +{ JNI_NULL_CHECK(env, j_view_handle, "view cannot be null", 0); JNI_NULL_CHECK(env, j_scalar_handle, "path cannot be null", 0); try { cudf::jni::auto_set_device(env); - cudf::column_view *n_column_view = reinterpret_cast(j_view_handle); + cudf::column_view* n_column_view = reinterpret_cast(j_view_handle); cudf::strings_column_view n_strings_col_view(*n_column_view); - cudf::string_scalar *n_scalar_path = reinterpret_cast(j_scalar_handle); - auto options = cudf::get_json_object_options{}; + cudf::string_scalar* n_scalar_path = reinterpret_cast(j_scalar_handle); + auto options = cudf::get_json_object_options{}; options.set_allow_single_quotes(allow_single_quotes); options.set_strip_quotes_from_single_strings(strip_quotes_from_single_strings); options.set_missing_fields_as_nulls(missing_fields_as_nulls); auto result_col_ptr = [&]() { try { return cudf::get_json_object(n_strings_col_view, *n_scalar_path, options); - } catch (std::invalid_argument const &err) { + } catch (std::invalid_argument const& err) { auto const null_scalar = cudf::string_scalar(std::string(""), false); return cudf::make_column_from_scalar(null_scalar, n_strings_col_view.size()); - } catch (...) { throw; } + } catch (...) { + throw; + } }(); return release_as_jlong(result_col_ptr); } @@ -2466,64 +2687,82 @@ JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_getJSONObject( } JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_stringConcatenationListElementsSepCol( - JNIEnv *env, jclass, jlong column_handle, jlong sep_handle, jlong separator_narep, - jlong col_narep, jboolean separate_nulls, jboolean empty_string_output_if_empty_list) { + JNIEnv* env, + jclass, + jlong column_handle, + jlong sep_handle, + jlong separator_narep, + jlong col_narep, + jboolean separate_nulls, + jboolean empty_string_output_if_empty_list) +{ JNI_NULL_CHECK(env, column_handle, "column handle is null", 0); JNI_NULL_CHECK(env, sep_handle, "separator column handle is null", 0); JNI_NULL_CHECK(env, separator_narep, "separator narep string scalar object is null", 0); JNI_NULL_CHECK(env, col_narep, "column narep string scalar object is null", 0); try { cudf::jni::auto_set_device(env); - const auto &separator_narep_scalar = *reinterpret_cast(separator_narep); - const auto &col_narep_scalar = *reinterpret_cast(col_narep); - auto null_policy = separate_nulls ? cudf::strings::separator_on_nulls::YES : - cudf::strings::separator_on_nulls::NO; - auto empty_list_output = empty_string_output_if_empty_list ? - cudf::strings::output_if_empty_list::EMPTY_STRING : - cudf::strings::output_if_empty_list::NULL_ELEMENT; + const auto& separator_narep_scalar = *reinterpret_cast(separator_narep); + const auto& col_narep_scalar = *reinterpret_cast(col_narep); + auto null_policy = separate_nulls ? cudf::strings::separator_on_nulls::YES + : cudf::strings::separator_on_nulls::NO; + auto empty_list_output = empty_string_output_if_empty_list + ? cudf::strings::output_if_empty_list::EMPTY_STRING + : cudf::strings::output_if_empty_list::NULL_ELEMENT; - cudf::column_view *column = reinterpret_cast(sep_handle); + cudf::column_view* column = reinterpret_cast(sep_handle); cudf::strings_column_view strings_column(*column); - cudf::column_view *cv = reinterpret_cast(column_handle); + cudf::column_view* cv = reinterpret_cast(column_handle); cudf::lists_column_view lcv(*cv); - return release_as_jlong( - cudf::strings::join_list_elements(lcv, strings_column, separator_narep_scalar, - col_narep_scalar, null_policy, empty_list_output)); + return release_as_jlong(cudf::strings::join_list_elements(lcv, + strings_column, + separator_narep_scalar, + col_narep_scalar, + null_policy, + empty_list_output)); } CATCH_STD(env, 0); } JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_stringConcatenationListElements( - JNIEnv *env, jclass, jlong column_handle, jlong separator, jlong narep, jboolean separate_nulls, - jboolean empty_string_output_if_empty_list) { + JNIEnv* env, + jclass, + jlong column_handle, + jlong separator, + jlong narep, + jboolean separate_nulls, + jboolean empty_string_output_if_empty_list) +{ JNI_NULL_CHECK(env, column_handle, "column handle is null", 0); JNI_NULL_CHECK(env, separator, "separator string scalar object is null", 0); JNI_NULL_CHECK(env, narep, "separator narep string scalar object is null", 0); try { cudf::jni::auto_set_device(env); - const auto &separator_scalar = *reinterpret_cast(separator); - const auto &narep_scalar = *reinterpret_cast(narep); - auto null_policy = separate_nulls ? cudf::strings::separator_on_nulls::YES : - cudf::strings::separator_on_nulls::NO; - auto empty_list_output = empty_string_output_if_empty_list ? - cudf::strings::output_if_empty_list::EMPTY_STRING : - cudf::strings::output_if_empty_list::NULL_ELEMENT; + const auto& separator_scalar = *reinterpret_cast(separator); + const auto& narep_scalar = *reinterpret_cast(narep); + auto null_policy = separate_nulls ? cudf::strings::separator_on_nulls::YES + : cudf::strings::separator_on_nulls::NO; + auto empty_list_output = empty_string_output_if_empty_list + ? cudf::strings::output_if_empty_list::EMPTY_STRING + : cudf::strings::output_if_empty_list::NULL_ELEMENT; - cudf::column_view *cv = reinterpret_cast(column_handle); + cudf::column_view* cv = reinterpret_cast(column_handle); cudf::lists_column_view lcv(*cv); - return release_as_jlong(cudf::strings::join_list_elements(lcv, separator_scalar, narep_scalar, - null_policy, empty_list_output)); + return release_as_jlong(cudf::strings::join_list_elements( + lcv, separator_scalar, narep_scalar, null_policy, empty_list_output)); } CATCH_STD(env, 0); } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_repeatStrings(JNIEnv *env, jclass, +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_repeatStrings(JNIEnv* env, + jclass, jlong strings_handle, - jint repeat_times) { + jint repeat_times) +{ JNI_NULL_CHECK(env, strings_handle, "strings_handle is null", 0); try { cudf::jni::auto_set_device(env); - auto const cv = *reinterpret_cast(strings_handle); + auto const cv = *reinterpret_cast(strings_handle); auto const strs_col = cudf::strings_column_view(cv); return release_as_jlong(cudf::strings::repeat_strings(strs_col, repeat_times)); } @@ -2531,69 +2770,76 @@ JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_repeatStrings(JNIEnv *env } JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_repeatStringsWithColumnRepeatTimes( - JNIEnv *env, jclass, jlong strings_handle, jlong repeat_times_handle) { + JNIEnv* env, jclass, jlong strings_handle, jlong repeat_times_handle) +{ JNI_NULL_CHECK(env, strings_handle, "strings_handle is null", 0); JNI_NULL_CHECK(env, repeat_times_handle, "repeat_times_handle is null", 0); try { cudf::jni::auto_set_device(env); - auto const strings_cv = *reinterpret_cast(strings_handle); - auto const strs_col = cudf::strings_column_view(strings_cv); - auto const repeat_times_cv = *reinterpret_cast(repeat_times_handle); + auto const strings_cv = *reinterpret_cast(strings_handle); + auto const strs_col = cudf::strings_column_view(strings_cv); + auto const repeat_times_cv = *reinterpret_cast(repeat_times_handle); return release_as_jlong(cudf::strings::repeat_strings(strs_col, repeat_times_cv)); } CATCH_STD(env, 0); } JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_applyBooleanMask( - JNIEnv *env, jclass, jlong list_column_handle, jlong boolean_mask_list_column_handle) { + JNIEnv* env, jclass, jlong list_column_handle, jlong boolean_mask_list_column_handle) +{ JNI_NULL_CHECK(env, list_column_handle, "list handle is null", 0); JNI_NULL_CHECK(env, boolean_mask_list_column_handle, "boolean mask handle is null", 0); try { cudf::jni::auto_set_device(env); - cudf::column_view const *list_column = - reinterpret_cast(list_column_handle); + cudf::column_view const* list_column = + reinterpret_cast(list_column_handle); cudf::lists_column_view const list_view = cudf::lists_column_view(*list_column); - cudf::column_view const *boolean_mask_list_column = - reinterpret_cast(boolean_mask_list_column_handle); + cudf::column_view const* boolean_mask_list_column = + reinterpret_cast(boolean_mask_list_column_handle); cudf::lists_column_view const boolean_mask_list_view = - cudf::lists_column_view(*boolean_mask_list_column); + cudf::lists_column_view(*boolean_mask_list_column); return release_as_jlong(cudf::lists::apply_boolean_mask(list_view, boolean_mask_list_view)); } CATCH_STD(env, 0); } -JNIEXPORT jboolean JNICALL -Java_ai_rapids_cudf_ColumnView_hasNonEmptyNulls(JNIEnv *env, jclass, jlong column_view_handle) { +JNIEXPORT jboolean JNICALL Java_ai_rapids_cudf_ColumnView_hasNonEmptyNulls(JNIEnv* env, + jclass, + jlong column_view_handle) +{ JNI_NULL_CHECK(env, column_view_handle, "column_view handle is null", 0); try { cudf::jni::auto_set_device(env); - auto const *cv = reinterpret_cast(column_view_handle); + auto const* cv = reinterpret_cast(column_view_handle); return cudf::has_nonempty_nulls(*cv); } CATCH_STD(env, 0); } -JNIEXPORT jlong JNICALL -Java_ai_rapids_cudf_ColumnView_purgeNonEmptyNulls(JNIEnv *env, jclass, jlong column_view_handle) { +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_purgeNonEmptyNulls(JNIEnv* env, + jclass, + jlong column_view_handle) +{ JNI_NULL_CHECK(env, column_view_handle, "column_view handle is null", 0); try { cudf::jni::auto_set_device(env); - auto const *cv = reinterpret_cast(column_view_handle); + auto const* cv = reinterpret_cast(column_view_handle); return release_as_jlong(cudf::purge_nonempty_nulls(*cv)); } CATCH_STD(env, 0); } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_toHex(JNIEnv *env, jclass, jlong input_ptr) { +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_toHex(JNIEnv* env, jclass, jlong input_ptr) +{ JNI_NULL_CHECK(env, input_ptr, "input is null", 0); try { cudf::jni::auto_set_device(env); - const cudf::column_view *input = reinterpret_cast(input_ptr); + const cudf::column_view* input = reinterpret_cast(input_ptr); return release_as_jlong(cudf::strings::integers_to_hex(*input)); } CATCH_STD(env, 0); } -} // extern "C" +} // extern "C" diff --git a/java/src/main/native/src/ColumnViewJni.cu b/java/src/main/native/src/ColumnViewJni.cu index 56aea0b45e2..2dbff923544 100644 --- a/java/src/main/native/src/ColumnViewJni.cu +++ b/java/src/main/native/src/ColumnViewJni.cu @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2023, NVIDIA CORPORATION. + * Copyright (c) 2021-2024, NVIDIA CORPORATION. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,7 +14,7 @@ * limitations under the License. */ -#include +#include "ColumnViewJni.hpp" #include #include @@ -29,59 +29,64 @@ #include #include #include + #include #include #include + #include #include #include #include -#include "ColumnViewJni.hpp" +#include namespace cudf::jni { -std::unique_ptr -new_column_with_boolean_column_as_validity(cudf::column_view const &exemplar, - cudf::column_view const &validity_column) { +std::unique_ptr new_column_with_boolean_column_as_validity( + cudf::column_view const& exemplar, cudf::column_view const& validity_column) +{ CUDF_EXPECTS(validity_column.type().id() == type_id::BOOL8, "Validity column must be of type bool"); CUDF_EXPECTS(validity_column.size() == exemplar.size(), "Exemplar and validity columns must have the same size"); auto validity_device_view = cudf::column_device_view::create(validity_column); - auto validity_begin = cudf::detail::make_optional_iterator( - *validity_device_view, cudf::nullate::DYNAMIC{validity_column.has_nulls()}); - auto validity_end = validity_begin + validity_device_view->size(); + auto validity_begin = cudf::detail::make_optional_iterator( + *validity_device_view, cudf::nullate::DYNAMIC{validity_column.has_nulls()}); + auto validity_end = validity_begin + validity_device_view->size(); auto [null_mask, null_count] = cudf::detail::valid_if( - validity_begin, validity_end, - [] __device__(auto optional_bool) { return optional_bool.value_or(false); }, - cudf::get_default_stream(), rmm::mr::get_current_device_resource()); - auto const exemplar_without_null_mask = cudf::column_view{ - exemplar.type(), - exemplar.size(), - exemplar.head(), - nullptr, - 0, - exemplar.offset(), - std::vector{exemplar.child_begin(), exemplar.child_end()}}; + validity_begin, + validity_end, + [] __device__(auto optional_bool) { return optional_bool.value_or(false); }, + cudf::get_default_stream(), + rmm::mr::get_current_device_resource()); + auto const exemplar_without_null_mask = + cudf::column_view{exemplar.type(), + exemplar.size(), + exemplar.head(), + nullptr, + 0, + exemplar.offset(), + std::vector{exemplar.child_begin(), exemplar.child_end()}}; auto deep_copy = std::make_unique(exemplar_without_null_mask); deep_copy->set_null_mask(std::move(null_mask), null_count); return deep_copy; } -std::unique_ptr generate_list_offsets(cudf::column_view const &list_length, - rmm::cuda_stream_view stream) { +std::unique_ptr generate_list_offsets(cudf::column_view const& list_length, + rmm::cuda_stream_view stream) +{ CUDF_EXPECTS(list_length.type().id() == cudf::type_id::INT32, "Input column does not have type INT32."); auto const begin_iter = list_length.template begin(); - auto const end_iter = list_length.template end(); + auto const end_iter = list_length.template end(); - auto offsets_column = make_numeric_column(data_type{type_id::INT32}, list_length.size() + 1, - mask_state::UNALLOCATED, stream); + auto offsets_column = make_numeric_column( + data_type{type_id::INT32}, list_length.size() + 1, mask_state::UNALLOCATED, stream); auto offsets_view = offsets_column->mutable_view(); - auto d_offsets = offsets_view.template begin(); + auto d_offsets = offsets_view.template begin(); thrust::inclusive_scan(rmm::exec_policy(stream), begin_iter, end_iter, d_offsets + 1); CUDF_CUDA_TRY(cudaMemsetAsync(d_offsets, 0, sizeof(int32_t), stream)); @@ -97,75 +102,82 @@ namespace { * @param list The input list. * @return The boolean result indicating if the input list has null elements. */ -__device__ bool list_has_nulls(list_device_view list) { - return thrust::any_of(thrust::seq, thrust::make_counting_iterator(0), +__device__ bool list_has_nulls(list_device_view list) +{ + return thrust::any_of(thrust::seq, + thrust::make_counting_iterator(0), thrust::make_counting_iterator(list.size()), [&list](auto const idx) { return list.is_null(idx); }); } -} // namespace +} // namespace -void post_process_list_overlap(cudf::column_view const &lhs, cudf::column_view const &rhs, - std::unique_ptr const &overlap_result, - rmm::cuda_stream_view stream) { +void post_process_list_overlap(cudf::column_view const& lhs, + cudf::column_view const& rhs, + std::unique_ptr const& overlap_result, + rmm::cuda_stream_view stream) +{ // If both of the input columns do not have nulls, we don't need to do anything here. if (!lists_column_view{lhs}.child().has_nulls() && !lists_column_view{rhs}.child().has_nulls()) { return; } - auto const overlap_cv = overlap_result->view(); - auto const lhs_cdv_ptr = column_device_view::create(lhs, stream); - auto const rhs_cdv_ptr = column_device_view::create(rhs, stream); + auto const overlap_cv = overlap_result->view(); + auto const lhs_cdv_ptr = column_device_view::create(lhs, stream); + auto const rhs_cdv_ptr = column_device_view::create(rhs, stream); auto const overlap_cdv_ptr = column_device_view::create(overlap_cv, stream); // Create a new bitmask to satisfy Spark's arrays_overlap's special behavior. auto validity = rmm::device_uvector(overlap_cv.size(), stream); - thrust::tabulate(rmm::exec_policy(stream), validity.begin(), validity.end(), - [lhs = cudf::detail::lists_column_device_view{*lhs_cdv_ptr}, - rhs = cudf::detail::lists_column_device_view{*rhs_cdv_ptr}, - overlap_result = *overlap_cdv_ptr] __device__(auto const idx) { - if (overlap_result.is_null(idx) || - overlap_result.template element(idx)) { - return true; - } - - // `lhs_list` and `rhs_list` should not be null, otherwise - // `overlap_result[idx]` is null and that has been handled above. - auto const lhs_list = list_device_view{lhs, idx}; - auto const rhs_list = list_device_view{rhs, idx}; - - // Only proceed if both lists are non-empty. - if (lhs_list.size() == 0 || rhs_list.size() == 0) { - return true; - } - - // Only proceed if at least one list has nulls. - if (!list_has_nulls(lhs_list) && !list_has_nulls(rhs_list)) { - return true; - } - - // Here, the input lists satisfy all the conditions below so we output a - // null: - // - Both of the input lists have no non-null common element, and - // - They are both non-empty, and - // - Either of them contains null elements. - return false; - }); + thrust::tabulate( + rmm::exec_policy(stream), + validity.begin(), + validity.end(), + [lhs = cudf::detail::lists_column_device_view{*lhs_cdv_ptr}, + rhs = cudf::detail::lists_column_device_view{*rhs_cdv_ptr}, + overlap_result = *overlap_cdv_ptr] __device__(auto const idx) { + if (overlap_result.is_null(idx) || overlap_result.template element(idx)) { + return true; + } + + // `lhs_list` and `rhs_list` should not be null, otherwise + // `overlap_result[idx]` is null and that has been handled above. + auto const lhs_list = list_device_view{lhs, idx}; + auto const rhs_list = list_device_view{rhs, idx}; + + // Only proceed if both lists are non-empty. + if (lhs_list.size() == 0 || rhs_list.size() == 0) { return true; } + + // Only proceed if at least one list has nulls. + if (!list_has_nulls(lhs_list) && !list_has_nulls(rhs_list)) { return true; } + + // Here, the input lists satisfy all the conditions below so we output a + // null: + // - Both of the input lists have no non-null common element, and + // - They are both non-empty, and + // - Either of them contains null elements. + return false; + }); // Create a new nullmask from the validity data. auto [new_null_mask, new_null_count] = - cudf::detail::valid_if(validity.begin(), validity.end(), thrust::identity{}, - cudf::get_default_stream(), rmm::mr::get_current_device_resource()); + cudf::detail::valid_if(validity.begin(), + validity.end(), + thrust::identity{}, + cudf::get_default_stream(), + rmm::mr::get_current_device_resource()); if (new_null_count > 0) { // If the `overlap_result` column is nullable, perform `bitmask_and` of its nullmask and the // new nullmask. if (overlap_cv.nullable()) { auto [null_mask, null_count] = cudf::detail::bitmask_and( - std::vector{ - overlap_cv.null_mask(), static_cast(new_null_mask.data())}, - std::vector{0, 0}, overlap_cv.size(), stream, - rmm::mr::get_current_device_resource()); + std::vector{overlap_cv.null_mask(), + static_cast(new_null_mask.data())}, + std::vector{0, 0}, + overlap_cv.size(), + stream, + rmm::mr::get_current_device_resource()); overlap_result->set_null_mask(std::move(null_mask), null_count); } else { // Just set the output nullmask as the new nullmask. @@ -174,30 +186,32 @@ void post_process_list_overlap(cudf::column_view const &lhs, cudf::column_view c } } -std::unique_ptr lists_distinct_by_key(cudf::lists_column_view const &input, - rmm::cuda_stream_view stream) { - if (input.is_empty()) { - return empty_like(input.parent()); - } +std::unique_ptr lists_distinct_by_key(cudf::lists_column_view const& input, + rmm::cuda_stream_view stream) +{ + if (input.is_empty()) { return empty_like(input.parent()); } auto const child = input.get_sliced_child(stream); // Generate labels for the input list elements. auto labels = rmm::device_uvector(child.size(), stream); - cudf::detail::label_segments(input.offsets_begin(), input.offsets_end(), labels.begin(), - labels.end(), stream); + cudf::detail::label_segments( + input.offsets_begin(), input.offsets_end(), labels.begin(), labels.end(), stream); // Use `cudf::duplicate_keep_option::KEEP_LAST` so this will produce the desired behavior when // being called in `create_map` in spark-rapids. // Other options comparing nulls and NaNs are set as all-equal. - auto out_columns = - cudf::detail::stable_distinct( - table_view{{column_view{cudf::device_span{labels}}, child.child(0), - child.child(1)}}, // input table - std::vector{0, 1}, // key columns - cudf::duplicate_keep_option::KEEP_LAST, cudf::null_equality::EQUAL, - cudf::nan_equality::ALL_EQUAL, stream, rmm::mr::get_current_device_resource()) - ->release(); + auto out_columns = cudf::detail::stable_distinct( + table_view{{column_view{cudf::device_span{labels}}, + child.child(0), + child.child(1)}}, // input table + std::vector{0, 1}, // key columns + cudf::duplicate_keep_option::KEEP_LAST, + cudf::null_equality::EQUAL, + cudf::nan_equality::ALL_EQUAL, + stream, + rmm::mr::get_current_device_resource()) + ->release(); auto const out_labels = out_columns.front()->view(); // Assemble a structs column of . @@ -205,20 +219,26 @@ std::unique_ptr lists_distinct_by_key(cudf::lists_column_view cons out_structs_members.emplace_back(std::move(out_columns[1])); out_structs_members.emplace_back(std::move(out_columns[2])); auto out_structs = - cudf::make_structs_column(out_labels.size(), std::move(out_structs_members), 0, {}); + cudf::make_structs_column(out_labels.size(), std::move(out_structs_members), 0, {}); // Assemble a lists column of structs. - auto out_offsets = make_numeric_column(data_type{type_to_id()}, input.size() + 1, - mask_state::UNALLOCATED, stream); + auto out_offsets = make_numeric_column( + data_type{type_to_id()}, input.size() + 1, mask_state::UNALLOCATED, stream); auto const offsets_begin = out_offsets->mutable_view().template begin(); - auto const labels_begin = out_labels.template begin(); - cudf::detail::labels_to_offsets(labels_begin, labels_begin + out_labels.size(), offsets_begin, - offsets_begin + out_offsets->size(), stream); + auto const labels_begin = out_labels.template begin(); + cudf::detail::labels_to_offsets(labels_begin, + labels_begin + out_labels.size(), + offsets_begin, + offsets_begin + out_offsets->size(), + stream); return cudf::make_lists_column( - input.size(), std::move(out_offsets), std::move(out_structs), input.null_count(), - cudf::detail::copy_bitmask(input.parent(), stream, rmm::mr::get_current_device_resource()), - stream); + input.size(), + std::move(out_offsets), + std::move(out_structs), + input.null_count(), + cudf::detail::copy_bitmask(input.parent(), stream, rmm::mr::get_current_device_resource()), + stream); } -} // namespace cudf::jni +} // namespace cudf::jni diff --git a/java/src/main/native/src/ColumnViewJni.hpp b/java/src/main/native/src/ColumnViewJni.hpp index 12061119402..c9eef0139ea 100644 --- a/java/src/main/native/src/ColumnViewJni.hpp +++ b/java/src/main/native/src/ColumnViewJni.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2023, NVIDIA CORPORATION. + * Copyright (c) 2021-2024, NVIDIA CORPORATION. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,6 +17,7 @@ #include #include #include + #include namespace cudf::jni { @@ -34,9 +35,8 @@ namespace cudf::jni { * @param bool_column bool column whose value is to be used as the validity. * @return Deep copy of the exemplar, with the replaced validity. */ -std::unique_ptr -new_column_with_boolean_column_as_validity(cudf::column_view const &exemplar, - cudf::column_view const &bool_column); +std::unique_ptr new_column_with_boolean_column_as_validity( + cudf::column_view const& exemplar, cudf::column_view const& bool_column); /** * @brief Generates list offsets with lengths of each list. @@ -49,9 +49,8 @@ new_column_with_boolean_column_as_validity(cudf::column_view const &exemplar, * @param list_length The column represents list lengths. * @return The column represents list offsets. */ -std::unique_ptr -generate_list_offsets(cudf::column_view const &list_length, - rmm::cuda_stream_view stream = cudf::get_default_stream()); +std::unique_ptr generate_list_offsets( + cudf::column_view const& list_length, rmm::cuda_stream_view stream = cudf::get_default_stream()); /** * @brief Perform a special treatment for the results of `cudf::lists::have_overlap` to produce the @@ -71,8 +70,9 @@ generate_list_offsets(cudf::column_view const &list_length, * @param rhs The input lists column for the other side. * @param overlap_result The result column generated by checking list overlap in cudf. */ -void post_process_list_overlap(cudf::column_view const &lhs, cudf::column_view const &rhs, - std::unique_ptr const &overlap_result, +void post_process_list_overlap(cudf::column_view const& lhs, + cudf::column_view const& rhs, + std::unique_ptr const& overlap_result, rmm::cuda_stream_view stream = cudf::get_default_stream()); /** @@ -88,7 +88,7 @@ void post_process_list_overlap(cudf::column_view const &lhs, cudf::column_view c * * @return A new list columns in which the elements in each list are distinct by key. */ -std::unique_ptr lists_distinct_by_key(cudf::lists_column_view const &input, +std::unique_ptr lists_distinct_by_key(cudf::lists_column_view const& input, rmm::cuda_stream_view stream); -} // namespace cudf::jni +} // namespace cudf::jni diff --git a/java/src/main/native/src/CompiledExpression.cpp b/java/src/main/native/src/CompiledExpression.cpp index 56c96b26200..339204b96e6 100644 --- a/java/src/main/native/src/CompiledExpression.cpp +++ b/java/src/main/native/src/CompiledExpression.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2023, NVIDIA CORPORATION. + * Copyright (c) 2021-2024, NVIDIA CORPORATION. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,10 +14,8 @@ * limitations under the License. */ -#include -#include -#include -#include +#include "cudf_jni_apis.hpp" +#include "jni_compiled_expr.hpp" #include #include @@ -25,56 +23,65 @@ #include #include -#include "cudf_jni_apis.hpp" -#include "jni_compiled_expr.hpp" +#include +#include +#include +#include namespace { /** Utility class to read data from the serialized AST buffer generated from Java */ class jni_serialized_ast { - jbyte const *data_ptr; // pointer to the current entity to deserialize - jbyte const *const end_ptr; // pointer to the byte immediately after the AST serialized data + jbyte const* data_ptr; // pointer to the current entity to deserialize + jbyte const* const end_ptr; // pointer to the byte immediately after the AST serialized data /** Throws an error if there is insufficient space left to read the specified number of bytes */ - void check_for_eof(std::size_t num_bytes_to_read) { + void check_for_eof(std::size_t num_bytes_to_read) + { if (data_ptr + num_bytes_to_read > end_ptr) { throw std::runtime_error("Unexpected end of serialized data"); } } -public: - jni_serialized_ast(cudf::jni::native_jbyteArray &jni_data) - : data_ptr(jni_data.begin()), end_ptr(jni_data.end()) {} + public: + jni_serialized_ast(cudf::jni::native_jbyteArray& jni_data) + : data_ptr(jni_data.begin()), end_ptr(jni_data.end()) + { + } /** Returns true if there is no data remaining to be read */ bool at_eof() { return data_ptr == end_ptr; } /** Read a byte from the serialized AST data buffer */ - jbyte read_byte() { + jbyte read_byte() + { check_for_eof(sizeof(jbyte)); return *data_ptr++; } /** Read a multi-byte value from the serialized AST data buffer */ - template T read() { + template + T read() + { if constexpr (std::is_same_v) { auto const size = read(); check_for_eof(size); - auto const result = std::string(reinterpret_cast(data_ptr), size); + auto const result = std::string(reinterpret_cast(data_ptr), size); data_ptr += size; return result; } else { check_for_eof(sizeof(T)); // use memcpy since data may be misaligned T result; - memcpy(reinterpret_cast(&result), data_ptr, sizeof(T)); + memcpy(reinterpret_cast(&result), data_ptr, sizeof(T)); data_ptr += sizeof(T); return result; } } /** Decode a libcudf data type from the serialized AST data buffer */ - cudf::data_type read_cudf_type() { + cudf::data_type read_cudf_type() + { auto const dtype_id = static_cast(read_byte()); switch (dtype_id) { case cudf::type_id::INT8: @@ -116,10 +123,10 @@ class jni_serialized_ast { * NOTE: This must be kept in sync with the NodeType enumeration in AstNode.java! */ enum class jni_serialized_expression_type : int8_t { - VALID_LITERAL = 0, - NULL_LITERAL = 1, + VALID_LITERAL = 0, + NULL_LITERAL = 1, COLUMN_REFERENCE = 2, - UNARY_OPERATION = 3, + UNARY_OPERATION = 3, BINARY_OPERATION = 4 }; @@ -128,7 +135,8 @@ enum class jni_serialized_expression_type : int8_t { * corresponding libcudf AST operator. * NOTE: This must be kept in sync with the enumeration in UnaryOperator.java! */ -cudf::ast::ast_operator jni_to_unary_operator(jbyte jni_op_value) { +cudf::ast::ast_operator jni_to_unary_operator(jbyte jni_op_value) +{ switch (jni_op_value) { case 0: return cudf::ast::ast_operator::IDENTITY; case 1: return cudf::ast::ast_operator::IS_NULL; @@ -166,7 +174,8 @@ cudf::ast::ast_operator jni_to_unary_operator(jbyte jni_op_value) { * corresponding libcudf AST operator. * NOTE: This must be kept in sync with the enumeration in BinaryOperator.java! */ -cudf::ast::ast_operator jni_to_binary_operator(jbyte jni_op_value) { +cudf::ast::ast_operator jni_to_binary_operator(jbyte jni_op_value) +{ switch (jni_op_value) { case 0: return cudf::ast::ast_operator::ADD; case 1: return cudf::ast::ast_operator::SUB; @@ -200,7 +209,8 @@ cudf::ast::ast_operator jni_to_binary_operator(jbyte jni_op_value) { * corresponding libcudf AST table reference. * NOTE: This must be kept in sync with the enumeration in TableReference.java! */ -cudf::ast::table_reference jni_to_table_reference(jbyte jni_value) { +cudf::ast::table_reference jni_to_table_reference(jbyte jni_value) +{ switch (jni_value) { case 0: return cudf::ast::table_reference::LEFT; case 1: return cudf::ast::table_reference::RIGHT; @@ -211,64 +221,72 @@ cudf::ast::table_reference jni_to_table_reference(jbyte jni_value) { /** Functor for type-dispatching the creation of an AST literal */ struct make_literal { /** Construct an AST literal from a numeric value */ - template ()> * = nullptr> - cudf::ast::literal &operator()(cudf::data_type dtype, bool is_valid, - cudf::jni::ast::compiled_expr &compiled_expr, - jni_serialized_ast &jni_ast) { + template ()>* = nullptr> + cudf::ast::literal& operator()(cudf::data_type dtype, + bool is_valid, + cudf::jni::ast::compiled_expr& compiled_expr, + jni_serialized_ast& jni_ast) + { std::unique_ptr scalar_ptr = cudf::make_numeric_scalar(dtype); scalar_ptr->set_valid_async(is_valid); if (is_valid) { - T val = jni_ast.read(); + T val = jni_ast.read(); using ScalarType = cudf::scalar_type_t; - static_cast(scalar_ptr.get())->set_value(val); + static_cast(scalar_ptr.get())->set_value(val); } - auto &numeric_scalar = static_cast &>(*scalar_ptr); + auto& numeric_scalar = static_cast&>(*scalar_ptr); return compiled_expr.add_literal(std::make_unique(numeric_scalar), std::move(scalar_ptr)); } /** Construct an AST literal from a timestamp value */ - template ()> * = nullptr> - cudf::ast::literal &operator()(cudf::data_type dtype, bool is_valid, - cudf::jni::ast::compiled_expr &compiled_expr, - jni_serialized_ast &jni_ast) { + template ()>* = nullptr> + cudf::ast::literal& operator()(cudf::data_type dtype, + bool is_valid, + cudf::jni::ast::compiled_expr& compiled_expr, + jni_serialized_ast& jni_ast) + { std::unique_ptr scalar_ptr = cudf::make_timestamp_scalar(dtype); scalar_ptr->set_valid_async(is_valid); if (is_valid) { - T val = jni_ast.read(); + T val = jni_ast.read(); using ScalarType = cudf::scalar_type_t; - static_cast(scalar_ptr.get())->set_value(val); + static_cast(scalar_ptr.get())->set_value(val); } - auto ×tamp_scalar = static_cast &>(*scalar_ptr); + auto& timestamp_scalar = static_cast&>(*scalar_ptr); return compiled_expr.add_literal(std::make_unique(timestamp_scalar), std::move(scalar_ptr)); } /** Construct an AST literal from a duration value */ - template ()> * = nullptr> - cudf::ast::literal &operator()(cudf::data_type dtype, bool is_valid, - cudf::jni::ast::compiled_expr &compiled_expr, - jni_serialized_ast &jni_ast) { + template ()>* = nullptr> + cudf::ast::literal& operator()(cudf::data_type dtype, + bool is_valid, + cudf::jni::ast::compiled_expr& compiled_expr, + jni_serialized_ast& jni_ast) + { std::unique_ptr scalar_ptr = cudf::make_duration_scalar(dtype); scalar_ptr->set_valid_async(is_valid); if (is_valid) { - T val = jni_ast.read(); + T val = jni_ast.read(); using ScalarType = cudf::scalar_type_t; - static_cast(scalar_ptr.get())->set_value(val); + static_cast(scalar_ptr.get())->set_value(val); } - auto &duration_scalar = static_cast &>(*scalar_ptr); + auto& duration_scalar = static_cast&>(*scalar_ptr); return compiled_expr.add_literal(std::make_unique(duration_scalar), std::move(scalar_ptr)); } /** Construct an AST literal from a string value */ - template > * = nullptr> - cudf::ast::literal &operator()(cudf::data_type dtype, bool is_valid, - cudf::jni::ast::compiled_expr &compiled_expr, - jni_serialized_ast &jni_ast) { + template >* = nullptr> + cudf::ast::literal& operator()(cudf::data_type dtype, + bool is_valid, + cudf::jni::ast::compiled_expr& compiled_expr, + jni_serialized_ast& jni_ast) + { std::unique_ptr scalar_ptr = [&]() { if (is_valid) { std::string val = jni_ast.read(); @@ -278,64 +296,73 @@ struct make_literal { } }(); - auto &str_scalar = static_cast(*scalar_ptr); + auto& str_scalar = static_cast(*scalar_ptr); return compiled_expr.add_literal(std::make_unique(str_scalar), std::move(scalar_ptr)); } /** Default functor implementation to catch type dispatch errors */ - template () && !cudf::is_timestamp() && - !cudf::is_duration() && - !std::is_same_v> * = nullptr> - cudf::ast::literal &operator()(cudf::data_type dtype, bool is_valid, - cudf::jni::ast::compiled_expr &compiled_expr, - jni_serialized_ast &jni_ast) { + template < + typename T, + std::enable_if_t() && !cudf::is_timestamp() && + !cudf::is_duration() && !std::is_same_v>* = nullptr> + cudf::ast::literal& operator()(cudf::data_type dtype, + bool is_valid, + cudf::jni::ast::compiled_expr& compiled_expr, + jni_serialized_ast& jni_ast) + { throw std::logic_error("Unsupported AST literal type"); } }; /** Decode a serialized AST literal */ -cudf::ast::literal &compile_literal(bool is_valid, cudf::jni::ast::compiled_expr &compiled_expr, - jni_serialized_ast &jni_ast) { +cudf::ast::literal& compile_literal(bool is_valid, + cudf::jni::ast::compiled_expr& compiled_expr, + jni_serialized_ast& jni_ast) +{ auto const dtype = jni_ast.read_cudf_type(); return cudf::type_dispatcher(dtype, make_literal{}, dtype, is_valid, compiled_expr, jni_ast); } /** Decode a serialized AST column reference */ -cudf::ast::column_reference &compile_column_reference(cudf::jni::ast::compiled_expr &compiled_expr, - jni_serialized_ast &jni_ast) { - auto const table_ref = jni_to_table_reference(jni_ast.read_byte()); +cudf::ast::column_reference& compile_column_reference(cudf::jni::ast::compiled_expr& compiled_expr, + jni_serialized_ast& jni_ast) +{ + auto const table_ref = jni_to_table_reference(jni_ast.read_byte()); cudf::size_type const column_index = jni_ast.read(); return compiled_expr.add_column_ref( - std::make_unique(column_index, table_ref)); + std::make_unique(column_index, table_ref)); } // forward declaration -cudf::ast::expression &compile_expression(cudf::jni::ast::compiled_expr &compiled_expr, - jni_serialized_ast &jni_ast); +cudf::ast::expression& compile_expression(cudf::jni::ast::compiled_expr& compiled_expr, + jni_serialized_ast& jni_ast); /** Decode a serialized AST unary expression */ -cudf::ast::operation &compile_unary_expression(cudf::jni::ast::compiled_expr &compiled_expr, - jni_serialized_ast &jni_ast) { - auto const ast_op = jni_to_unary_operator(jni_ast.read_byte()); - cudf::ast::expression &child_expression = compile_expression(compiled_expr, jni_ast); +cudf::ast::operation& compile_unary_expression(cudf::jni::ast::compiled_expr& compiled_expr, + jni_serialized_ast& jni_ast) +{ + auto const ast_op = jni_to_unary_operator(jni_ast.read_byte()); + cudf::ast::expression& child_expression = compile_expression(compiled_expr, jni_ast); return compiled_expr.add_operation( - std::make_unique(ast_op, child_expression)); + std::make_unique(ast_op, child_expression)); } /** Decode a serialized AST binary expression */ -cudf::ast::operation &compile_binary_expression(cudf::jni::ast::compiled_expr &compiled_expr, - jni_serialized_ast &jni_ast) { - auto const ast_op = jni_to_binary_operator(jni_ast.read_byte()); - cudf::ast::expression &left_child = compile_expression(compiled_expr, jni_ast); - cudf::ast::expression &right_child = compile_expression(compiled_expr, jni_ast); +cudf::ast::operation& compile_binary_expression(cudf::jni::ast::compiled_expr& compiled_expr, + jni_serialized_ast& jni_ast) +{ + auto const ast_op = jni_to_binary_operator(jni_ast.read_byte()); + cudf::ast::expression& left_child = compile_expression(compiled_expr, jni_ast); + cudf::ast::expression& right_child = compile_expression(compiled_expr, jni_ast); return compiled_expr.add_operation( - std::make_unique(ast_op, left_child, right_child)); + std::make_unique(ast_op, left_child, right_child)); } /** Decode a serialized AST expression by reading the expression type and dispatching */ -cudf::ast::expression &compile_expression(cudf::jni::ast::compiled_expr &compiled_expr, - jni_serialized_ast &jni_ast) { +cudf::ast::expression& compile_expression(cudf::jni::ast::compiled_expr& compiled_expr, + jni_serialized_ast& jni_ast) +{ auto const expression_type = static_cast(jni_ast.read_byte()); switch (expression_type) { case jni_serialized_expression_type::VALID_LITERAL: @@ -353,23 +380,24 @@ cudf::ast::expression &compile_expression(cudf::jni::ast::compiled_expr &compile } /** Decode a serialized AST into a native libcudf AST and associated resources */ -std::unique_ptr compile_serialized_ast(jni_serialized_ast &jni_ast) { +std::unique_ptr compile_serialized_ast(jni_serialized_ast& jni_ast) +{ auto jni_expr_ptr = std::make_unique(); (void)compile_expression(*jni_expr_ptr, jni_ast); - if (!jni_ast.at_eof()) { - throw std::invalid_argument("Extra bytes at end of serialized AST"); - } + if (!jni_ast.at_eof()) { throw std::invalid_argument("Extra bytes at end of serialized AST"); } return jni_expr_ptr; } -} // anonymous namespace +} // anonymous namespace extern "C" { -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ast_CompiledExpression_compile(JNIEnv *env, jclass, - jbyteArray jni_data) { +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ast_CompiledExpression_compile(JNIEnv* env, + jclass, + jbyteArray jni_data) +{ JNI_NULL_CHECK(env, jni_data, "Serialized AST data is null", 0); try { cudf::jni::auto_set_device(env); @@ -382,31 +410,34 @@ JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ast_CompiledExpression_compile(JNIEn CATCH_STD(env, 0); } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ast_CompiledExpression_computeColumn(JNIEnv *env, +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ast_CompiledExpression_computeColumn(JNIEnv* env, jclass, jlong j_ast, - jlong j_table) { + jlong j_table) +{ JNI_NULL_CHECK(env, j_ast, "Compiled AST pointer is null", 0); JNI_NULL_CHECK(env, j_table, "Table view pointer is null", 0); try { cudf::jni::auto_set_device(env); - auto compiled_expr_ptr = reinterpret_cast(j_ast); - auto tview_ptr = reinterpret_cast(j_table); + auto compiled_expr_ptr = reinterpret_cast(j_ast); + auto tview_ptr = reinterpret_cast(j_table); std::unique_ptr result = - cudf::compute_column(*tview_ptr, compiled_expr_ptr->get_top_expression()); + cudf::compute_column(*tview_ptr, compiled_expr_ptr->get_top_expression()); return reinterpret_cast(result.release()); } CATCH_STD(env, 0); } -JNIEXPORT void JNICALL Java_ai_rapids_cudf_ast_CompiledExpression_destroy(JNIEnv *env, jclass, - jlong jni_handle) { +JNIEXPORT void JNICALL Java_ai_rapids_cudf_ast_CompiledExpression_destroy(JNIEnv* env, + jclass, + jlong jni_handle) +{ try { cudf::jni::auto_set_device(env); - auto ptr = reinterpret_cast(jni_handle); + auto ptr = reinterpret_cast(jni_handle); delete ptr; } CATCH_STD(env, ); } -} // extern "C" +} // extern "C" diff --git a/java/src/main/native/src/ContiguousTableJni.cpp b/java/src/main/native/src/ContiguousTableJni.cpp index 8c99c77ca1f..19a10bf25ec 100644 --- a/java/src/main/native/src/ContiguousTableJni.cpp +++ b/java/src/main/native/src/ContiguousTableJni.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2023, NVIDIA CORPORATION. + * Copyright (c) 2021-2024, NVIDIA CORPORATION. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,7 +18,7 @@ namespace { -#define CONTIGUOUS_TABLE_CLASS "ai/rapids/cudf/ContiguousTable" +#define CONTIGUOUS_TABLE_CLASS "ai/rapids/cudf/ContiguousTable" #define CONTIGUOUS_TABLE_FACTORY_SIG(param_sig) "(" param_sig ")L" CONTIGUOUS_TABLE_CLASS ";" jclass Contiguous_table_jclass; @@ -29,87 +29,85 @@ jclass Contig_split_group_by_result_jclass; jfieldID Contig_split_group_by_result_groups_field; jfieldID Contig_split_group_by_result_uniq_key_columns_field; -} // anonymous namespace +} // anonymous namespace namespace cudf { namespace jni { -bool cache_contiguous_table_jni(JNIEnv *env) { +bool cache_contiguous_table_jni(JNIEnv* env) +{ jclass cls = env->FindClass(CONTIGUOUS_TABLE_CLASS); - if (cls == nullptr) { - return false; - } + if (cls == nullptr) { return false; } From_packed_table_method = - env->GetStaticMethodID(cls, "fromPackedTable", CONTIGUOUS_TABLE_FACTORY_SIG("JJJJJ")); - if (From_packed_table_method == nullptr) { - return false; - } + env->GetStaticMethodID(cls, "fromPackedTable", CONTIGUOUS_TABLE_FACTORY_SIG("JJJJJ")); + if (From_packed_table_method == nullptr) { return false; } // Convert local reference to global so it cannot be garbage collected. Contiguous_table_jclass = static_cast(env->NewGlobalRef(cls)); - if (Contiguous_table_jclass == nullptr) { - return false; - } + if (Contiguous_table_jclass == nullptr) { return false; } return true; } -void release_contiguous_table_jni(JNIEnv *env) { +void release_contiguous_table_jni(JNIEnv* env) +{ Contiguous_table_jclass = cudf::jni::del_global_ref(env, Contiguous_table_jclass); } -bool cache_contig_split_group_by_result_jni(JNIEnv *env) { +bool cache_contig_split_group_by_result_jni(JNIEnv* env) +{ jclass cls = env->FindClass(GROUP_BY_RESULT_CLASS); - if (cls == nullptr) { - return false; - } + if (cls == nullptr) { return false; } Contig_split_group_by_result_groups_field = - env->GetFieldID(cls, "groups", "[Lai/rapids/cudf/ContiguousTable;"); - if (Contig_split_group_by_result_groups_field == nullptr) { - return false; - } + env->GetFieldID(cls, "groups", "[Lai/rapids/cudf/ContiguousTable;"); + if (Contig_split_group_by_result_groups_field == nullptr) { return false; } Contig_split_group_by_result_uniq_key_columns_field = - env->GetFieldID(cls, "uniqKeyColumns", "[J"); - if (Contig_split_group_by_result_uniq_key_columns_field == nullptr) { - return false; - } + env->GetFieldID(cls, "uniqKeyColumns", "[J"); + if (Contig_split_group_by_result_uniq_key_columns_field == nullptr) { return false; } // Convert local reference to global so it cannot be garbage collected. Contig_split_group_by_result_jclass = static_cast(env->NewGlobalRef(cls)); - if (Contig_split_group_by_result_jclass == nullptr) { - return false; - } + if (Contig_split_group_by_result_jclass == nullptr) { return false; } return true; } -void release_contig_split_group_by_result_jni(JNIEnv *env) { +void release_contig_split_group_by_result_jni(JNIEnv* env) +{ Contig_split_group_by_result_jclass = del_global_ref(env, Contig_split_group_by_result_jclass); } -jobject contig_split_group_by_result_from(JNIEnv *env, jobjectArray &groups) { +jobject contig_split_group_by_result_from(JNIEnv* env, jobjectArray& groups) +{ jobject gbr = env->AllocObject(Contig_split_group_by_result_jclass); env->SetObjectField(gbr, Contig_split_group_by_result_groups_field, groups); return gbr; } -jobject contig_split_group_by_result_from(JNIEnv *env, jobjectArray &groups, - jlongArray &uniq_key_columns) { +jobject contig_split_group_by_result_from(JNIEnv* env, + jobjectArray& groups, + jlongArray& uniq_key_columns) +{ jobject gbr = env->AllocObject(Contig_split_group_by_result_jclass); env->SetObjectField(gbr, Contig_split_group_by_result_groups_field, groups); env->SetObjectField(gbr, Contig_split_group_by_result_uniq_key_columns_field, uniq_key_columns); return gbr; } -jobject contiguous_table_from(JNIEnv *env, cudf::packed_columns &split, long row_count) { - jlong metadata_address = reinterpret_cast(split.metadata.get()); - jlong data_address = reinterpret_cast(split.gpu_data->data()); - jlong data_size = static_cast(split.gpu_data->size()); +jobject contiguous_table_from(JNIEnv* env, cudf::packed_columns& split, long row_count) +{ + jlong metadata_address = reinterpret_cast(split.metadata.get()); + jlong data_address = reinterpret_cast(split.gpu_data->data()); + jlong data_size = static_cast(split.gpu_data->size()); jlong rmm_buffer_address = reinterpret_cast(split.gpu_data.get()); - jobject contig_table_obj = env->CallStaticObjectMethod( - Contiguous_table_jclass, From_packed_table_method, metadata_address, data_address, data_size, - rmm_buffer_address, row_count); + jobject contig_table_obj = env->CallStaticObjectMethod(Contiguous_table_jclass, + From_packed_table_method, + metadata_address, + data_address, + data_size, + rmm_buffer_address, + row_count); if (contig_table_obj != nullptr) { split.metadata.release(); @@ -119,28 +117,30 @@ jobject contiguous_table_from(JNIEnv *env, cudf::packed_columns &split, long row return contig_table_obj; } -native_jobjectArray contiguous_table_array(JNIEnv *env, jsize length) { +native_jobjectArray contiguous_table_array(JNIEnv* env, jsize length) +{ return native_jobjectArray( - env, env->NewObjectArray(length, Contiguous_table_jclass, nullptr)); + env, env->NewObjectArray(length, Contiguous_table_jclass, nullptr)); } -} // namespace jni -} // namespace cudf +} // namespace jni +} // namespace cudf extern "C" { JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ContiguousTable_createPackedMetadata( - JNIEnv *env, jclass, jlong j_table, jlong j_buffer_addr, jlong j_buffer_length) { + JNIEnv* env, jclass, jlong j_table, jlong j_buffer_addr, jlong j_buffer_length) +{ JNI_NULL_CHECK(env, j_table, "input table is null", 0); try { cudf::jni::auto_set_device(env); - auto table = reinterpret_cast(j_table); - auto data_addr = reinterpret_cast(j_buffer_addr); - auto data_size = static_cast(j_buffer_length); + auto table = reinterpret_cast(j_table); + auto data_addr = reinterpret_cast(j_buffer_addr); + auto data_size = static_cast(j_buffer_length); auto metadata_ptr = new std::vector(cudf::pack_metadata(*table, data_addr, data_size)); return reinterpret_cast(metadata_ptr); } CATCH_STD(env, 0); } -} // extern "C" +} // extern "C" diff --git a/java/src/main/native/src/CuFileJni.cpp b/java/src/main/native/src/CuFileJni.cpp index ef165281bf9..382d0e6c9f7 100644 --- a/java/src/main/native/src/CuFileJni.cpp +++ b/java/src/main/native/src/CuFileJni.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020-2021, NVIDIA CORPORATION. + * Copyright (c) 2020-2024, NVIDIA CORPORATION. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,18 +13,18 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include +#include "cudf_jni_apis.hpp" +#include "jni_utils.hpp" + +#include #include #include -#include - -#include #include #include +#include -#include "cudf_jni_apis.hpp" -#include "jni_utils.hpp" +#include namespace { @@ -34,10 +34,10 @@ namespace { * @param cu_result CUDA driver error code. * @return Description for the error. */ -char const *GetCuErrorString(CUresult cu_result) { - char const *description; - if (cuGetErrorName(cu_result, &description) != CUDA_SUCCESS) - description = "unknown cuda error"; +char const* GetCuErrorString(CUresult cu_result) +{ + char const* description; + if (cuGetErrorName(cu_result, &description) != CUDA_SUCCESS) description = "unknown cuda error"; return description; } @@ -49,9 +49,10 @@ char const *GetCuErrorString(CUresult cu_result) { * @param error_code Integer error code. * @return Description of the error. */ -std::string cuFileGetErrorString(int error_code) { - return IS_CUFILE_ERR(error_code) ? std::string(CUFILE_ERRSTR(error_code)) : - std::string(std::strerror(error_code)); +std::string cuFileGetErrorString(int error_code) +{ + return IS_CUFILE_ERR(error_code) ? std::string(CUFILE_ERRSTR(error_code)) + : std::string(std::strerror(error_code)); } /** @@ -60,11 +61,10 @@ std::string cuFileGetErrorString(int error_code) { * @param status cuFile return status. * @return Description of the error. */ -std::string cuFileGetErrorString(CUfileError_t status) { +std::string cuFileGetErrorString(CUfileError_t status) +{ std::string error = cuFileGetErrorString(status.err); - if (IS_CUDA_ERR(status)) { - error.append(".").append(GetCuErrorString(status.cu_err)); - } + if (IS_CUDA_ERR(status)) { error.append(".").append(GetCuErrorString(status.cu_err)); } return error; } @@ -72,9 +72,10 @@ std::string cuFileGetErrorString(CUfileError_t status) { * @brief RAII wrapper for the cuFile driver. */ class cufile_driver { -public: + public: /** @brief Construct a new driver instance by opening the cuFile driver. */ - cufile_driver() { + cufile_driver() + { auto const status = cuFileDriverOpen(); if (status.err != CU_FILE_SUCCESS) { CUDF_FAIL("Failed to initialize cuFile driver: " + cuFileGetErrorString(status)); @@ -82,8 +83,8 @@ class cufile_driver { } // Disable copy (and move) semantics. - cufile_driver(cufile_driver const &) = delete; - cufile_driver &operator=(cufile_driver const &) = delete; + cufile_driver(cufile_driver const&) = delete; + cufile_driver& operator=(cufile_driver const&) = delete; /** @brief Destroy the driver instance by closing the cuFile driver. */ ~cufile_driver() { cuFileDriverClose(); } @@ -91,7 +92,7 @@ class cufile_driver { /** @brief RAII wrapper for a device buffer used by cuFile. */ class cufile_buffer { -public: + public: /** * @brief Construct a new cuFile buffer. * @@ -100,8 +101,9 @@ class cufile_buffer { * @param register_buffer Whether to register the buffer with cuFile. This should only be set to * true if this buffer is being reused and is 4KiB aligned. */ - cufile_buffer(void *device_pointer, std::size_t size, bool register_buffer = false) - : device_pointer_{device_pointer}, size_{size}, register_buffer_{register_buffer} { + cufile_buffer(void* device_pointer, std::size_t size, bool register_buffer = false) + : device_pointer_{device_pointer}, size_{size}, register_buffer_{register_buffer} + { if (register_buffer_) { auto const status = cuFileBufRegister(device_pointer_, size_, 0); if (status.err != CU_FILE_SUCCESS) { @@ -111,14 +113,13 @@ class cufile_buffer { } // Disable copy (and move) semantics. - cufile_buffer(cufile_buffer const &) = delete; - cufile_buffer &operator=(cufile_buffer const &) = delete; + cufile_buffer(cufile_buffer const&) = delete; + cufile_buffer& operator=(cufile_buffer const&) = delete; /** @brief Destroy the buffer by de-registering it if necessary. */ - ~cufile_buffer() { - if (register_buffer_) { - cuFileBufDeregister(device_pointer_); - } + ~cufile_buffer() + { + if (register_buffer_) { cuFileBufDeregister(device_pointer_); } } /** @@ -126,7 +127,7 @@ class cufile_buffer { * * @return Pointer to the device buffer. */ - void *device_pointer() const { return device_pointer_; } + void* device_pointer() const { return device_pointer_; } /** * @brief Get the size of the underlying device buffer. @@ -135,9 +136,9 @@ class cufile_buffer { */ std::size_t size() const { return size_; } -private: + private: /// Pointer to the device buffer. - void *device_pointer_; + void* device_pointer_; /// Size of the device buffer. std::size_t size_; /// Whether to register the buffer with cuFile. @@ -146,7 +147,7 @@ class cufile_buffer { /** @brief RAII wrapper for a file descriptor and the corresponding cuFile handle. */ class cufile_file { -public: + public: /** * @brief Construct a file wrapper. * @@ -154,7 +155,8 @@ class cufile_file { * * @param file_descriptor A valid file descriptor. */ - explicit cufile_file(int file_descriptor) : file_descriptor_{file_descriptor} { + explicit cufile_file(int file_descriptor) : file_descriptor_{file_descriptor} + { CUfileDescr_t cufile_descriptor{CU_FILE_HANDLE_TYPE_OPAQUE_FD, file_descriptor_}; auto const status = cuFileHandleRegister(&cufile_handle_, &cufile_descriptor); if (status.err != CU_FILE_SUCCESS) { @@ -169,7 +171,8 @@ class cufile_file { * @param path Absolute path of the file to read from. * @return std::unique_ptr for reading. */ - static auto make_reader(char const *path) { + static auto make_reader(char const* path) + { auto const file_descriptor = open(path, O_RDONLY | O_DIRECT); if (file_descriptor < 0) { CUDF_FAIL("Failed to open file to read: " + cuFileGetErrorString(errno)); @@ -183,7 +186,8 @@ class cufile_file { * @param path Absolute path of the file to write to. * @return std::unique_ptr for writing. */ - static auto make_writer(char const *path) { + static auto make_writer(char const* path) + { auto const file_descriptor = open(path, O_CREAT | O_WRONLY | O_DIRECT, S_IRUSR | S_IWUSR); if (file_descriptor < 0) { CUDF_FAIL("Failed to open file to write: " + cuFileGetErrorString(errno)); @@ -192,11 +196,12 @@ class cufile_file { } // Disable copy (and move) semantics. - cufile_file(cufile_file const &) = delete; - cufile_file &operator=(cufile_file const &) = delete; + cufile_file(cufile_file const&) = delete; + cufile_file& operator=(cufile_file const&) = delete; /** @brief Destroy the file wrapper by de-registering the cuFile handle and closing the file. */ - ~cufile_file() { + ~cufile_file() + { cuFileHandleDeregister(cufile_handle_); close(file_descriptor_); } @@ -207,9 +212,10 @@ class cufile_file { * @param buffer Device buffer to read the file content into. * @param file_offset Starting offset from which to read the file. */ - void read(cufile_buffer const &buffer, std::size_t file_offset) const { + void read(cufile_buffer const& buffer, std::size_t file_offset) const + { auto const status = - cuFileRead(cufile_handle_, buffer.device_pointer(), buffer.size(), file_offset, 0); + cuFileRead(cufile_handle_, buffer.device_pointer(), buffer.size(), file_offset, 0); if (status < 0) { if (IS_CUFILE_ERR(status)) { @@ -230,7 +236,8 @@ class cufile_file { * @param size The number of bytes to write. * @param file_offset Starting offset from which to write the buffer. */ - void write(cufile_buffer const &buffer, std::size_t size, std::size_t file_offset) { + void write(cufile_buffer const& buffer, std::size_t size, std::size_t file_offset) + { auto const status = cuFileWrite(cufile_handle_, buffer.device_pointer(), size, file_offset, 0); if (status < 0) { @@ -252,7 +259,8 @@ class cufile_file { * @param size The number of bytes to append. * @return The file offset from which the buffer was appended. */ - std::size_t append(cufile_buffer const &buffer, std::size_t size) { + std::size_t append(cufile_buffer const& buffer, std::size_t size) + { struct stat stat_buffer; auto const status = fstat(file_descriptor_, &stat_buffer); if (status < 0) { @@ -264,14 +272,14 @@ class cufile_file { return file_offset; } -private: + private: /// The underlying file descriptor. int file_descriptor_; /// The registered cuFile handle. CUfileHandle_t cufile_handle_{}; }; -} // anonymous namespace +} // anonymous namespace extern "C" { @@ -281,7 +289,8 @@ extern "C" { * @param env The JNI environment. * @return Pointer address to the new driver wrapper instance. */ -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_CuFileDriver_create(JNIEnv *env, jclass) { +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_CuFileDriver_create(JNIEnv* env, jclass) +{ try { cudf::jni::auto_set_device(env); return reinterpret_cast(new cufile_driver()); @@ -295,11 +304,11 @@ JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_CuFileDriver_create(JNIEnv *env, jcl * @param env The JNI environment. * @param pointer Pointer address to the driver wrapper instance. */ -JNIEXPORT void JNICALL Java_ai_rapids_cudf_CuFileDriver_destroy(JNIEnv *env, jclass, - jlong pointer) { +JNIEXPORT void JNICALL Java_ai_rapids_cudf_CuFileDriver_destroy(JNIEnv* env, jclass, jlong pointer) +{ try { cudf::jni::auto_set_device(env); - delete reinterpret_cast(pointer); + delete reinterpret_cast(pointer); } CATCH_STD(env, ); } @@ -313,13 +322,13 @@ JNIEXPORT void JNICALL Java_ai_rapids_cudf_CuFileDriver_destroy(JNIEnv *env, jcl * @param register_buffer If true, register the cuFile buffer. * @return Pointer address to the new buffer wrapper instance. */ -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_CuFileBuffer_create(JNIEnv *env, jclass, - jlong device_pointer, jlong size, - jboolean register_buffer) { +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_CuFileBuffer_create( + JNIEnv* env, jclass, jlong device_pointer, jlong size, jboolean register_buffer) +{ try { cudf::jni::auto_set_device(env); - auto *buffer = - new cufile_buffer(reinterpret_cast(device_pointer), size, register_buffer); + auto* buffer = + new cufile_buffer(reinterpret_cast(device_pointer), size, register_buffer); return reinterpret_cast(buffer); } CATCH_STD(env, 0); @@ -331,11 +340,11 @@ JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_CuFileBuffer_create(JNIEnv *env, jcl * @param env The JNI environment. * @param pointer Pointer address to the buffer wrapper instance. */ -JNIEXPORT void JNICALL Java_ai_rapids_cudf_CuFileBuffer_destroy(JNIEnv *env, jclass, - jlong pointer) { +JNIEXPORT void JNICALL Java_ai_rapids_cudf_CuFileBuffer_destroy(JNIEnv* env, jclass, jlong pointer) +{ try { cudf::jni::auto_set_device(env); - delete reinterpret_cast(pointer); + delete reinterpret_cast(pointer); } CATCH_STD(env, ); } @@ -347,8 +356,10 @@ JNIEXPORT void JNICALL Java_ai_rapids_cudf_CuFileBuffer_destroy(JNIEnv *env, jcl * @param path The file path to read from. * @return Pointer address to the new file handle wrapper instance. */ -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_CuFileReadHandle_create(JNIEnv *env, jclass, - jstring path) { +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_CuFileReadHandle_create(JNIEnv* env, + jclass, + jstring path) +{ try { cudf::jni::auto_set_device(env); auto file = cufile_file::make_reader(env->GetStringUTFChars(path, nullptr)); @@ -365,14 +376,13 @@ JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_CuFileReadHandle_create(JNIEnv *env, * @param file_offset The file offset from which to read. * @param buffer Pointer to the cuFile buffer object. */ -JNIEXPORT void JNICALL Java_ai_rapids_cudf_CuFileReadHandle_readIntoBuffer(JNIEnv *env, jclass, - jlong file, - jlong file_offset, - jlong buffer) { +JNIEXPORT void JNICALL Java_ai_rapids_cudf_CuFileReadHandle_readIntoBuffer( + JNIEnv* env, jclass, jlong file, jlong file_offset, jlong buffer) +{ try { cudf::jni::auto_set_device(env); - auto *file_ptr = reinterpret_cast(file); - auto *buffer_ptr = reinterpret_cast(buffer); + auto* file_ptr = reinterpret_cast(file); + auto* buffer_ptr = reinterpret_cast(buffer); file_ptr->read(*buffer_ptr, file_offset); } CATCH_STD(env, ); @@ -385,8 +395,10 @@ JNIEXPORT void JNICALL Java_ai_rapids_cudf_CuFileReadHandle_readIntoBuffer(JNIEn * @param path The file path to write to. * @return Pointer address to the new file handle wrapper instance. */ -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_CuFileWriteHandle_create(JNIEnv *env, jclass, - jstring path) { +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_CuFileWriteHandle_create(JNIEnv* env, + jclass, + jstring path) +{ try { cudf::jni::auto_set_device(env); auto file = cufile_file::make_writer(env->GetStringUTFChars(path, nullptr)); @@ -405,11 +417,12 @@ JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_CuFileWriteHandle_create(JNIEnv *env * @param size Number of bytes to write. */ JNIEXPORT void JNICALL Java_ai_rapids_cudf_CuFileWriteHandle_writeFromBuffer( - JNIEnv *env, jclass, jlong file, jlong file_offset, jlong buffer, jlong size) { + JNIEnv* env, jclass, jlong file, jlong file_offset, jlong buffer, jlong size) +{ try { cudf::jni::auto_set_device(env); - auto *file_ptr = reinterpret_cast(file); - auto *buffer_ptr = reinterpret_cast(buffer); + auto* file_ptr = reinterpret_cast(file); + auto* buffer_ptr = reinterpret_cast(buffer); file_ptr->write(*buffer_ptr, size, file_offset); } CATCH_STD(env, ); @@ -424,14 +437,13 @@ JNIEXPORT void JNICALL Java_ai_rapids_cudf_CuFileWriteHandle_writeFromBuffer( * @param size Number of bytes to append * @return The file offset from which the buffer was appended. */ -JNIEXPORT long JNICALL Java_ai_rapids_cudf_CuFileWriteHandle_appendFromBuffer(JNIEnv *env, jclass, - jlong file, - jlong buffer, - jlong size) { +JNIEXPORT long JNICALL Java_ai_rapids_cudf_CuFileWriteHandle_appendFromBuffer( + JNIEnv* env, jclass, jlong file, jlong buffer, jlong size) +{ try { cudf::jni::auto_set_device(env); - auto *file_ptr = reinterpret_cast(file); - auto *buffer_ptr = reinterpret_cast(buffer); + auto* file_ptr = reinterpret_cast(file); + auto* buffer_ptr = reinterpret_cast(buffer); return file_ptr->append(*buffer_ptr, size); } CATCH_STD(env, -1); @@ -443,11 +455,11 @@ JNIEXPORT long JNICALL Java_ai_rapids_cudf_CuFileWriteHandle_appendFromBuffer(JN * @param env The JNI environment. * @param pointer Pointer address to the file handle wrapper instance. */ -JNIEXPORT void JNICALL Java_ai_rapids_cudf_CuFileHandle_destroy(JNIEnv *env, jclass, - jlong pointer) { +JNIEXPORT void JNICALL Java_ai_rapids_cudf_CuFileHandle_destroy(JNIEnv* env, jclass, jlong pointer) +{ try { cudf::jni::auto_set_device(env); - delete reinterpret_cast(pointer); + delete reinterpret_cast(pointer); } CATCH_STD(env, ); } @@ -461,12 +473,12 @@ JNIEXPORT void JNICALL Java_ai_rapids_cudf_CuFileHandle_destroy(JNIEnv *env, jcl * @param device_pointer Pointer address to the device buffer. * @param size Number of bytes to write. */ -JNIEXPORT void JNICALL Java_ai_rapids_cudf_CuFile_writeToFile(JNIEnv *env, jclass, jstring path, - jlong file_offset, - jlong device_pointer, jlong size) { +JNIEXPORT void JNICALL Java_ai_rapids_cudf_CuFile_writeToFile( + JNIEnv* env, jclass, jstring path, jlong file_offset, jlong device_pointer, jlong size) +{ try { cudf::jni::auto_set_device(env); - cufile_buffer buffer{reinterpret_cast(device_pointer), static_cast(size)}; + cufile_buffer buffer{reinterpret_cast(device_pointer), static_cast(size)}; auto writer = cufile_file::make_writer(env->GetStringUTFChars(path, nullptr)); writer->write(buffer, size, file_offset); } @@ -482,11 +494,12 @@ JNIEXPORT void JNICALL Java_ai_rapids_cudf_CuFile_writeToFile(JNIEnv *env, jclas * @param size Number of bytes to append. * @return The file offset from which the buffer was appended. */ -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_CuFile_appendToFile(JNIEnv *env, jclass, jstring path, - jlong device_pointer, jlong size) { +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_CuFile_appendToFile( + JNIEnv* env, jclass, jstring path, jlong device_pointer, jlong size) +{ try { cudf::jni::auto_set_device(env); - cufile_buffer buffer{reinterpret_cast(device_pointer), static_cast(size)}; + cufile_buffer buffer{reinterpret_cast(device_pointer), static_cast(size)}; auto writer = cufile_file::make_writer(env->GetStringUTFChars(path, nullptr)); return writer->append(buffer, size); } @@ -502,16 +515,16 @@ JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_CuFile_appendToFile(JNIEnv *env, jcl * @param path Absolute path of the file to copy from. * @param file_offset The file offset from which to copy content. */ -JNIEXPORT void JNICALL Java_ai_rapids_cudf_CuFile_readFromFile(JNIEnv *env, jclass, - jlong device_pointer, jlong size, - jstring path, jlong file_offset) { +JNIEXPORT void JNICALL Java_ai_rapids_cudf_CuFile_readFromFile( + JNIEnv* env, jclass, jlong device_pointer, jlong size, jstring path, jlong file_offset) +{ try { cudf::jni::auto_set_device(env); - cufile_buffer buffer{reinterpret_cast(device_pointer), static_cast(size)}; + cufile_buffer buffer{reinterpret_cast(device_pointer), static_cast(size)}; auto const reader = cufile_file::make_reader(env->GetStringUTFChars(path, nullptr)); reader->read(buffer, file_offset); } CATCH_STD(env, ); } -} // extern "C" +} // extern "C" diff --git a/java/src/main/native/src/CudaJni.cpp b/java/src/main/native/src/CudaJni.cpp index 2fe550cdfeb..127a750db43 100644 --- a/java/src/main/native/src/CudaJni.cpp +++ b/java/src/main/native/src/CudaJni.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019-2022, NVIDIA CORPORATION. + * Copyright (c) 2019-2024, NVIDIA CORPORATION. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,6 +15,7 @@ */ #include + #include #ifdef CUDF_JNI_ENABLE_PROFILING @@ -30,21 +31,20 @@ int Cudf_device{cudaInvalidDeviceId}; thread_local int Thread_device = cudaInvalidDeviceId; -} // anonymous namespace +} // anonymous namespace namespace cudf { namespace jni { /** Set the device to use for cudf */ -void set_cudf_device(int device) { - Cudf_device = device; -} +void set_cudf_device(int device) { Cudf_device = device; } /** * If a cudf device has been specified then this ensures the calling thread * is using the same device. */ -void auto_set_device(JNIEnv *env) { +void auto_set_device(JNIEnv* env) +{ if (Cudf_device != cudaInvalidDeviceId) { if (Thread_device != Cudf_device) { cudaError_t cuda_status = cudaSetDevice(Cudf_device); @@ -55,17 +55,19 @@ void auto_set_device(JNIEnv *env) { } /** Fills all the bytes in the buffer 'buf' with 'value'. */ -void device_memset_async(JNIEnv *env, rmm::device_buffer &buf, char value) { - cudaError_t cuda_status = cudaMemsetAsync((void *)buf.data(), value, buf.size()); +void device_memset_async(JNIEnv* env, rmm::device_buffer& buf, char value) +{ + cudaError_t cuda_status = cudaMemsetAsync((void*)buf.data(), value, buf.size()); jni_cuda_check(env, cuda_status); } -} // namespace jni -} // namespace cudf +} // namespace jni +} // namespace cudf extern "C" { -JNIEXPORT jobject JNICALL Java_ai_rapids_cudf_Cuda_memGetInfo(JNIEnv *env, jclass clazz) { +JNIEXPORT jobject JNICALL Java_ai_rapids_cudf_Cuda_memGetInfo(JNIEnv* env, jclass clazz) +{ try { cudf::jni::auto_set_device(env); @@ -73,14 +75,10 @@ JNIEXPORT jobject JNICALL Java_ai_rapids_cudf_Cuda_memGetInfo(JNIEnv *env, jclas CUDF_CUDA_TRY(cudaMemGetInfo(&free, &total)); jclass info_class = env->FindClass("Lai/rapids/cudf/CudaMemInfo;"); - if (info_class == NULL) { - return NULL; - } + if (info_class == NULL) { return NULL; } jmethodID ctor_id = env->GetMethodID(info_class, "", "(JJ)V"); - if (ctor_id == NULL) { - return NULL; - } + if (ctor_id == NULL) { return NULL; } jobject info_obj = env->NewObject(info_class, ctor_id, (jlong)free, (jlong)total); // No need to check for exceptions of null return value as we are just handing the object back @@ -90,46 +88,51 @@ JNIEXPORT jobject JNICALL Java_ai_rapids_cudf_Cuda_memGetInfo(JNIEnv *env, jclas CATCH_STD(env, nullptr); } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Cuda_hostAllocPinned(JNIEnv *env, jclass, jlong size) { +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Cuda_hostAllocPinned(JNIEnv* env, jclass, jlong size) +{ try { cudf::jni::auto_set_device(env); - void *ret = nullptr; + void* ret = nullptr; CUDF_CUDA_TRY(cudaMallocHost(&ret, size)); return reinterpret_cast(ret); } CATCH_STD(env, 0); } -JNIEXPORT void JNICALL Java_ai_rapids_cudf_Cuda_freePinned(JNIEnv *env, jclass, jlong ptr) { +JNIEXPORT void JNICALL Java_ai_rapids_cudf_Cuda_freePinned(JNIEnv* env, jclass, jlong ptr) +{ try { cudf::jni::auto_set_device(env); - CUDF_CUDA_TRY(cudaFreeHost(reinterpret_cast(ptr))); + CUDF_CUDA_TRY(cudaFreeHost(reinterpret_cast(ptr))); } CATCH_STD(env, ); } -JNIEXPORT void JNICALL Java_ai_rapids_cudf_Cuda_memset(JNIEnv *env, jclass, jlong dst, jbyte value, - jlong count, jint kind) { +JNIEXPORT void JNICALL +Java_ai_rapids_cudf_Cuda_memset(JNIEnv* env, jclass, jlong dst, jbyte value, jlong count, jint kind) +{ JNI_NULL_CHECK(env, dst, "dst memory pointer is null", ); try { cudf::jni::auto_set_device(env); - CUDF_CUDA_TRY(cudaMemsetAsync((void *)dst, value, count)); + CUDF_CUDA_TRY(cudaMemsetAsync((void*)dst, value, count)); CUDF_CUDA_TRY(cudaStreamSynchronize(0)); } CATCH_STD(env, ); } -JNIEXPORT void JNICALL Java_ai_rapids_cudf_Cuda_asyncMemset(JNIEnv *env, jclass, jlong dst, - jbyte value, jlong count, jint kind) { +JNIEXPORT void JNICALL Java_ai_rapids_cudf_Cuda_asyncMemset( + JNIEnv* env, jclass, jlong dst, jbyte value, jlong count, jint kind) +{ JNI_NULL_CHECK(env, dst, "dst memory pointer is null", ); try { cudf::jni::auto_set_device(env); - CUDF_CUDA_TRY(cudaMemsetAsync((void *)dst, value, count)); + CUDF_CUDA_TRY(cudaMemsetAsync((void*)dst, value, count)); } CATCH_STD(env, ); } -JNIEXPORT jint JNICALL Java_ai_rapids_cudf_Cuda_getDevice(JNIEnv *env, jclass) { +JNIEXPORT jint JNICALL Java_ai_rapids_cudf_Cuda_getDevice(JNIEnv* env, jclass) +{ try { cudf::jni::auto_set_device(env); jint dev; @@ -139,7 +142,8 @@ JNIEXPORT jint JNICALL Java_ai_rapids_cudf_Cuda_getDevice(JNIEnv *env, jclass) { CATCH_STD(env, -2); } -JNIEXPORT jint JNICALL Java_ai_rapids_cudf_Cuda_getDeviceCount(JNIEnv *env, jclass) { +JNIEXPORT jint JNICALL Java_ai_rapids_cudf_Cuda_getDeviceCount(JNIEnv* env, jclass) +{ try { cudf::jni::auto_set_device(env); jint count; @@ -149,25 +153,28 @@ JNIEXPORT jint JNICALL Java_ai_rapids_cudf_Cuda_getDeviceCount(JNIEnv *env, jcla CATCH_STD(env, -2); } -JNIEXPORT void JNICALL Java_ai_rapids_cudf_Cuda_setDevice(JNIEnv *env, jclass, jint dev) { +JNIEXPORT void JNICALL Java_ai_rapids_cudf_Cuda_setDevice(JNIEnv* env, jclass, jint dev) +{ try { if (Cudf_device != cudaInvalidDeviceId && dev != Cudf_device) { - cudf::jni::throw_java_exception(env, cudf::jni::CUDF_ERROR_CLASS, - "Cannot change device after RMM init"); + cudf::jni::throw_java_exception( + env, cudf::jni::CUDF_ERROR_CLASS, "Cannot change device after RMM init"); } CUDF_CUDA_TRY(cudaSetDevice(dev)); } CATCH_STD(env, ); } -JNIEXPORT void JNICALL Java_ai_rapids_cudf_Cuda_autoSetDevice(JNIEnv *env, jclass, jint dev) { +JNIEXPORT void JNICALL Java_ai_rapids_cudf_Cuda_autoSetDevice(JNIEnv* env, jclass, jint dev) +{ try { cudf::jni::auto_set_device(env); } CATCH_STD(env, ); } -JNIEXPORT jint JNICALL Java_ai_rapids_cudf_Cuda_getDriverVersion(JNIEnv *env, jclass) { +JNIEXPORT jint JNICALL Java_ai_rapids_cudf_Cuda_getDriverVersion(JNIEnv* env, jclass) +{ try { cudf::jni::auto_set_device(env); jint driver_version; @@ -177,7 +184,8 @@ JNIEXPORT jint JNICALL Java_ai_rapids_cudf_Cuda_getDriverVersion(JNIEnv *env, jc CATCH_STD(env, -2); } -JNIEXPORT jint JNICALL Java_ai_rapids_cudf_Cuda_getRuntimeVersion(JNIEnv *env, jclass) { +JNIEXPORT jint JNICALL Java_ai_rapids_cudf_Cuda_getRuntimeVersion(JNIEnv* env, jclass) +{ try { cudf::jni::auto_set_device(env); jint runtime_version; @@ -187,7 +195,8 @@ JNIEXPORT jint JNICALL Java_ai_rapids_cudf_Cuda_getRuntimeVersion(JNIEnv *env, j CATCH_STD(env, -2); } -JNIEXPORT jint JNICALL Java_ai_rapids_cudf_Cuda_getNativeComputeMode(JNIEnv *env, jclass) { +JNIEXPORT jint JNICALL Java_ai_rapids_cudf_Cuda_getNativeComputeMode(JNIEnv* env, jclass) +{ try { cudf::jni::auto_set_device(env); int device; @@ -199,33 +208,36 @@ JNIEXPORT jint JNICALL Java_ai_rapids_cudf_Cuda_getNativeComputeMode(JNIEnv *env CATCH_STD(env, -2); } -JNIEXPORT jint JNICALL Java_ai_rapids_cudf_Cuda_getComputeCapabilityMajor(JNIEnv *env, jclass) { +JNIEXPORT jint JNICALL Java_ai_rapids_cudf_Cuda_getComputeCapabilityMajor(JNIEnv* env, jclass) +{ try { cudf::jni::auto_set_device(env); int device; CUDF_CUDA_TRY(::cudaGetDevice(&device)); int attribute_value; CUDF_CUDA_TRY( - ::cudaDeviceGetAttribute(&attribute_value, ::cudaDevAttrComputeCapabilityMajor, device)); + ::cudaDeviceGetAttribute(&attribute_value, ::cudaDevAttrComputeCapabilityMajor, device)); return attribute_value; } CATCH_STD(env, -2); } -JNIEXPORT jint JNICALL Java_ai_rapids_cudf_Cuda_getComputeCapabilityMinor(JNIEnv *env, jclass) { +JNIEXPORT jint JNICALL Java_ai_rapids_cudf_Cuda_getComputeCapabilityMinor(JNIEnv* env, jclass) +{ try { cudf::jni::auto_set_device(env); int device; CUDF_CUDA_TRY(::cudaGetDevice(&device)); int attribute_value; CUDF_CUDA_TRY( - ::cudaDeviceGetAttribute(&attribute_value, ::cudaDevAttrComputeCapabilityMinor, device)); + ::cudaDeviceGetAttribute(&attribute_value, ::cudaDevAttrComputeCapabilityMinor, device)); return attribute_value; } CATCH_STD(env, -2); } -JNIEXPORT void JNICALL Java_ai_rapids_cudf_Cuda_freeZero(JNIEnv *env, jclass) { +JNIEXPORT void JNICALL Java_ai_rapids_cudf_Cuda_freeZero(JNIEnv* env, jclass) +{ try { cudf::jni::auto_set_device(env); CUDF_CUDA_TRY(cudaFree(0)); @@ -233,19 +245,22 @@ JNIEXPORT void JNICALL Java_ai_rapids_cudf_Cuda_freeZero(JNIEnv *env, jclass) { CATCH_STD(env, ); } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Cuda_createStream(JNIEnv *env, jclass, - jboolean isNonBlocking) { +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Cuda_createStream(JNIEnv* env, + jclass, + jboolean isNonBlocking) +{ try { cudf::jni::auto_set_device(env); cudaStream_t stream = nullptr; - auto flags = isNonBlocking ? cudaStreamNonBlocking : cudaStreamDefault; + auto flags = isNonBlocking ? cudaStreamNonBlocking : cudaStreamDefault; CUDF_CUDA_TRY(cudaStreamCreateWithFlags(&stream, flags)); return reinterpret_cast(stream); } CATCH_STD(env, 0); } -JNIEXPORT void JNICALL Java_ai_rapids_cudf_Cuda_destroyStream(JNIEnv *env, jclass, jlong jstream) { +JNIEXPORT void JNICALL Java_ai_rapids_cudf_Cuda_destroyStream(JNIEnv* env, jclass, jlong jstream) +{ try { cudf::jni::auto_set_device(env); auto stream = reinterpret_cast(jstream); @@ -254,19 +269,24 @@ JNIEXPORT void JNICALL Java_ai_rapids_cudf_Cuda_destroyStream(JNIEnv *env, jclas CATCH_STD(env, ); } -JNIEXPORT void JNICALL Java_ai_rapids_cudf_Cuda_streamWaitEvent(JNIEnv *env, jclass, jlong jstream, - jlong jevent) { +JNIEXPORT void JNICALL Java_ai_rapids_cudf_Cuda_streamWaitEvent(JNIEnv* env, + jclass, + jlong jstream, + jlong jevent) +{ try { cudf::jni::auto_set_device(env); auto stream = reinterpret_cast(jstream); - auto event = reinterpret_cast(jevent); + auto event = reinterpret_cast(jevent); CUDF_CUDA_TRY(cudaStreamWaitEvent(stream, event, 0)); } CATCH_STD(env, ); } -JNIEXPORT void JNICALL Java_ai_rapids_cudf_Cuda_streamSynchronize(JNIEnv *env, jclass, - jlong jstream) { +JNIEXPORT void JNICALL Java_ai_rapids_cudf_Cuda_streamSynchronize(JNIEnv* env, + jclass, + jlong jstream) +{ try { cudf::jni::auto_set_device(env); auto stream = reinterpret_cast(jstream); @@ -275,26 +295,25 @@ JNIEXPORT void JNICALL Java_ai_rapids_cudf_Cuda_streamSynchronize(JNIEnv *env, j CATCH_STD(env, ); } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Cuda_createEvent(JNIEnv *env, jclass, +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Cuda_createEvent(JNIEnv* env, + jclass, jboolean enableTiming, - jboolean blockingSync) { + jboolean blockingSync) +{ try { cudf::jni::auto_set_device(env); - cudaEvent_t event = nullptr; + cudaEvent_t event = nullptr; unsigned int flags = 0; - if (!enableTiming) { - flags = flags | cudaEventDisableTiming; - } - if (blockingSync) { - flags = flags | cudaEventBlockingSync; - } + if (!enableTiming) { flags = flags | cudaEventDisableTiming; } + if (blockingSync) { flags = flags | cudaEventBlockingSync; } CUDF_CUDA_TRY(cudaEventCreateWithFlags(&event, flags)); return reinterpret_cast(event); } CATCH_STD(env, 0); } -JNIEXPORT void JNICALL Java_ai_rapids_cudf_Cuda_destroyEvent(JNIEnv *env, jclass, jlong jevent) { +JNIEXPORT void JNICALL Java_ai_rapids_cudf_Cuda_destroyEvent(JNIEnv* env, jclass, jlong jevent) +{ try { cudf::jni::auto_set_device(env); auto event = reinterpret_cast(jevent); @@ -303,35 +322,39 @@ JNIEXPORT void JNICALL Java_ai_rapids_cudf_Cuda_destroyEvent(JNIEnv *env, jclass CATCH_STD(env, ); } -JNIEXPORT jboolean JNICALL Java_ai_rapids_cudf_Cuda_eventQuery(JNIEnv *env, jclass, jlong jevent) { +JNIEXPORT jboolean JNICALL Java_ai_rapids_cudf_Cuda_eventQuery(JNIEnv* env, jclass, jlong jevent) +{ try { cudf::jni::auto_set_device(env); - auto event = reinterpret_cast(jevent); + auto event = reinterpret_cast(jevent); auto result = cudaEventQuery(event); if (result == cudaSuccess) { return true; } else if (result == cudaErrorNotReady) { return false; - } // else + } // else CUDF_CUDA_TRY(result); } CATCH_STD(env, false); return false; } -JNIEXPORT void JNICALL Java_ai_rapids_cudf_Cuda_eventRecord(JNIEnv *env, jclass, jlong jevent, - jlong jstream) { +JNIEXPORT void JNICALL Java_ai_rapids_cudf_Cuda_eventRecord(JNIEnv* env, + jclass, + jlong jevent, + jlong jstream) +{ try { cudf::jni::auto_set_device(env); - auto event = reinterpret_cast(jevent); + auto event = reinterpret_cast(jevent); auto stream = reinterpret_cast(jstream); CUDF_CUDA_TRY(cudaEventRecord(event, stream)); } CATCH_STD(env, ); } -JNIEXPORT void JNICALL Java_ai_rapids_cudf_Cuda_eventSynchronize(JNIEnv *env, jclass, - jlong jevent) { +JNIEXPORT void JNICALL Java_ai_rapids_cudf_Cuda_eventSynchronize(JNIEnv* env, jclass, jlong jevent) +{ try { cudf::jni::auto_set_device(env); auto event = reinterpret_cast(jevent); @@ -340,19 +363,17 @@ JNIEXPORT void JNICALL Java_ai_rapids_cudf_Cuda_eventSynchronize(JNIEnv *env, jc CATCH_STD(env, ); } -JNIEXPORT void JNICALL Java_ai_rapids_cudf_Cuda_memcpyOnStream(JNIEnv *env, jclass, jlong jdst, - jlong jsrc, jlong count, jint jkind, - jlong jstream) { - if (count == 0) { - return; - } +JNIEXPORT void JNICALL Java_ai_rapids_cudf_Cuda_memcpyOnStream( + JNIEnv* env, jclass, jlong jdst, jlong jsrc, jlong count, jint jkind, jlong jstream) +{ + if (count == 0) { return; } JNI_ARG_CHECK(env, jdst != 0, "dst memory pointer is null", ); JNI_ARG_CHECK(env, jsrc != 0, "src memory pointer is null", ); try { cudf::jni::auto_set_device(env); - auto dst = reinterpret_cast(jdst); - auto src = reinterpret_cast(jsrc); - auto kind = static_cast(jkind); + auto dst = reinterpret_cast(jdst); + auto src = reinterpret_cast(jsrc); + auto kind = static_cast(jkind); auto stream = reinterpret_cast(jstream); CUDF_CUDA_TRY(cudaMemcpyAsync(dst, src, count, kind, stream)); CUDF_CUDA_TRY(cudaStreamSynchronize(stream)); @@ -360,50 +381,51 @@ JNIEXPORT void JNICALL Java_ai_rapids_cudf_Cuda_memcpyOnStream(JNIEnv *env, jcla CATCH_STD(env, ); } -JNIEXPORT void JNICALL Java_ai_rapids_cudf_Cuda_asyncMemcpyOnStream(JNIEnv *env, jclass, jlong jdst, - jlong jsrc, jlong count, - jint jkind, jlong jstream) { - if (count == 0) { - return; - } +JNIEXPORT void JNICALL Java_ai_rapids_cudf_Cuda_asyncMemcpyOnStream( + JNIEnv* env, jclass, jlong jdst, jlong jsrc, jlong count, jint jkind, jlong jstream) +{ + if (count == 0) { return; } JNI_ARG_CHECK(env, jdst != 0, "dst memory pointer is null", ); JNI_ARG_CHECK(env, jsrc != 0, "src memory pointer is null", ); try { cudf::jni::auto_set_device(env); - auto dst = reinterpret_cast(jdst); - auto src = reinterpret_cast(jsrc); - auto kind = static_cast(jkind); + auto dst = reinterpret_cast(jdst); + auto src = reinterpret_cast(jsrc); + auto kind = static_cast(jkind); auto stream = reinterpret_cast(jstream); CUDF_CUDA_TRY(cudaMemcpyAsync(dst, src, count, kind, stream)); } CATCH_STD(env, ); } -JNIEXPORT void JNICALL Java_ai_rapids_cudf_Cuda_profilerStart(JNIEnv *env, jclass clazz) { +JNIEXPORT void JNICALL Java_ai_rapids_cudf_Cuda_profilerStart(JNIEnv* env, jclass clazz) +{ #ifdef CUDF_JNI_ENABLE_PROFILING try { cudaProfilerStart(); } CATCH_STD(env, ); #else - cudf::jni::throw_java_exception(env, cudf::jni::CUDF_ERROR_CLASS, - "This library was built without CUDA profiler support."); + cudf::jni::throw_java_exception( + env, cudf::jni::CUDF_ERROR_CLASS, "This library was built without CUDA profiler support."); #endif } -JNIEXPORT void JNICALL Java_ai_rapids_cudf_Cuda_profilerStop(JNIEnv *env, jclass clazz) { +JNIEXPORT void JNICALL Java_ai_rapids_cudf_Cuda_profilerStop(JNIEnv* env, jclass clazz) +{ #ifdef CUDF_JNI_ENABLE_PROFILING try { cudaProfilerStop(); } CATCH_STD(env, ); #else - cudf::jni::throw_java_exception(env, cudf::jni::CUDF_ERROR_CLASS, - "This library was built without CUDA profiler support."); + cudf::jni::throw_java_exception( + env, cudf::jni::CUDF_ERROR_CLASS, "This library was built without CUDA profiler support."); #endif } -JNIEXPORT void JNICALL Java_ai_rapids_cudf_Cuda_deviceSynchronize(JNIEnv *env, jclass clazz) { +JNIEXPORT void JNICALL Java_ai_rapids_cudf_Cuda_deviceSynchronize(JNIEnv* env, jclass clazz) +{ try { cudf::jni::auto_set_device(env); CUDF_CUDA_TRY(cudaDeviceSynchronize()); @@ -411,4 +433,4 @@ JNIEXPORT void JNICALL Java_ai_rapids_cudf_Cuda_deviceSynchronize(JNIEnv *env, j CATCH_STD(env, ); } -} // extern "C" +} // extern "C" diff --git a/java/src/main/native/src/CudfJni.cpp b/java/src/main/native/src/CudfJni.cpp index d0a25d449a6..698a8f6ff02 100644 --- a/java/src/main/native/src/CudfJni.cpp +++ b/java/src/main/native/src/CudfJni.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019-2023, NVIDIA CORPORATION. + * Copyright (c) 2019-2024, NVIDIA CORPORATION. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,27 +14,27 @@ * limitations under the License. */ -#include +#include "cudf_jni_apis.hpp" #include #include -#include "cudf_jni_apis.hpp" +#include namespace { // handles detaching a thread from the JVM when the thread terminates class jvm_detach_on_destruct { -public: - explicit jvm_detach_on_destruct(JavaVM *jvm) : jvm{jvm} {} + public: + explicit jvm_detach_on_destruct(JavaVM* jvm) : jvm{jvm} {} ~jvm_detach_on_destruct() { jvm->DetachCurrentThread(); } -private: - JavaVM *jvm; + private: + JavaVM* jvm; }; -} // anonymous namespace +} // anonymous namespace namespace cudf { namespace jni { @@ -49,74 +49,70 @@ static jclass Host_memory_buffer_jclass; static jfieldID Host_buffer_address; static jfieldID Host_buffer_length; -#define HOST_MEMORY_BUFFER_CLASS "ai/rapids/cudf/HostMemoryBuffer" +#define HOST_MEMORY_BUFFER_CLASS "ai/rapids/cudf/HostMemoryBuffer" #define HOST_MEMORY_BUFFER_SIG(param_sig) "(" param_sig ")L" HOST_MEMORY_BUFFER_CLASS ";" -static bool cache_host_memory_buffer_jni(JNIEnv *env) { +static bool cache_host_memory_buffer_jni(JNIEnv* env) +{ jclass cls = env->FindClass(HOST_MEMORY_BUFFER_CLASS); - if (cls == nullptr) { - return false; - } + if (cls == nullptr) { return false; } Host_buffer_address = env->GetFieldID(cls, "address", "J"); - if (Host_buffer_address == nullptr) { - return false; - } + if (Host_buffer_address == nullptr) { return false; } Host_buffer_length = env->GetFieldID(cls, "length", "J"); - if (Host_buffer_length == nullptr) { - return false; - } + if (Host_buffer_length == nullptr) { return false; } // Convert local reference to global so it cannot be garbage collected. Host_memory_buffer_jclass = static_cast(env->NewGlobalRef(cls)); - if (Host_memory_buffer_jclass == nullptr) { - return false; - } + if (Host_memory_buffer_jclass == nullptr) { return false; } return true; } -static void release_host_memory_buffer_jni(JNIEnv *env) { +static void release_host_memory_buffer_jni(JNIEnv* env) +{ Host_memory_buffer_jclass = del_global_ref(env, Host_memory_buffer_jclass); } -jobject allocate_host_buffer(JNIEnv *env, jlong amount, jboolean prefer_pinned, - jobject host_memory_allocator) { +jobject allocate_host_buffer(JNIEnv* env, + jlong amount, + jboolean prefer_pinned, + jobject host_memory_allocator) +{ auto const host_memory_allocator_class = env->GetObjectClass(host_memory_allocator); auto const allocateMethodId = - env->GetMethodID(host_memory_allocator_class, "allocate", HOST_MEMORY_BUFFER_SIG("JZ")); + env->GetMethodID(host_memory_allocator_class, "allocate", HOST_MEMORY_BUFFER_SIG("JZ")); jobject ret = - env->CallObjectMethod(host_memory_allocator, allocateMethodId, amount, prefer_pinned); + env->CallObjectMethod(host_memory_allocator, allocateMethodId, amount, prefer_pinned); - if (env->ExceptionCheck()) { - throw std::runtime_error("allocateHostBuffer threw an exception"); - } + if (env->ExceptionCheck()) { throw std::runtime_error("allocateHostBuffer threw an exception"); } return ret; } -jlong get_host_buffer_address(JNIEnv *env, jobject buffer) { +jlong get_host_buffer_address(JNIEnv* env, jobject buffer) +{ return env->GetLongField(buffer, Host_buffer_address); } -jlong get_host_buffer_length(JNIEnv *env, jobject buffer) { +jlong get_host_buffer_length(JNIEnv* env, jobject buffer) +{ return env->GetLongField(buffer, Host_buffer_length); } // Get the JNI environment, attaching the current thread to the JVM if necessary. If the thread // needs to be attached, the thread will automatically detach when the thread terminates. -JNIEnv *get_jni_env(JavaVM *jvm) { - JNIEnv *env = nullptr; - jint rc = jvm->GetEnv(reinterpret_cast(&env), MINIMUM_JNI_VERSION); - if (rc == JNI_OK) { - return env; - } +JNIEnv* get_jni_env(JavaVM* jvm) +{ + JNIEnv* env = nullptr; + jint rc = jvm->GetEnv(reinterpret_cast(&env), MINIMUM_JNI_VERSION); + if (rc == JNI_OK) { return env; } if (rc == JNI_EDETACHED) { JavaVMAttachArgs attach_args; attach_args.version = MINIMUM_JNI_VERSION; - attach_args.name = const_cast("cudf thread"); - attach_args.group = NULL; + attach_args.name = const_cast("cudf thread"); + attach_args.group = NULL; - if (jvm->AttachCurrentThreadAsDaemon(reinterpret_cast(&env), &attach_args) == JNI_OK) { + if (jvm->AttachCurrentThreadAsDaemon(reinterpret_cast(&env), &attach_args) == JNI_OK) { // use thread_local object to detach the thread from the JVM when thread terminates. thread_local jvm_detach_on_destruct detacher(jvm); } else { @@ -129,14 +125,15 @@ JNIEnv *get_jni_env(JavaVM *jvm) { throw std::runtime_error("error detecting thread attach state with JVM"); } -} // namespace jni -} // namespace cudf +} // namespace jni +} // namespace cudf extern "C" { -JNIEXPORT jint JNI_OnLoad(JavaVM *vm, void *) { - JNIEnv *env; - if (vm->GetEnv(reinterpret_cast(&env), cudf::jni::MINIMUM_JNI_VERSION) != JNI_OK) { +JNIEXPORT jint JNI_OnLoad(JavaVM* vm, void*) +{ + JNIEnv* env; + if (vm->GetEnv(reinterpret_cast(&env), cudf::jni::MINIMUM_JNI_VERSION) != JNI_OK) { return JNI_ERR; } @@ -186,9 +183,10 @@ JNIEXPORT jint JNI_OnLoad(JavaVM *vm, void *) { return cudf::jni::MINIMUM_JNI_VERSION; } -JNIEXPORT void JNI_OnUnload(JavaVM *vm, void *) { - JNIEnv *env = nullptr; - if (vm->GetEnv(reinterpret_cast(&env), cudf::jni::MINIMUM_JNI_VERSION) != JNI_OK) { +JNIEXPORT void JNI_OnUnload(JavaVM* vm, void*) +{ + JNIEnv* env = nullptr; + if (vm->GetEnv(reinterpret_cast(&env), cudf::jni::MINIMUM_JNI_VERSION) != JNI_OK) { return; } @@ -198,8 +196,9 @@ JNIEXPORT void JNI_OnUnload(JavaVM *vm, void *) { cudf::jni::release_host_memory_buffer_jni(env); } -JNIEXPORT jboolean JNICALL Java_ai_rapids_cudf_Cuda_isPtdsEnabled(JNIEnv *env, jclass) { +JNIEXPORT jboolean JNICALL Java_ai_rapids_cudf_Cuda_isPtdsEnabled(JNIEnv* env, jclass) +{ return cudf::jni::is_ptds_enabled; } -} // extern "C" +} // extern "C" diff --git a/java/src/main/native/src/DataSourceHelperJni.cpp b/java/src/main/native/src/DataSourceHelperJni.cpp index 8d0e4d36413..af064a4f428 100644 --- a/java/src/main/native/src/DataSourceHelperJni.cpp +++ b/java/src/main/native/src/DataSourceHelperJni.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023, NVIDIA CORPORATION. + * Copyright (c) 2023-2024, NVIDIA CORPORATION. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,11 +14,11 @@ * limitations under the License. */ -#include - #include "cudf_jni_apis.hpp" #include "jni_utils.hpp" +#include + namespace { #define DATA_SOURCE_CLASS "ai/rapids/cudf/DataSource" @@ -29,136 +29,127 @@ jmethodID hostReadBuff_method; jmethodID onHostBufferDone_method; jmethodID deviceRead_method; -} // anonymous namespace +} // anonymous namespace namespace cudf { namespace jni { -bool cache_data_source_jni(JNIEnv *env) { +bool cache_data_source_jni(JNIEnv* env) +{ jclass cls = env->FindClass(DATA_SOURCE_CLASS); - if (cls == nullptr) { - return false; - } + if (cls == nullptr) { return false; } hostRead_method = env->GetMethodID(cls, "hostRead", "(JJJ)J"); - if (hostRead_method == nullptr) { - return false; - } + if (hostRead_method == nullptr) { return false; } hostReadBuff_method = env->GetMethodID(cls, "hostReadBuff", "(JJ)[J"); - if (hostReadBuff_method == nullptr) { - return false; - } + if (hostReadBuff_method == nullptr) { return false; } onHostBufferDone_method = env->GetMethodID(cls, "onHostBufferDone", "(J)V"); - if (onHostBufferDone_method == nullptr) { - return false; - } + if (onHostBufferDone_method == nullptr) { return false; } deviceRead_method = env->GetMethodID(cls, "deviceRead", "(JJJJ)J"); - if (deviceRead_method == nullptr) { - return false; - } + if (deviceRead_method == nullptr) { return false; } // Convert local reference to global so it cannot be garbage collected. DataSource_jclass = static_cast(env->NewGlobalRef(cls)); - if (DataSource_jclass == nullptr) { - return false; - } + if (DataSource_jclass == nullptr) { return false; } return true; } -void release_data_source_jni(JNIEnv *env) { +void release_data_source_jni(JNIEnv* env) +{ DataSource_jclass = cudf::jni::del_global_ref(env, DataSource_jclass); } class host_buffer_done_callback { -public: - explicit host_buffer_done_callback(JavaVM *jvm, jobject ds, long id) : jvm(jvm), ds(ds), id(id) {} + public: + explicit host_buffer_done_callback(JavaVM* jvm, jobject ds, long id) : jvm(jvm), ds(ds), id(id) {} - host_buffer_done_callback(host_buffer_done_callback const &other) = delete; - host_buffer_done_callback(host_buffer_done_callback &&other) - : jvm(other.jvm), ds(other.ds), id(other.id) { + host_buffer_done_callback(host_buffer_done_callback const& other) = delete; + host_buffer_done_callback(host_buffer_done_callback&& other) + : jvm(other.jvm), ds(other.ds), id(other.id) + { other.jvm = nullptr; - other.ds = nullptr; - other.id = -1; + other.ds = nullptr; + other.id = -1; } - host_buffer_done_callback &operator=(host_buffer_done_callback &&other) = delete; - host_buffer_done_callback &operator=(host_buffer_done_callback const &other) = delete; + host_buffer_done_callback& operator=(host_buffer_done_callback&& other) = delete; + host_buffer_done_callback& operator=(host_buffer_done_callback const& other) = delete; - ~host_buffer_done_callback() { + ~host_buffer_done_callback() + { // because we are in a destructor we cannot throw an exception, so for now we are // just going to keep the java exceptions around and have them be thrown when this // thread returns to the JVM. It might be kind of confusing, but we will not lose // them. if (jvm != nullptr) { // We cannot throw an exception in the destructor, so this is really best effort - JNIEnv *env = nullptr; - if (jvm->GetEnv(reinterpret_cast(&env), cudf::jni::MINIMUM_JNI_VERSION) == JNI_OK) { + JNIEnv* env = nullptr; + if (jvm->GetEnv(reinterpret_cast(&env), cudf::jni::MINIMUM_JNI_VERSION) == JNI_OK) { env->CallVoidMethod(this->ds, onHostBufferDone_method, id); } } } -private: - JavaVM *jvm; + private: + JavaVM* jvm; jobject ds; long id; }; class jni_datasource : public cudf::io::datasource { -public: - explicit jni_datasource(JNIEnv *env, jobject ds, size_t ds_size, bool device_read_supported, - size_t device_read_cutoff) - : ds_size(ds_size), device_read_supported(device_read_supported), - device_read_cutoff(device_read_cutoff) { - if (env->GetJavaVM(&jvm) < 0) { - throw std::runtime_error("GetJavaVM failed"); - } + public: + explicit jni_datasource( + JNIEnv* env, jobject ds, size_t ds_size, bool device_read_supported, size_t device_read_cutoff) + : ds_size(ds_size), + device_read_supported(device_read_supported), + device_read_cutoff(device_read_cutoff) + { + if (env->GetJavaVM(&jvm) < 0) { throw std::runtime_error("GetJavaVM failed"); } this->ds = add_global_ref(env, ds); } - virtual ~jni_datasource() { - JNIEnv *env = nullptr; - if (jvm->GetEnv(reinterpret_cast(&env), cudf::jni::MINIMUM_JNI_VERSION) == JNI_OK) { + virtual ~jni_datasource() + { + JNIEnv* env = nullptr; + if (jvm->GetEnv(reinterpret_cast(&env), cudf::jni::MINIMUM_JNI_VERSION) == JNI_OK) { ds = del_global_ref(env, ds); } ds = nullptr; } - std::unique_ptr host_read(size_t offset, size_t size) override { - JNIEnv *env = nullptr; - if (jvm->GetEnv(reinterpret_cast(&env), cudf::jni::MINIMUM_JNI_VERSION) != JNI_OK) { + std::unique_ptr host_read(size_t offset, size_t size) override + { + JNIEnv* env = nullptr; + if (jvm->GetEnv(reinterpret_cast(&env), cudf::jni::MINIMUM_JNI_VERSION) != JNI_OK) { throw cudf::jni::jni_exception("Could not load JNIEnv"); } jlongArray jbuffer_info = - static_cast(env->CallObjectMethod(this->ds, hostReadBuff_method, offset, size)); - if (env->ExceptionOccurred()) { - throw cudf::jni::jni_exception("Java exception in hostRead"); - } + static_cast(env->CallObjectMethod(this->ds, hostReadBuff_method, offset, size)); + if (env->ExceptionOccurred()) { throw cudf::jni::jni_exception("Java exception in hostRead"); } cudf::jni::native_jlongArray buffer_info(env, jbuffer_info); - auto ptr = reinterpret_cast(buffer_info[0]); + auto ptr = reinterpret_cast(buffer_info[0]); size_t length = buffer_info[1]; - long id = buffer_info[2]; + long id = buffer_info[2]; cudf::jni::host_buffer_done_callback cb(this->jvm, this->ds, id); - return std::make_unique>(std::move(cb), ptr, - length); + return std::make_unique>( + std::move(cb), ptr, length); } - size_t host_read(size_t offset, size_t size, uint8_t *dst) override { - JNIEnv *env = nullptr; - if (jvm->GetEnv(reinterpret_cast(&env), cudf::jni::MINIMUM_JNI_VERSION) != JNI_OK) { + size_t host_read(size_t offset, size_t size, uint8_t* dst) override + { + JNIEnv* env = nullptr; + if (jvm->GetEnv(reinterpret_cast(&env), cudf::jni::MINIMUM_JNI_VERSION) != JNI_OK) { throw cudf::jni::jni_exception("Could not load JNIEnv"); } jlong amount_read = - env->CallLongMethod(this->ds, hostRead_method, offset, size, reinterpret_cast(dst)); - if (env->ExceptionOccurred()) { - throw cudf::jni::jni_exception("Java exception in hostRead"); - } + env->CallLongMethod(this->ds, hostRead_method, offset, size, reinterpret_cast(dst)); + if (env->ExceptionOccurred()) { throw cudf::jni::jni_exception("Java exception in hostRead"); } return amount_read; } @@ -166,28 +157,38 @@ class jni_datasource : public cudf::io::datasource { bool supports_device_read() const override { return device_read_supported; } - bool is_device_read_preferred(size_t size) const override { + bool is_device_read_preferred(size_t size) const override + { return device_read_supported && size >= device_read_cutoff; } - size_t device_read(size_t offset, size_t size, uint8_t *dst, - rmm::cuda_stream_view stream) override { - JNIEnv *env = nullptr; - if (jvm->GetEnv(reinterpret_cast(&env), cudf::jni::MINIMUM_JNI_VERSION) != JNI_OK) { + size_t device_read(size_t offset, + size_t size, + uint8_t* dst, + rmm::cuda_stream_view stream) override + { + JNIEnv* env = nullptr; + if (jvm->GetEnv(reinterpret_cast(&env), cudf::jni::MINIMUM_JNI_VERSION) != JNI_OK) { throw cudf::jni::jni_exception("Could not load JNIEnv"); } - jlong amount_read = - env->CallLongMethod(this->ds, deviceRead_method, offset, size, reinterpret_cast(dst), - reinterpret_cast(stream.value())); + jlong amount_read = env->CallLongMethod(this->ds, + deviceRead_method, + offset, + size, + reinterpret_cast(dst), + reinterpret_cast(stream.value())); if (env->ExceptionOccurred()) { throw cudf::jni::jni_exception("Java exception in deviceRead"); } return amount_read; } - std::future device_read_async(size_t offset, size_t size, uint8_t *dst, - rmm::cuda_stream_view stream) override { + std::future device_read_async(size_t offset, + size_t size, + uint8_t* dst, + rmm::cuda_stream_view stream) override + { auto amount_read = device_read(offset, size, dst, stream); // This is a bit ugly, but we don't have a good way or a need to return // a future for the read @@ -196,42 +197,48 @@ class jni_datasource : public cudf::io::datasource { return ret.get_future(); } -private: + private: size_t ds_size; bool device_read_supported; size_t device_read_cutoff; - JavaVM *jvm; + JavaVM* jvm; jobject ds; }; -} // namespace jni -} // namespace cudf +} // namespace jni +} // namespace cudf extern "C" { -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_DataSourceHelper_createWrapperDataSource( - JNIEnv *env, jclass, jobject ds, jlong ds_size, jboolean device_read_supported, - jlong device_read_cutoff) { +JNIEXPORT jlong JNICALL +Java_ai_rapids_cudf_DataSourceHelper_createWrapperDataSource(JNIEnv* env, + jclass, + jobject ds, + jlong ds_size, + jboolean device_read_supported, + jlong device_read_cutoff) +{ JNI_NULL_CHECK(env, ds, "Null data source", 0); try { cudf::jni::auto_set_device(env); auto source = - new cudf::jni::jni_datasource(env, ds, ds_size, device_read_supported, device_read_cutoff); + new cudf::jni::jni_datasource(env, ds, ds_size, device_read_supported, device_read_cutoff); return reinterpret_cast(source); } CATCH_STD(env, 0); } -JNIEXPORT void JNICALL Java_ai_rapids_cudf_DataSourceHelper_destroyWrapperDataSource(JNIEnv *env, +JNIEXPORT void JNICALL Java_ai_rapids_cudf_DataSourceHelper_destroyWrapperDataSource(JNIEnv* env, jclass, - jlong handle) { + jlong handle) +{ try { cudf::jni::auto_set_device(env); if (handle != 0) { - auto source = reinterpret_cast(handle); + auto source = reinterpret_cast(handle); delete (source); } } CATCH_STD(env, ); } -} // extern "C" +} // extern "C" diff --git a/java/src/main/native/src/HashJoinJni.cpp b/java/src/main/native/src/HashJoinJni.cpp index 0f78aef64bc..d4aa08e9a2d 100644 --- a/java/src/main/native/src/HashJoinJni.cpp +++ b/java/src/main/native/src/HashJoinJni.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, NVIDIA CORPORATION. + * Copyright (c) 2021-2024, NVIDIA CORPORATION. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,32 +14,36 @@ * limitations under the License. */ -#include - #include "cudf_jni_apis.hpp" +#include + extern "C" { -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_HashJoin_create(JNIEnv *env, jclass, jlong j_table, - jboolean j_nulls_equal) { +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_HashJoin_create(JNIEnv* env, + jclass, + jlong j_table, + jboolean j_nulls_equal) +{ JNI_NULL_CHECK(env, j_table, "table handle is null", 0); try { cudf::jni::auto_set_device(env); - auto tview = reinterpret_cast(j_table); - auto nulleq = j_nulls_equal ? cudf::null_equality::EQUAL : cudf::null_equality::UNEQUAL; + auto tview = reinterpret_cast(j_table); + auto nulleq = j_nulls_equal ? cudf::null_equality::EQUAL : cudf::null_equality::UNEQUAL; auto hash_join_ptr = new cudf::hash_join(*tview, nulleq); return reinterpret_cast(hash_join_ptr); } CATCH_STD(env, 0); } -JNIEXPORT void JNICALL Java_ai_rapids_cudf_HashJoin_destroy(JNIEnv *env, jclass, jlong j_handle) { +JNIEXPORT void JNICALL Java_ai_rapids_cudf_HashJoin_destroy(JNIEnv* env, jclass, jlong j_handle) +{ try { cudf::jni::auto_set_device(env); - auto hash_join_ptr = reinterpret_cast(j_handle); + auto hash_join_ptr = reinterpret_cast(j_handle); delete hash_join_ptr; } CATCH_STD(env, ); } -} // extern "C" +} // extern "C" diff --git a/java/src/main/native/src/HostMemoryBufferNativeUtilsJni.cpp b/java/src/main/native/src/HostMemoryBufferNativeUtilsJni.cpp index f9e05d27798..b175920ab4e 100644 --- a/java/src/main/native/src/HostMemoryBufferNativeUtilsJni.cpp +++ b/java/src/main/native/src/HostMemoryBufferNativeUtilsJni.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019-2021, NVIDIA CORPORATION. + * Copyright (c) 2019-2024, NVIDIA CORPORATION. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,40 +14,39 @@ * limitations under the License. */ +#include "jni_utils.hpp" + #include #include #include #include -#include - #include #include - -#include "jni_utils.hpp" +#include extern "C" { JNIEXPORT jobject JNICALL Java_ai_rapids_cudf_HostMemoryBufferNativeUtils_wrapRangeInBuffer( - JNIEnv *env, jclass, jlong addr, jlong len) { - return env->NewDirectByteBuffer(reinterpret_cast(addr), len); + JNIEnv* env, jclass, jlong addr, jlong len) +{ + return env->NewDirectByteBuffer(reinterpret_cast(addr), len); } JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_HostMemoryBufferNativeUtils_mmap( - JNIEnv *env, jclass, jstring jpath, jint mode, jlong offset, jlong length) { + JNIEnv* env, jclass, jstring jpath, jint mode, jlong offset, jlong length) +{ JNI_NULL_CHECK(env, jpath, "path is null", 0); JNI_ARG_CHECK(env, (mode == 0 || mode == 1), "bad mode value", 0); try { cudf::jni::native_jstring path(env, jpath); int fd = open(path.get(), (mode == 0) ? O_RDONLY : O_RDWR); - if (fd == -1) { - cudf::jni::throw_java_exception(env, "java/io/IOException", strerror(errno)); - } + if (fd == -1) { cudf::jni::throw_java_exception(env, "java/io/IOException", strerror(errno)); } - void *address = mmap(NULL, length, (mode == 0) ? PROT_READ : PROT_READ | PROT_WRITE, MAP_SHARED, - fd, offset); + void* address = + mmap(NULL, length, (mode == 0) ? PROT_READ : PROT_READ | PROT_WRITE, MAP_SHARED, fd, offset); if (address == MAP_FAILED) { - char const *error_msg = strerror(errno); + char const* error_msg = strerror(errno); close(fd); cudf::jni::throw_java_exception(env, "java/io/IOException", error_msg); } @@ -58,17 +57,17 @@ JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_HostMemoryBufferNativeUtils_mmap( CATCH_STD(env, 0); } -JNIEXPORT void JNICALL Java_ai_rapids_cudf_HostMemoryBufferNativeUtils_munmap(JNIEnv *env, jclass, +JNIEXPORT void JNICALL Java_ai_rapids_cudf_HostMemoryBufferNativeUtils_munmap(JNIEnv* env, + jclass, jlong address, - jlong length) { + jlong length) +{ JNI_NULL_CHECK(env, address, "address is NULL", ); try { - int rc = munmap(reinterpret_cast(address), length); - if (rc == -1) { - cudf::jni::throw_java_exception(env, "java/io/IOException", strerror(errno)); - } + int rc = munmap(reinterpret_cast(address), length); + if (rc == -1) { cudf::jni::throw_java_exception(env, "java/io/IOException", strerror(errno)); } } CATCH_STD(env, ); } -} // extern "C" +} // extern "C" diff --git a/java/src/main/native/src/NvcompJni.cpp b/java/src/main/native/src/NvcompJni.cpp index e616b7f66be..47a24653549 100644 --- a/java/src/main/native/src/NvcompJni.cpp +++ b/java/src/main/native/src/NvcompJni.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020-2022, NVIDIA CORPORATION. + * Copyright (c) 2020-2024, NVIDIA CORPORATION. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,22 +13,23 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include +#include "check_nvcomp_output_sizes.hpp" +#include "cudf_jni_apis.hpp" -#include #include -#include "check_nvcomp_output_sizes.hpp" -#include "cudf_jni_apis.hpp" +#include +#include namespace { -constexpr char const *NVCOMP_ERROR_CLASS = "ai/rapids/cudf/nvcomp/NvcompException"; -constexpr char const *NVCOMP_CUDA_ERROR_CLASS = "ai/rapids/cudf/nvcomp/NvcompCudaException"; -constexpr char const *ILLEGAL_ARG_CLASS = "java/lang/IllegalArgumentException"; -constexpr char const *UNSUPPORTED_CLASS = "java/lang/UnsupportedOperationException"; +constexpr char const* NVCOMP_ERROR_CLASS = "ai/rapids/cudf/nvcomp/NvcompException"; +constexpr char const* NVCOMP_CUDA_ERROR_CLASS = "ai/rapids/cudf/nvcomp/NvcompCudaException"; +constexpr char const* ILLEGAL_ARG_CLASS = "java/lang/IllegalArgumentException"; +constexpr char const* UNSUPPORTED_CLASS = "java/lang/UnsupportedOperationException"; -void check_nvcomp_status(JNIEnv *env, nvcompStatus_t status) { +void check_nvcomp_status(JNIEnv* env, nvcompStatus_t status) +{ switch (status) { case nvcompSuccess: break; case nvcompErrorInvalidValue: @@ -52,19 +53,20 @@ void check_nvcomp_status(JNIEnv *env, nvcompStatus_t status) { } } -} // anonymous namespace +} // anonymous namespace extern "C" { JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_nvcomp_NvcompJni_batchedLZ4CompressGetTempSize( - JNIEnv *env, jclass, jlong j_batch_size, jlong j_max_chunk_size) { + JNIEnv* env, jclass, jlong j_batch_size, jlong j_max_chunk_size) +{ try { cudf::jni::auto_set_device(env); - auto batch_size = static_cast(j_batch_size); - auto max_chunk_size = static_cast(j_max_chunk_size); + auto batch_size = static_cast(j_batch_size); + auto max_chunk_size = static_cast(j_max_chunk_size); std::size_t temp_size = 0; - auto status = nvcompBatchedLZ4CompressGetTempSize(batch_size, max_chunk_size, - nvcompBatchedLZ4DefaultOpts, &temp_size); + auto status = nvcompBatchedLZ4CompressGetTempSize( + batch_size, max_chunk_size, nvcompBatchedLZ4DefaultOpts, &temp_size); check_nvcomp_status(env, status); return static_cast(temp_size); } @@ -72,49 +74,68 @@ JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_nvcomp_NvcompJni_batchedLZ4CompressG } JNIEXPORT jlong JNICALL -Java_ai_rapids_cudf_nvcomp_NvcompJni_batchedLZ4CompressGetMaxOutputChunkSize( - JNIEnv *env, jclass, jlong j_max_chunk_size) { +Java_ai_rapids_cudf_nvcomp_NvcompJni_batchedLZ4CompressGetMaxOutputChunkSize(JNIEnv* env, + jclass, + jlong j_max_chunk_size) +{ try { cudf::jni::auto_set_device(env); - auto max_chunk_size = static_cast(j_max_chunk_size); + auto max_chunk_size = static_cast(j_max_chunk_size); std::size_t max_output_size = 0; - auto status = nvcompBatchedLZ4CompressGetMaxOutputChunkSize( - max_chunk_size, nvcompBatchedLZ4DefaultOpts, &max_output_size); + auto status = nvcompBatchedLZ4CompressGetMaxOutputChunkSize( + max_chunk_size, nvcompBatchedLZ4DefaultOpts, &max_output_size); check_nvcomp_status(env, status); return static_cast(max_output_size); } CATCH_STD(env, 0); } -JNIEXPORT void JNICALL Java_ai_rapids_cudf_nvcomp_NvcompJni_batchedLZ4CompressAsync( - JNIEnv *env, jclass, jlong j_in_ptrs, jlong j_in_sizes, jlong j_chunk_size, jlong j_batch_size, - jlong j_temp_ptr, jlong j_temp_size, jlong j_out_ptrs, jlong j_compressed_sizes_out_ptr, - jlong j_stream) { +JNIEXPORT void JNICALL +Java_ai_rapids_cudf_nvcomp_NvcompJni_batchedLZ4CompressAsync(JNIEnv* env, + jclass, + jlong j_in_ptrs, + jlong j_in_sizes, + jlong j_chunk_size, + jlong j_batch_size, + jlong j_temp_ptr, + jlong j_temp_size, + jlong j_out_ptrs, + jlong j_compressed_sizes_out_ptr, + jlong j_stream) +{ try { cudf::jni::auto_set_device(env); - auto in_ptrs = reinterpret_cast(j_in_ptrs); - auto in_sizes = reinterpret_cast(j_in_sizes); - auto chunk_size = static_cast(j_chunk_size); - auto batch_size = static_cast(j_batch_size); - auto temp_ptr = reinterpret_cast(j_temp_ptr); - auto temp_size = static_cast(j_temp_size); - auto out_ptrs = reinterpret_cast(j_out_ptrs); - auto compressed_out_sizes = reinterpret_cast(j_compressed_sizes_out_ptr); - auto stream = reinterpret_cast(j_stream); - auto status = nvcompBatchedLZ4CompressAsync(in_ptrs, in_sizes, chunk_size, batch_size, temp_ptr, - temp_size, out_ptrs, compressed_out_sizes, - nvcompBatchedLZ4DefaultOpts, stream); + auto in_ptrs = reinterpret_cast(j_in_ptrs); + auto in_sizes = reinterpret_cast(j_in_sizes); + auto chunk_size = static_cast(j_chunk_size); + auto batch_size = static_cast(j_batch_size); + auto temp_ptr = reinterpret_cast(j_temp_ptr); + auto temp_size = static_cast(j_temp_size); + auto out_ptrs = reinterpret_cast(j_out_ptrs); + auto compressed_out_sizes = reinterpret_cast(j_compressed_sizes_out_ptr); + auto stream = reinterpret_cast(j_stream); + auto status = nvcompBatchedLZ4CompressAsync(in_ptrs, + in_sizes, + chunk_size, + batch_size, + temp_ptr, + temp_size, + out_ptrs, + compressed_out_sizes, + nvcompBatchedLZ4DefaultOpts, + stream); check_nvcomp_status(env, status); } CATCH_STD(env, ); } JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_nvcomp_NvcompJni_batchedLZ4DecompressGetTempSize( - JNIEnv *env, jclass, jlong j_batch_size, jlong j_chunk_size) { + JNIEnv* env, jclass, jlong j_batch_size, jlong j_chunk_size) +{ try { cudf::jni::auto_set_device(env); - auto batch_size = static_cast(j_batch_size); - auto chunk_size = static_cast(j_chunk_size); + auto batch_size = static_cast(j_batch_size); + auto chunk_size = static_cast(j_chunk_size); std::size_t temp_size = 0; auto status = nvcompBatchedLZ4DecompressGetTempSize(batch_size, chunk_size, &temp_size); check_nvcomp_status(env, status); @@ -123,49 +144,71 @@ JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_nvcomp_NvcompJni_batchedLZ4Decompres CATCH_STD(env, 0); } -JNIEXPORT void JNICALL Java_ai_rapids_cudf_nvcomp_NvcompJni_batchedLZ4DecompressAsync( - JNIEnv *env, jclass, jlong j_in_ptrs, jlong j_in_sizes, jlong j_out_sizes, jlong j_batch_size, - jlong j_temp_ptr, jlong j_temp_size, jlong j_out_ptrs, jlong j_stream) { +JNIEXPORT void JNICALL +Java_ai_rapids_cudf_nvcomp_NvcompJni_batchedLZ4DecompressAsync(JNIEnv* env, + jclass, + jlong j_in_ptrs, + jlong j_in_sizes, + jlong j_out_sizes, + jlong j_batch_size, + jlong j_temp_ptr, + jlong j_temp_size, + jlong j_out_ptrs, + jlong j_stream) +{ try { cudf::jni::auto_set_device(env); - auto compressed_ptrs = reinterpret_cast(j_in_ptrs); - auto compressed_sizes = reinterpret_cast(j_in_sizes); - auto uncompressed_sizes = reinterpret_cast(j_out_sizes); - auto batch_size = static_cast(j_batch_size); - auto temp_ptr = reinterpret_cast(j_temp_ptr); - auto temp_size = static_cast(j_temp_size); - auto uncompressed_ptrs = reinterpret_cast(j_out_ptrs); - auto stream = reinterpret_cast(j_stream); - auto uncompressed_statuses = rmm::device_uvector(batch_size, stream); + auto compressed_ptrs = reinterpret_cast(j_in_ptrs); + auto compressed_sizes = reinterpret_cast(j_in_sizes); + auto uncompressed_sizes = reinterpret_cast(j_out_sizes); + auto batch_size = static_cast(j_batch_size); + auto temp_ptr = reinterpret_cast(j_temp_ptr); + auto temp_size = static_cast(j_temp_size); + auto uncompressed_ptrs = reinterpret_cast(j_out_ptrs); + auto stream = reinterpret_cast(j_stream); + auto uncompressed_statuses = rmm::device_uvector(batch_size, stream); auto actual_uncompressed_sizes = rmm::device_uvector(batch_size, stream); - auto status = nvcompBatchedLZ4DecompressAsync( - compressed_ptrs, compressed_sizes, uncompressed_sizes, actual_uncompressed_sizes.data(), - batch_size, temp_ptr, temp_size, uncompressed_ptrs, uncompressed_statuses.data(), stream); + auto status = nvcompBatchedLZ4DecompressAsync(compressed_ptrs, + compressed_sizes, + uncompressed_sizes, + actual_uncompressed_sizes.data(), + batch_size, + temp_ptr, + temp_size, + uncompressed_ptrs, + uncompressed_statuses.data(), + stream); check_nvcomp_status(env, status); - if (!cudf::java::check_nvcomp_output_sizes(uncompressed_sizes, actual_uncompressed_sizes.data(), - batch_size, stream)) { - cudf::jni::throw_java_exception(env, NVCOMP_ERROR_CLASS, - "nvcomp decompress output size mismatch"); + if (!cudf::java::check_nvcomp_output_sizes( + uncompressed_sizes, actual_uncompressed_sizes.data(), batch_size, stream)) { + cudf::jni::throw_java_exception( + env, NVCOMP_ERROR_CLASS, "nvcomp decompress output size mismatch"); } } CATCH_STD(env, ); } -JNIEXPORT void JNICALL Java_ai_rapids_cudf_nvcomp_NvcompJni_batchedLZ4GetDecompressSizeAsync( - JNIEnv *env, jclass, jlong j_in_ptrs, jlong j_in_sizes, jlong j_out_sizes, jlong j_batch_size, - jlong j_stream) { +JNIEXPORT void JNICALL +Java_ai_rapids_cudf_nvcomp_NvcompJni_batchedLZ4GetDecompressSizeAsync(JNIEnv* env, + jclass, + jlong j_in_ptrs, + jlong j_in_sizes, + jlong j_out_sizes, + jlong j_batch_size, + jlong j_stream) +{ try { cudf::jni::auto_set_device(env); - auto compressed_ptrs = reinterpret_cast(j_in_ptrs); - auto compressed_sizes = reinterpret_cast(j_in_sizes); - auto uncompressed_sizes = reinterpret_cast(j_out_sizes); - auto batch_size = static_cast(j_batch_size); - auto stream = reinterpret_cast(j_stream); - auto status = nvcompBatchedLZ4GetDecompressSizeAsync(compressed_ptrs, compressed_sizes, - uncompressed_sizes, batch_size, stream); + auto compressed_ptrs = reinterpret_cast(j_in_ptrs); + auto compressed_sizes = reinterpret_cast(j_in_sizes); + auto uncompressed_sizes = reinterpret_cast(j_out_sizes); + auto batch_size = static_cast(j_batch_size); + auto stream = reinterpret_cast(j_stream); + auto status = nvcompBatchedLZ4GetDecompressSizeAsync( + compressed_ptrs, compressed_sizes, uncompressed_sizes, batch_size, stream); check_nvcomp_status(env, status); } CATCH_STD(env, ); } -} // extern "C" +} // extern "C" diff --git a/java/src/main/native/src/NvtxRangeJni.cpp b/java/src/main/native/src/NvtxRangeJni.cpp index 2529acfb91d..4ba6be31b87 100644 --- a/java/src/main/native/src/NvtxRangeJni.cpp +++ b/java/src/main/native/src/NvtxRangeJni.cpp @@ -14,15 +14,18 @@ * limitations under the License. */ -#include - #include "jni_utils.hpp" #include "nvtx_common.hpp" +#include + extern "C" { -JNIEXPORT void JNICALL Java_ai_rapids_cudf_NvtxRange_push(JNIEnv *env, jclass clazz, jstring name, - jint color_bits) { +JNIEXPORT void JNICALL Java_ai_rapids_cudf_NvtxRange_push(JNIEnv* env, + jclass clazz, + jstring name, + jint color_bits) +{ try { cudf::jni::native_jstring range_name(env, name); nvtx3::color range_color(static_cast(color_bits)); @@ -32,11 +35,12 @@ JNIEXPORT void JNICALL Java_ai_rapids_cudf_NvtxRange_push(JNIEnv *env, jclass cl CATCH_STD(env, ); } -JNIEXPORT void JNICALL Java_ai_rapids_cudf_NvtxRange_pop(JNIEnv *env, jclass clazz) { +JNIEXPORT void JNICALL Java_ai_rapids_cudf_NvtxRange_pop(JNIEnv* env, jclass clazz) +{ try { nvtxDomainRangePop(nvtx3::domain::get()); } CATCH_STD(env, ); } -} // extern "C" +} // extern "C" diff --git a/java/src/main/native/src/NvtxUniqueRangeJni.cpp b/java/src/main/native/src/NvtxUniqueRangeJni.cpp index 924b5a564e6..2ff96f96497 100644 --- a/java/src/main/native/src/NvtxUniqueRangeJni.cpp +++ b/java/src/main/native/src/NvtxUniqueRangeJni.cpp @@ -14,28 +14,33 @@ * limitations under the License. */ -#include - #include "jni_utils.hpp" #include "nvtx_common.hpp" +#include + extern "C" { -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_NvtxUniqueRange_start(JNIEnv *env, jclass clazz, - jstring name, jint color_bits) { +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_NvtxUniqueRange_start(JNIEnv* env, + jclass clazz, + jstring name, + jint color_bits) +{ try { cudf::jni::native_jstring range_name(env, name); nvtx3::color range_color(static_cast(color_bits)); nvtx3::event_attributes attr{range_color, range_name.get()}; auto nvtxRangeId = - nvtxDomainRangeStartEx(nvtx3::domain::get(), attr.get()); + nvtxDomainRangeStartEx(nvtx3::domain::get(), attr.get()); return static_cast(nvtxRangeId); } CATCH_STD(env, 0); } -JNIEXPORT void JNICALL Java_ai_rapids_cudf_NvtxUniqueRange_end(JNIEnv *env, jclass clazz, - jlong nvtxRangeId) { +JNIEXPORT void JNICALL Java_ai_rapids_cudf_NvtxUniqueRange_end(JNIEnv* env, + jclass clazz, + jlong nvtxRangeId) +{ try { nvtxDomainRangeEnd(nvtx3::domain::get(), static_cast(nvtxRangeId)); @@ -43,4 +48,4 @@ JNIEXPORT void JNICALL Java_ai_rapids_cudf_NvtxUniqueRange_end(JNIEnv *env, jcla CATCH_STD(env, ); } -} // extern "C" +} // extern "C" diff --git a/java/src/main/native/src/PackedColumnMetadataJni.cpp b/java/src/main/native/src/PackedColumnMetadataJni.cpp index 7ec3e1294ce..c7c95558e71 100644 --- a/java/src/main/native/src/PackedColumnMetadataJni.cpp +++ b/java/src/main/native/src/PackedColumnMetadataJni.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023, NVIDIA CORPORATION. + * Copyright (c) 2023-2024, NVIDIA CORPORATION. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,23 +19,26 @@ extern "C" { JNIEXPORT jobject JNICALL Java_ai_rapids_cudf_PackedColumnMetadata_createMetadataDirectBuffer( - JNIEnv *env, jclass, jlong j_metadata_ptr) { + JNIEnv* env, jclass, jlong j_metadata_ptr) +{ JNI_NULL_CHECK(env, j_metadata_ptr, "metadata is null", nullptr); try { - auto metadata = reinterpret_cast *>(j_metadata_ptr); - return env->NewDirectByteBuffer(const_cast(metadata->data()), metadata->size()); + auto metadata = reinterpret_cast*>(j_metadata_ptr); + return env->NewDirectByteBuffer(const_cast(metadata->data()), metadata->size()); } CATCH_STD(env, nullptr); } -JNIEXPORT void JNICALL -Java_ai_rapids_cudf_PackedColumnMetadata_closeMetadata(JNIEnv *env, jclass, jlong j_metadata_ptr) { +JNIEXPORT void JNICALL Java_ai_rapids_cudf_PackedColumnMetadata_closeMetadata(JNIEnv* env, + jclass, + jlong j_metadata_ptr) +{ JNI_NULL_CHECK(env, j_metadata_ptr, "metadata is null", ); try { - auto metadata = reinterpret_cast *>(j_metadata_ptr); + auto metadata = reinterpret_cast*>(j_metadata_ptr); delete metadata; } CATCH_STD(env, ); } -} // extern "C" +} // extern "C" diff --git a/java/src/main/native/src/RmmJni.cpp b/java/src/main/native/src/RmmJni.cpp index 8d7ac8890cc..68453c924d6 100644 --- a/java/src/main/native/src/RmmJni.cpp +++ b/java/src/main/native/src/RmmJni.cpp @@ -14,14 +14,10 @@ * limitations under the License. */ -#include -#include -#include -#include -#include -#include +#include "cudf_jni_apis.hpp" #include + #include #include #include @@ -36,7 +32,12 @@ #include #include -#include "cudf_jni_apis.hpp" +#include +#include +#include +#include +#include +#include using rmm::mr::device_memory_resource; using rmm::mr::logging_resource_adaptor; @@ -44,14 +45,14 @@ using rmm_pinned_pool_t = rmm::mr::pool_memory_resource class tracking_resource_adaptor final : public base_tracking_resource_adaptor { -public: + public: /** * @brief Constructs a new tracking resource adaptor that delegates to * `mr` for all allocation operations while tracking the amount of memory @@ -81,28 +82,32 @@ class tracking_resource_adaptor final : public base_tracking_resource_adaptor { * @param size_alignment The alignment to which the `mr` resource will * round up all memory allocation size requests. */ - tracking_resource_adaptor(Upstream *mr, std::size_t size_alignment) - : resource{mr}, size_align{size_alignment} {} + tracking_resource_adaptor(Upstream* mr, std::size_t size_alignment) + : resource{mr}, size_align{size_alignment} + { + } - Upstream *get_wrapped_resource() { return resource; } + Upstream* get_wrapped_resource() { return resource; } std::size_t get_total_allocated() override { return total_allocated.load(); } std::size_t get_max_total_allocated() override { return max_total_allocated; } - void reset_scoped_max_total_allocated(std::size_t initial_value) override { + void reset_scoped_max_total_allocated(std::size_t initial_value) override + { std::scoped_lock lock(max_total_allocated_mutex); - scoped_allocated = initial_value; + scoped_allocated = initial_value; scoped_max_total_allocated = initial_value; } - std::size_t get_scoped_max_total_allocated() override { + std::size_t get_scoped_max_total_allocated() override + { std::scoped_lock lock(max_total_allocated_mutex); return scoped_max_total_allocated; } -private: - Upstream *const resource; + private: + Upstream* const resource; std::size_t const size_align; // sum of what is currently allocated std::atomic_size_t total_allocated{0}; @@ -120,7 +125,8 @@ class tracking_resource_adaptor final : public base_tracking_resource_adaptor { std::mutex max_total_allocated_mutex; - void *do_allocate(std::size_t num_bytes, rmm::cuda_stream_view stream) override { + void* do_allocate(std::size_t num_bytes, rmm::cuda_stream_view stream) override + { // adjust size of allocation based on specified size alignment num_bytes = (num_bytes + size_align - 1) / size_align * size_align; @@ -129,13 +135,14 @@ class tracking_resource_adaptor final : public base_tracking_resource_adaptor { total_allocated += num_bytes; scoped_allocated += num_bytes; std::scoped_lock lock(max_total_allocated_mutex); - max_total_allocated = std::max(total_allocated.load(), max_total_allocated); + max_total_allocated = std::max(total_allocated.load(), max_total_allocated); scoped_max_total_allocated = std::max(scoped_allocated.load(), scoped_max_total_allocated); } return result; } - void do_deallocate(void *p, std::size_t size, rmm::cuda_stream_view stream) override { + void do_deallocate(void* p, std::size_t size, rmm::cuda_stream_view stream) override + { size = (size + size_align - 1) / size_align * size_align; resource->deallocate(p, size, stream); @@ -148,8 +155,9 @@ class tracking_resource_adaptor final : public base_tracking_resource_adaptor { }; template -tracking_resource_adaptor *make_tracking_adaptor(Upstream *upstream, - std::size_t size_alignment) { +tracking_resource_adaptor* make_tracking_adaptor(Upstream* upstream, + std::size_t size_alignment) +{ return new tracking_resource_adaptor{upstream, size_alignment}; } @@ -158,24 +166,23 @@ tracking_resource_adaptor *make_tracking_adaptor(Upstream *upstream, * for most operations but will call Java to handle certain situations (e.g.: allocation failure). */ class java_event_handler_memory_resource : public device_memory_resource { -public: - java_event_handler_memory_resource(JNIEnv *env, jobject jhandler, jlongArray jalloc_thresholds, + public: + java_event_handler_memory_resource(JNIEnv* env, + jobject jhandler, + jlongArray jalloc_thresholds, jlongArray jdealloc_thresholds, - device_memory_resource *resource_to_wrap, - base_tracking_resource_adaptor *tracker) - : resource(resource_to_wrap), tracker(tracker) { - if (env->GetJavaVM(&jvm) < 0) { - throw std::runtime_error("GetJavaVM failed"); - } + device_memory_resource* resource_to_wrap, + base_tracking_resource_adaptor* tracker) + : resource(resource_to_wrap), tracker(tracker) + { + if (env->GetJavaVM(&jvm) < 0) { throw std::runtime_error("GetJavaVM failed"); } jclass cls = env->GetObjectClass(jhandler); - if (cls == nullptr) { - throw cudf::jni::jni_exception("class not found"); - } + if (cls == nullptr) { throw cudf::jni::jni_exception("class not found"); } on_alloc_fail_method = env->GetMethodID(cls, "onAllocFailure", "(JI)Z"); if (on_alloc_fail_method == nullptr) { use_old_alloc_fail_interface = true; - on_alloc_fail_method = env->GetMethodID(cls, "onAllocFailure", "(J)Z"); + on_alloc_fail_method = env->GetMethodID(cls, "onAllocFailure", "(J)Z"); if (on_alloc_fail_method == nullptr) { throw cudf::jni::jni_exception("onAllocFailure method"); } @@ -197,22 +204,23 @@ class java_event_handler_memory_resource : public device_memory_resource { handler_obj = cudf::jni::add_global_ref(env, jhandler); } - virtual ~java_event_handler_memory_resource() { + virtual ~java_event_handler_memory_resource() + { // This should normally be called by a JVM thread. If the JVM environment is missing then this // is likely being triggered by the C++ runtime during shutdown. In that case the JVM may // already be destroyed and this thread should not try to attach to get an environment. - JNIEnv *env = nullptr; - if (jvm->GetEnv(reinterpret_cast(&env), cudf::jni::MINIMUM_JNI_VERSION) == JNI_OK) { + JNIEnv* env = nullptr; + if (jvm->GetEnv(reinterpret_cast(&env), cudf::jni::MINIMUM_JNI_VERSION) == JNI_OK) { handler_obj = cudf::jni::del_global_ref(env, handler_obj); } handler_obj = nullptr; } - device_memory_resource *get_wrapped_resource() { return resource; } + device_memory_resource* get_wrapped_resource() { return resource; } -private: - device_memory_resource *const resource; - base_tracking_resource_adaptor *const tracker; + private: + device_memory_resource* const resource; + base_tracking_resource_adaptor* const tracker; jmethodID on_alloc_fail_method; bool use_old_alloc_fail_interface; jmethodID on_alloc_threshold_method; @@ -222,8 +230,10 @@ class java_event_handler_memory_resource : public device_memory_resource { std::vector alloc_thresholds{}; std::vector dealloc_thresholds{}; - static void update_thresholds(JNIEnv *env, std::vector &thresholds, - jlongArray from_java) { + static void update_thresholds(JNIEnv* env, + std::vector& thresholds, + jlongArray from_java) + { thresholds.clear(); if (from_java != nullptr) { cudf::jni::native_jlongArray jvalues(env, from_java); @@ -234,17 +244,19 @@ class java_event_handler_memory_resource : public device_memory_resource { } } - bool on_alloc_fail(std::size_t num_bytes, int retry_count) { - JNIEnv *env = cudf::jni::get_jni_env(jvm); + bool on_alloc_fail(std::size_t num_bytes, int retry_count) + { + JNIEnv* env = cudf::jni::get_jni_env(jvm); jboolean result = false; if (!use_old_alloc_fail_interface) { - result = - env->CallBooleanMethod(handler_obj, on_alloc_fail_method, static_cast(num_bytes), - static_cast(retry_count)); + result = env->CallBooleanMethod(handler_obj, + on_alloc_fail_method, + static_cast(num_bytes), + static_cast(retry_count)); } else { result = - env->CallBooleanMethod(handler_obj, on_alloc_fail_method, static_cast(num_bytes)); + env->CallBooleanMethod(handler_obj, on_alloc_fail_method, static_cast(num_bytes)); } if (env->ExceptionCheck()) { throw std::runtime_error("onAllocFailure handler threw an exception"); @@ -252,16 +264,20 @@ class java_event_handler_memory_resource : public device_memory_resource { return result; } - void check_for_threshold_callback(std::size_t low, std::size_t high, - std::vector const &thresholds, - jmethodID callback_method, char const *callback_name, - std::size_t current_total) { + void check_for_threshold_callback(std::size_t low, + std::size_t high, + std::vector const& thresholds, + jmethodID callback_method, + char const* callback_name, + std::size_t current_total) + { if (high >= thresholds.front() && low < thresholds.back()) { // could use binary search, but assumption is threshold count is very small - auto it = std::find_if(thresholds.begin(), thresholds.end(), - [=](std::size_t t) -> bool { return low < t && high >= t; }); + auto it = std::find_if(thresholds.begin(), thresholds.end(), [=](std::size_t t) -> bool { + return low < t && high >= t; + }); if (it != thresholds.end()) { - JNIEnv *env = cudf::jni::get_jni_env(jvm); + JNIEnv* env = cudf::jni::get_jni_env(jvm); env->CallVoidMethod(handler_obj, callback_method, current_total); if (env->ExceptionCheck()) { throw std::runtime_error("onAllocThreshold handler threw an exception"); @@ -270,13 +286,14 @@ class java_event_handler_memory_resource : public device_memory_resource { } } -protected: - JavaVM *jvm; + protected: + JavaVM* jvm; jobject handler_obj; - void *do_allocate(std::size_t num_bytes, rmm::cuda_stream_view stream) override { + void* do_allocate(std::size_t num_bytes, rmm::cuda_stream_view stream) override + { std::size_t total_before; - void *result; + void* result; // a non-zero retry_count signifies that the `on_alloc_fail` // callback is being invoked while re-attempting an allocation // that had previously failed. @@ -284,20 +301,22 @@ class java_event_handler_memory_resource : public device_memory_resource { while (true) { try { total_before = tracker->get_total_allocated(); - result = resource->allocate(num_bytes, stream); + result = resource->allocate(num_bytes, stream); break; - } catch (rmm::out_of_memory const &e) { - if (!on_alloc_fail(num_bytes, retry_count++)) { - throw; - } + } catch (rmm::out_of_memory const& e) { + if (!on_alloc_fail(num_bytes, retry_count++)) { throw; } } } auto total_after = tracker->get_total_allocated(); try { - check_for_threshold_callback(total_before, total_after, alloc_thresholds, - on_alloc_threshold_method, "onAllocThreshold", total_after); - } catch (std::exception const &e) { + check_for_threshold_callback(total_before, + total_after, + alloc_thresholds, + on_alloc_threshold_method, + "onAllocThreshold", + total_after); + } catch (std::exception const& e) { // Free the allocation as app will think the exception means the memory was not allocated. resource->deallocate(result, num_bytes, stream); throw; @@ -306,33 +325,36 @@ class java_event_handler_memory_resource : public device_memory_resource { return result; } - void do_deallocate(void *p, std::size_t size, rmm::cuda_stream_view stream) override { + void do_deallocate(void* p, std::size_t size, rmm::cuda_stream_view stream) override + { auto total_before = tracker->get_total_allocated(); resource->deallocate(p, size, stream); auto total_after = tracker->get_total_allocated(); - check_for_threshold_callback(total_after, total_before, dealloc_thresholds, - on_dealloc_threshold_method, "onDeallocThreshold", total_after); + check_for_threshold_callback(total_after, + total_before, + dealloc_thresholds, + on_dealloc_threshold_method, + "onDeallocThreshold", + total_after); } }; class java_debug_event_handler_memory_resource final : public java_event_handler_memory_resource { -public: - java_debug_event_handler_memory_resource(JNIEnv *env, jobject jhandler, + public: + java_debug_event_handler_memory_resource(JNIEnv* env, + jobject jhandler, jlongArray jalloc_thresholds, jlongArray jdealloc_thresholds, - device_memory_resource *resource_to_wrap, - base_tracking_resource_adaptor *tracker) - : java_event_handler_memory_resource(env, jhandler, jalloc_thresholds, jdealloc_thresholds, - resource_to_wrap, tracker) { + device_memory_resource* resource_to_wrap, + base_tracking_resource_adaptor* tracker) + : java_event_handler_memory_resource( + env, jhandler, jalloc_thresholds, jdealloc_thresholds, resource_to_wrap, tracker) + { jclass cls = env->GetObjectClass(jhandler); - if (cls == nullptr) { - throw cudf::jni::jni_exception("class not found"); - } + if (cls == nullptr) { throw cudf::jni::jni_exception("class not found"); } on_allocated_method = env->GetMethodID(cls, "onAllocated", "(J)V"); - if (on_allocated_method == nullptr) { - throw cudf::jni::jni_exception("onAllocated method"); - } + if (on_allocated_method == nullptr) { throw cudf::jni::jni_exception("onAllocated method"); } on_deallocated_method = env->GetMethodID(cls, "onDeallocated", "(J)V"); if (on_deallocated_method == nullptr) { @@ -340,36 +362,41 @@ class java_debug_event_handler_memory_resource final : public java_event_handler } } -private: + private: jmethodID on_allocated_method; jmethodID on_deallocated_method; - void on_allocated_callback(std::size_t num_bytes, rmm::cuda_stream_view stream) { - JNIEnv *env = cudf::jni::get_jni_env(jvm); + void on_allocated_callback(std::size_t num_bytes, rmm::cuda_stream_view stream) + { + JNIEnv* env = cudf::jni::get_jni_env(jvm); env->CallVoidMethod(handler_obj, on_allocated_method, num_bytes); if (env->ExceptionCheck()) { throw std::runtime_error("onAllocated handler threw an exception"); } } - void on_deallocated_callback(void *p, std::size_t size, rmm::cuda_stream_view stream) { - JNIEnv *env = cudf::jni::get_jni_env(jvm); + void on_deallocated_callback(void* p, std::size_t size, rmm::cuda_stream_view stream) + { + JNIEnv* env = cudf::jni::get_jni_env(jvm); env->CallVoidMethod(handler_obj, on_deallocated_method, size); } - void *do_allocate(std::size_t num_bytes, rmm::cuda_stream_view stream) override { - void *result = java_event_handler_memory_resource::do_allocate(num_bytes, stream); + void* do_allocate(std::size_t num_bytes, rmm::cuda_stream_view stream) override + { + void* result = java_event_handler_memory_resource::do_allocate(num_bytes, stream); on_allocated_callback(num_bytes, stream); return result; } - void do_deallocate(void *p, std::size_t size, rmm::cuda_stream_view stream) override { + void do_deallocate(void* p, std::size_t size, rmm::cuda_stream_view stream) override + { java_event_handler_memory_resource::do_deallocate(p, size, stream); on_deallocated_callback(p, size, stream); } }; -inline auto &prior_cuio_host_mr() { +inline auto& prior_cuio_host_mr() +{ static rmm::host_async_resource_ref _prior_cuio_host_mr = cudf::io::get_host_memory_resource(); return _prior_cuio_host_mr; } @@ -384,18 +411,19 @@ inline auto &prior_cuio_host_mr() { * Most of this comes directly from `pinned_host_memory_resource` in RMM. */ class pinned_fallback_host_memory_resource { -private: - rmm_pinned_pool_t *_pool; - void *pool_begin_; - void *pool_end_; - -public: - pinned_fallback_host_memory_resource(rmm_pinned_pool_t *pool) : _pool(pool) { + private: + rmm_pinned_pool_t* _pool; + void* pool_begin_; + void* pool_end_; + + public: + pinned_fallback_host_memory_resource(rmm_pinned_pool_t* pool) : _pool(pool) + { // allocate from the pinned pool the full size to figure out // our beginning and end address. auto pool_size = pool->pool_size(); - pool_begin_ = pool->allocate(pool_size); - pool_end_ = static_cast(static_cast(pool_begin_) + pool_size); + pool_begin_ = pool->allocate(pool_size); + pool_end_ = static_cast(static_cast(pool_begin_) + pool_size); pool->deallocate(pool_begin_, pool_size); } @@ -415,11 +443,12 @@ class pinned_fallback_host_memory_resource { * * @return Pointer to the newly allocated memory. */ - void *allocate(std::size_t bytes, - [[maybe_unused]] std::size_t alignment = rmm::RMM_DEFAULT_HOST_ALIGNMENT) { + void* allocate(std::size_t bytes, + [[maybe_unused]] std::size_t alignment = rmm::RMM_DEFAULT_HOST_ALIGNMENT) + { try { return _pool->allocate(bytes, alignment); - } catch (const std::exception &unused) { + } catch (const std::exception& unused) { // try to allocate using the underlying pinned resource return prior_cuio_host_mr().allocate(bytes, alignment); } @@ -436,8 +465,10 @@ class pinned_fallback_host_memory_resource { * @param bytes Size of the allocation. * @param alignment Alignment in bytes. Default alignment is used if unspecified. */ - void deallocate(void *ptr, std::size_t bytes, - std::size_t alignment = rmm::RMM_DEFAULT_HOST_ALIGNMENT) noexcept { + void deallocate(void* ptr, + std::size_t bytes, + std::size_t alignment = rmm::RMM_DEFAULT_HOST_ALIGNMENT) noexcept + { if (ptr >= pool_begin_ && ptr <= pool_end_) { _pool->deallocate(ptr, bytes, alignment); } else { @@ -459,7 +490,8 @@ class pinned_fallback_host_memory_resource { * @param stream CUDA stream on which to perform the allocation (ignored). * @return Pointer to the newly allocated memory. */ - void *allocate_async(std::size_t bytes, [[maybe_unused]] cuda::stream_ref stream) { + void* allocate_async(std::size_t bytes, [[maybe_unused]] cuda::stream_ref stream) + { return allocate(bytes); } @@ -478,8 +510,10 @@ class pinned_fallback_host_memory_resource { * @param stream CUDA stream on which to perform the allocation (ignored). * @return Pointer to the newly allocated memory. */ - void *allocate_async(std::size_t bytes, std::size_t alignment, - [[maybe_unused]] cuda::stream_ref stream) { + void* allocate_async(std::size_t bytes, + std::size_t alignment, + [[maybe_unused]] cuda::stream_ref stream) + { return allocate(bytes, alignment); } @@ -492,8 +526,10 @@ class pinned_fallback_host_memory_resource { * @param bytes Size of the allocation. * @param stream CUDA stream on which to perform the deallocation (ignored). */ - void deallocate_async(void *ptr, std::size_t bytes, - [[maybe_unused]] cuda::stream_ref stream) noexcept { + void deallocate_async(void* ptr, + std::size_t bytes, + [[maybe_unused]] cuda::stream_ref stream) noexcept + { return deallocate(ptr, bytes); } @@ -508,8 +544,11 @@ class pinned_fallback_host_memory_resource { * @param alignment Alignment in bytes. * @param stream CUDA stream on which to perform the deallocation (ignored). */ - void deallocate_async(void *ptr, std::size_t bytes, std::size_t alignment, - [[maybe_unused]] cuda::stream_ref stream) noexcept { + void deallocate_async(void* ptr, + std::size_t bytes, + std::size_t alignment, + [[maybe_unused]] cuda::stream_ref stream) noexcept + { return deallocate(ptr, bytes, alignment); } // NOLINTEND(bugprone-easily-swappable-parameters) @@ -517,44 +556,49 @@ class pinned_fallback_host_memory_resource { /** * @briefreturn{true if the specified resource is the same type as this resource.} */ - bool operator==(const pinned_fallback_host_memory_resource &) const { return true; } + bool operator==(const pinned_fallback_host_memory_resource&) const { return true; } /** * @briefreturn{true if the specified resource is not the same type as this resource, otherwise * false.} */ - bool operator!=(const pinned_fallback_host_memory_resource &) const { return false; } + bool operator!=(const pinned_fallback_host_memory_resource&) const { return false; } /** * @brief Enables the `cuda::mr::device_accessible` property * * This property declares that a `pinned_host_memory_resource` provides device accessible memory */ - friend void get_property(pinned_fallback_host_memory_resource const &, - cuda::mr::device_accessible) noexcept {} + friend void get_property(pinned_fallback_host_memory_resource const&, + cuda::mr::device_accessible) noexcept + { + } /** * @brief Enables the `cuda::mr::host_accessible` property * * This property declares that a `pinned_host_memory_resource` provides host accessible memory */ - friend void get_property(pinned_fallback_host_memory_resource const &, - cuda::mr::host_accessible) noexcept {} + friend void get_property(pinned_fallback_host_memory_resource const&, + cuda::mr::host_accessible) noexcept + { + } }; // carryover from RMM pinned_host_memory_resource -static_assert( - cuda::mr::async_resource_with); +static_assert(cuda::mr::async_resource_with); // we set this to our fallback resource if we have set it. std::unique_ptr pinned_fallback_mr; -} // anonymous namespace +} // anonymous namespace extern "C" { -JNIEXPORT void JNICALL Java_ai_rapids_cudf_Rmm_initDefaultCudaDevice(JNIEnv *env, jclass clazz) { +JNIEXPORT void JNICALL Java_ai_rapids_cudf_Rmm_initDefaultCudaDevice(JNIEnv* env, jclass clazz) +{ // make sure the CUDA device is setup in the context cudaError_t cuda_status = cudaFree(0); cudf::jni::jni_cuda_check(env, cuda_status); @@ -566,66 +610,78 @@ JNIEXPORT void JNICALL Java_ai_rapids_cudf_Rmm_initDefaultCudaDevice(JNIEnv *env cudf::jni::set_cudf_device(device_id); } -JNIEXPORT void JNICALL Java_ai_rapids_cudf_Rmm_cleanupDefaultCudaDevice(JNIEnv *env, jclass clazz) { +JNIEXPORT void JNICALL Java_ai_rapids_cudf_Rmm_cleanupDefaultCudaDevice(JNIEnv* env, jclass clazz) +{ cudf::jni::set_cudf_device(cudaInvalidDeviceId); } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Rmm_allocInternal(JNIEnv *env, jclass clazz, jlong size, - jlong stream) { +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Rmm_allocInternal(JNIEnv* env, + jclass clazz, + jlong size, + jlong stream) +{ try { cudf::jni::auto_set_device(env); rmm::device_async_resource_ref mr = rmm::mr::get_current_device_resource(); auto c_stream = rmm::cuda_stream_view(reinterpret_cast(stream)); - void *ret = mr.allocate_async(size, rmm::CUDA_ALLOCATION_ALIGNMENT, c_stream); + void* ret = mr.allocate_async(size, rmm::CUDA_ALLOCATION_ALIGNMENT, c_stream); return reinterpret_cast(ret); } CATCH_STD(env, 0) } -JNIEXPORT void JNICALL Java_ai_rapids_cudf_Rmm_free(JNIEnv *env, jclass clazz, jlong ptr, - jlong size, jlong stream) { +JNIEXPORT void JNICALL +Java_ai_rapids_cudf_Rmm_free(JNIEnv* env, jclass clazz, jlong ptr, jlong size, jlong stream) +{ try { cudf::jni::auto_set_device(env); rmm::device_async_resource_ref mr = rmm::mr::get_current_device_resource(); - void *cptr = reinterpret_cast(ptr); + void* cptr = reinterpret_cast(ptr); auto c_stream = rmm::cuda_stream_view(reinterpret_cast(stream)); mr.deallocate_async(cptr, size, rmm::CUDA_ALLOCATION_ALIGNMENT, c_stream); } CATCH_STD(env, ) } -JNIEXPORT void JNICALL Java_ai_rapids_cudf_Rmm_freeDeviceBuffer(JNIEnv *env, jclass clazz, - jlong ptr) { +JNIEXPORT void JNICALL Java_ai_rapids_cudf_Rmm_freeDeviceBuffer(JNIEnv* env, + jclass clazz, + jlong ptr) +{ try { cudf::jni::auto_set_device(env); - rmm::device_buffer *cptr = reinterpret_cast(ptr); + rmm::device_buffer* cptr = reinterpret_cast(ptr); delete cptr; } CATCH_STD(env, ); } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Rmm_allocCudaInternal(JNIEnv *env, jclass clazz, - jlong size, jlong stream) { +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Rmm_allocCudaInternal(JNIEnv* env, + jclass clazz, + jlong size, + jlong stream) +{ try { cudf::jni::auto_set_device(env); - void *ptr{nullptr}; + void* ptr{nullptr}; RMM_CUDA_TRY_ALLOC(cudaMalloc(&ptr, size)); return reinterpret_cast(ptr); } CATCH_STD(env, 0) } -JNIEXPORT void JNICALL Java_ai_rapids_cudf_Rmm_freeCuda(JNIEnv *env, jclass clazz, jlong ptr, - jlong size, jlong stream) { +JNIEXPORT void JNICALL +Java_ai_rapids_cudf_Rmm_freeCuda(JNIEnv* env, jclass clazz, jlong ptr, jlong size, jlong stream) +{ try { cudf::jni::auto_set_device(env); - void *cptr = reinterpret_cast(ptr); + void* cptr = reinterpret_cast(ptr); RMM_ASSERT_CUDA_SUCCESS(cudaFree(cptr)); } CATCH_STD(env, ) } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Rmm_newCudaMemoryResource(JNIEnv *env, jclass clazz) { +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Rmm_newCudaMemoryResource(JNIEnv* env, jclass clazz) +{ try { cudf::jni::auto_set_device(env); auto ret = new rmm::mr::cuda_memory_resource(); @@ -634,18 +690,20 @@ JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Rmm_newCudaMemoryResource(JNIEnv *en CATCH_STD(env, 0) } -JNIEXPORT void JNICALL Java_ai_rapids_cudf_Rmm_releaseCudaMemoryResource(JNIEnv *env, jclass clazz, - jlong ptr) { +JNIEXPORT void JNICALL Java_ai_rapids_cudf_Rmm_releaseCudaMemoryResource(JNIEnv* env, + jclass clazz, + jlong ptr) +{ try { cudf::jni::auto_set_device(env); - auto mr = reinterpret_cast(ptr); + auto mr = reinterpret_cast(ptr); delete mr; } CATCH_STD(env, ) } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Rmm_newManagedMemoryResource(JNIEnv *env, - jclass clazz) { +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Rmm_newManagedMemoryResource(JNIEnv* env, jclass clazz) +{ try { cudf::jni::auto_set_device(env); auto ret = new rmm::mr::managed_memory_resource(); @@ -654,70 +712,77 @@ JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Rmm_newManagedMemoryResource(JNIEnv CATCH_STD(env, 0) } -JNIEXPORT void JNICALL Java_ai_rapids_cudf_Rmm_releaseManagedMemoryResource(JNIEnv *env, +JNIEXPORT void JNICALL Java_ai_rapids_cudf_Rmm_releaseManagedMemoryResource(JNIEnv* env, jclass clazz, - jlong ptr) { + jlong ptr) +{ try { cudf::jni::auto_set_device(env); - auto mr = reinterpret_cast(ptr); + auto mr = reinterpret_cast(ptr); delete mr; } CATCH_STD(env, ) } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Rmm_newPoolMemoryResource(JNIEnv *env, jclass clazz, - jlong child, jlong init, - jlong max) { +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Rmm_newPoolMemoryResource( + JNIEnv* env, jclass clazz, jlong child, jlong init, jlong max) +{ JNI_NULL_CHECK(env, child, "child is null", 0); try { cudf::jni::auto_set_device(env); - auto wrapped = reinterpret_cast(child); + auto wrapped = reinterpret_cast(child); auto ret = - new rmm::mr::pool_memory_resource(wrapped, init, max); + new rmm::mr::pool_memory_resource(wrapped, init, max); return reinterpret_cast(ret); } CATCH_STD(env, 0) } -JNIEXPORT void JNICALL Java_ai_rapids_cudf_Rmm_releasePoolMemoryResource(JNIEnv *env, jclass clazz, - jlong ptr) { +JNIEXPORT void JNICALL Java_ai_rapids_cudf_Rmm_releasePoolMemoryResource(JNIEnv* env, + jclass clazz, + jlong ptr) +{ try { cudf::jni::auto_set_device(env); auto mr = - reinterpret_cast *>(ptr); + reinterpret_cast*>(ptr); delete mr; } CATCH_STD(env, ) } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Rmm_newArenaMemoryResource(JNIEnv *env, jclass clazz, - jlong child, jlong init, - jboolean dump_on_oom) { +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Rmm_newArenaMemoryResource( + JNIEnv* env, jclass clazz, jlong child, jlong init, jboolean dump_on_oom) +{ JNI_NULL_CHECK(env, child, "child is null", 0); try { cudf::jni::auto_set_device(env); - auto wrapped = reinterpret_cast(child); - auto ret = new rmm::mr::arena_memory_resource(wrapped, init, - dump_on_oom); + auto wrapped = reinterpret_cast(child); + auto ret = new rmm::mr::arena_memory_resource( + wrapped, init, dump_on_oom); return reinterpret_cast(ret); } CATCH_STD(env, 0) } -JNIEXPORT void JNICALL Java_ai_rapids_cudf_Rmm_releaseArenaMemoryResource(JNIEnv *env, jclass clazz, - jlong ptr) { +JNIEXPORT void JNICALL Java_ai_rapids_cudf_Rmm_releaseArenaMemoryResource(JNIEnv* env, + jclass clazz, + jlong ptr) +{ try { cudf::jni::auto_set_device(env); auto mr = - reinterpret_cast *>(ptr); + reinterpret_cast*>(ptr); delete mr; } CATCH_STD(env, ) } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Rmm_newCudaAsyncMemoryResource(JNIEnv *env, - jclass clazz, jlong init, - jlong release) { +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Rmm_newCudaAsyncMemoryResource(JNIEnv* env, + jclass clazz, + jlong init, + jlong release) +{ try { cudf::jni::auto_set_device(env); auto ret = new rmm::mr::cuda_async_memory_resource(init, release); @@ -726,71 +791,70 @@ JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Rmm_newCudaAsyncMemoryResource(JNIEn CATCH_STD(env, 0) } -JNIEXPORT void JNICALL Java_ai_rapids_cudf_Rmm_releaseCudaAsyncMemoryResource(JNIEnv *env, +JNIEXPORT void JNICALL Java_ai_rapids_cudf_Rmm_releaseCudaAsyncMemoryResource(JNIEnv* env, jclass clazz, - jlong ptr) { + jlong ptr) +{ try { cudf::jni::auto_set_device(env); - auto mr = reinterpret_cast(ptr); + auto mr = reinterpret_cast(ptr); delete mr; } CATCH_STD(env, ) } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Rmm_newLimitingResourceAdaptor(JNIEnv *env, - jclass clazz, - jlong child, jlong limit, - jlong align) { +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Rmm_newLimitingResourceAdaptor( + JNIEnv* env, jclass clazz, jlong child, jlong limit, jlong align) +{ JNI_NULL_CHECK(env, child, "child is null", 0); try { cudf::jni::auto_set_device(env); - auto wrapped = reinterpret_cast(child); - auto ret = new rmm::mr::limiting_resource_adaptor( - wrapped, limit, align); + auto wrapped = reinterpret_cast(child); + auto ret = new rmm::mr::limiting_resource_adaptor( + wrapped, limit, align); return reinterpret_cast(ret); } CATCH_STD(env, 0) } -JNIEXPORT void JNICALL Java_ai_rapids_cudf_Rmm_releaseLimitingResourceAdaptor(JNIEnv *env, +JNIEXPORT void JNICALL Java_ai_rapids_cudf_Rmm_releaseLimitingResourceAdaptor(JNIEnv* env, jclass clazz, - jlong ptr) { + jlong ptr) +{ try { cudf::jni::auto_set_device(env); auto mr = - reinterpret_cast *>( - ptr); + reinterpret_cast*>(ptr); delete mr; } CATCH_STD(env, ) } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Rmm_newLoggingResourceAdaptor(JNIEnv *env, jclass clazz, - jlong child, jint type, - jstring jpath, - jboolean auto_flush) { +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Rmm_newLoggingResourceAdaptor( + JNIEnv* env, jclass clazz, jlong child, jint type, jstring jpath, jboolean auto_flush) +{ JNI_NULL_CHECK(env, child, "child is null", 0); try { cudf::jni::auto_set_device(env); - auto wrapped = reinterpret_cast(child); + auto wrapped = reinterpret_cast(child); switch (type) { - case 1: // File + case 1: // File { cudf::jni::native_jstring path(env, jpath); auto ret = new logging_resource_adaptor( - wrapped, path.get(), auto_flush); + wrapped, path.get(), auto_flush); return reinterpret_cast(ret); } - case 2: // stdout + case 2: // stdout { - auto ret = new logging_resource_adaptor(wrapped, std::cout, - auto_flush); + auto ret = new logging_resource_adaptor( + wrapped, std::cout, auto_flush); return reinterpret_cast(ret); } - case 3: // stderr + case 3: // stderr { - auto ret = new logging_resource_adaptor(wrapped, std::cerr, - auto_flush); + auto ret = new logging_resource_adaptor( + wrapped, std::cerr, auto_flush); return reinterpret_cast(ret); } default: throw std::logic_error("unsupported logging location type"); @@ -799,108 +863,121 @@ JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Rmm_newLoggingResourceAdaptor(JNIEnv CATCH_STD(env, 0) } -JNIEXPORT void JNICALL Java_ai_rapids_cudf_Rmm_releaseLoggingResourceAdaptor(JNIEnv *env, +JNIEXPORT void JNICALL Java_ai_rapids_cudf_Rmm_releaseLoggingResourceAdaptor(JNIEnv* env, jclass clazz, - jlong ptr) { + jlong ptr) +{ try { cudf::jni::auto_set_device(env); auto mr = - reinterpret_cast *>(ptr); + reinterpret_cast*>(ptr); delete mr; } CATCH_STD(env, ) } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Rmm_newTrackingResourceAdaptor(JNIEnv *env, +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Rmm_newTrackingResourceAdaptor(JNIEnv* env, jclass clazz, jlong child, - jlong align) { + jlong align) +{ JNI_NULL_CHECK(env, child, "child is null", 0); try { cudf::jni::auto_set_device(env); - auto wrapped = reinterpret_cast(child); - auto ret = new tracking_resource_adaptor(wrapped, align); + auto wrapped = reinterpret_cast(child); + auto ret = new tracking_resource_adaptor(wrapped, align); return reinterpret_cast(ret); } CATCH_STD(env, 0) } -JNIEXPORT void JNICALL Java_ai_rapids_cudf_Rmm_releaseTrackingResourceAdaptor(JNIEnv *env, +JNIEXPORT void JNICALL Java_ai_rapids_cudf_Rmm_releaseTrackingResourceAdaptor(JNIEnv* env, jclass clazz, - jlong ptr) { + jlong ptr) +{ try { cudf::jni::auto_set_device(env); - auto mr = reinterpret_cast *>(ptr); + auto mr = reinterpret_cast*>(ptr); delete mr; } CATCH_STD(env, ) } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Rmm_nativeGetTotalBytesAllocated(JNIEnv *env, +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Rmm_nativeGetTotalBytesAllocated(JNIEnv* env, jclass clazz, - jlong ptr) { + jlong ptr) +{ JNI_NULL_CHECK(env, ptr, "adaptor is null", 0); try { cudf::jni::auto_set_device(env); - auto mr = reinterpret_cast *>(ptr); + auto mr = reinterpret_cast*>(ptr); return mr->get_total_allocated(); } CATCH_STD(env, 0) } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Rmm_nativeGetMaxTotalBytesAllocated(JNIEnv *env, +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Rmm_nativeGetMaxTotalBytesAllocated(JNIEnv* env, jclass clazz, - jlong ptr) { + jlong ptr) +{ JNI_NULL_CHECK(env, ptr, "adaptor is null", 0); try { cudf::jni::auto_set_device(env); - auto mr = reinterpret_cast *>(ptr); + auto mr = reinterpret_cast*>(ptr); return mr->get_max_total_allocated(); } CATCH_STD(env, 0) } -JNIEXPORT void JNICALL Java_ai_rapids_cudf_Rmm_nativeResetScopedMaxTotalBytesAllocated(JNIEnv *env, +JNIEXPORT void JNICALL Java_ai_rapids_cudf_Rmm_nativeResetScopedMaxTotalBytesAllocated(JNIEnv* env, jclass clazz, jlong ptr, - jlong init) { + jlong init) +{ JNI_NULL_CHECK(env, ptr, "adaptor is null", ); try { cudf::jni::auto_set_device(env); - auto mr = reinterpret_cast *>(ptr); + auto mr = reinterpret_cast*>(ptr); mr->reset_scoped_max_total_allocated(init); } CATCH_STD(env, ) } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Rmm_nativeGetScopedMaxTotalBytesAllocated(JNIEnv *env, +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Rmm_nativeGetScopedMaxTotalBytesAllocated(JNIEnv* env, jclass clazz, - jlong ptr) { + jlong ptr) +{ JNI_NULL_CHECK(env, ptr, "adaptor is null", 0); try { cudf::jni::auto_set_device(env); - auto mr = reinterpret_cast *>(ptr); + auto mr = reinterpret_cast*>(ptr); return mr->get_scoped_max_total_allocated(); } CATCH_STD(env, 0) } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Rmm_newEventHandlerResourceAdaptor( - JNIEnv *env, jclass, jlong child, jlong tracker, jobject handler_obj, - jlongArray jalloc_thresholds, jlongArray jdealloc_thresholds, jboolean enable_debug) { +JNIEXPORT jlong JNICALL +Java_ai_rapids_cudf_Rmm_newEventHandlerResourceAdaptor(JNIEnv* env, + jclass, + jlong child, + jlong tracker, + jobject handler_obj, + jlongArray jalloc_thresholds, + jlongArray jdealloc_thresholds, + jboolean enable_debug) +{ JNI_NULL_CHECK(env, child, "child is null", 0); JNI_NULL_CHECK(env, tracker, "tracker is null", 0); try { - auto wrapped = reinterpret_cast(child); - auto t = - reinterpret_cast *>(tracker); + auto wrapped = reinterpret_cast(child); + auto t = reinterpret_cast*>(tracker); if (enable_debug) { - auto ret = new java_debug_event_handler_memory_resource(env, handler_obj, jalloc_thresholds, - jdealloc_thresholds, wrapped, t); + auto ret = new java_debug_event_handler_memory_resource( + env, handler_obj, jalloc_thresholds, jdealloc_thresholds, wrapped, t); return reinterpret_cast(ret); } else { - auto ret = new java_event_handler_memory_resource(env, handler_obj, jalloc_thresholds, - jdealloc_thresholds, wrapped, t); + auto ret = new java_event_handler_memory_resource( + env, handler_obj, jalloc_thresholds, jdealloc_thresholds, wrapped, t); return reinterpret_cast(ret); } } @@ -908,34 +985,38 @@ JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Rmm_newEventHandlerResourceAdaptor( } JNIEXPORT void JNICALL Java_ai_rapids_cudf_Rmm_releaseEventHandlerResourceAdaptor( - JNIEnv *env, jclass clazz, jlong ptr, jboolean enable_debug) { + JNIEnv* env, jclass clazz, jlong ptr, jboolean enable_debug) +{ try { cudf::jni::auto_set_device(env); if (enable_debug) { - auto mr = reinterpret_cast(ptr); + auto mr = reinterpret_cast(ptr); delete mr; } else { - auto mr = reinterpret_cast(ptr); + auto mr = reinterpret_cast(ptr); delete mr; } } CATCH_STD(env, ) } -JNIEXPORT void JNICALL Java_ai_rapids_cudf_Rmm_setCurrentDeviceResourceInternal(JNIEnv *env, +JNIEXPORT void JNICALL Java_ai_rapids_cudf_Rmm_setCurrentDeviceResourceInternal(JNIEnv* env, jclass clazz, - jlong new_handle) { + jlong new_handle) +{ try { cudf::jni::auto_set_device(env); - auto mr = reinterpret_cast(new_handle); + auto mr = reinterpret_cast(new_handle); rmm::mr::set_current_device_resource(mr); } CATCH_STD(env, ) } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Rmm_newPinnedPoolMemoryResource(JNIEnv *env, +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Rmm_newPinnedPoolMemoryResource(JNIEnv* env, jclass clazz, - jlong init, jlong max) { + jlong init, + jlong max) +{ try { cudf::jni::auto_set_device(env); auto pool = new rmm_pinned_pool_t(new rmm::mr::pinned_host_memory_resource(), init, max); @@ -944,12 +1025,13 @@ JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Rmm_newPinnedPoolMemoryResource(JNIE CATCH_STD(env, 0) } -JNIEXPORT void JNICALL Java_ai_rapids_cudf_Rmm_setCuioPinnedPoolMemoryResource(JNIEnv *env, +JNIEXPORT void JNICALL Java_ai_rapids_cudf_Rmm_setCuioPinnedPoolMemoryResource(JNIEnv* env, jclass clazz, - jlong pool_ptr) { + jlong pool_ptr) +{ try { cudf::jni::auto_set_device(env); - auto pool = reinterpret_cast(pool_ptr); + auto pool = reinterpret_cast(pool_ptr); // create a pinned fallback pool that will allocate pinned memory // if the regular pinned pool is exhausted pinned_fallback_mr.reset(new pinned_fallback_host_memory_resource(pool)); @@ -959,57 +1041,67 @@ JNIEXPORT void JNICALL Java_ai_rapids_cudf_Rmm_setCuioPinnedPoolMemoryResource(J CATCH_STD(env, ) } -JNIEXPORT void JNICALL Java_ai_rapids_cudf_Rmm_releasePinnedPoolMemoryResource(JNIEnv *env, +JNIEXPORT void JNICALL Java_ai_rapids_cudf_Rmm_releasePinnedPoolMemoryResource(JNIEnv* env, jclass clazz, - jlong pool_ptr) { + jlong pool_ptr) +{ try { cudf::jni::auto_set_device(env); // set the cuio host memory resource to what it was before, or the same // if we didn't overwrite it with setCuioPinnedPoolMemoryResource cudf::io::set_host_memory_resource(prior_cuio_host_mr()); pinned_fallback_mr.reset(); - delete reinterpret_cast(pool_ptr); + delete reinterpret_cast(pool_ptr); } CATCH_STD(env, ) } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Rmm_allocFromPinnedPool(JNIEnv *env, jclass clazz, - jlong pool_ptr, jlong size) { +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Rmm_allocFromPinnedPool(JNIEnv* env, + jclass clazz, + jlong pool_ptr, + jlong size) +{ try { cudf::jni::auto_set_device(env); - auto pool = reinterpret_cast(pool_ptr); - void *ret = pool->allocate(size); + auto pool = reinterpret_cast(pool_ptr); + void* ret = pool->allocate(size); return reinterpret_cast(ret); - } catch (const std::exception &unused) { return -1; } + } catch (const std::exception& unused) { + return -1; + } } -JNIEXPORT void JNICALL Java_ai_rapids_cudf_Rmm_freeFromPinnedPool(JNIEnv *env, jclass clazz, - jlong pool_ptr, jlong ptr, - jlong size) { +JNIEXPORT void JNICALL Java_ai_rapids_cudf_Rmm_freeFromPinnedPool( + JNIEnv* env, jclass clazz, jlong pool_ptr, jlong ptr, jlong size) +{ try { cudf::jni::auto_set_device(env); - auto pool = reinterpret_cast(pool_ptr); - void *cptr = reinterpret_cast(ptr); + auto pool = reinterpret_cast(pool_ptr); + void* cptr = reinterpret_cast(ptr); pool->deallocate(cptr, size); } CATCH_STD(env, ) } // only for tests -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Rmm_allocFromFallbackPinnedPool(JNIEnv *env, +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Rmm_allocFromFallbackPinnedPool(JNIEnv* env, jclass clazz, - jlong size) { + jlong size) +{ cudf::jni::auto_set_device(env); - void *ret = cudf::io::get_host_memory_resource().allocate(size); + void* ret = cudf::io::get_host_memory_resource().allocate(size); return reinterpret_cast(ret); } // only for tests -JNIEXPORT void JNICALL Java_ai_rapids_cudf_Rmm_freeFromFallbackPinnedPool(JNIEnv *env, jclass clazz, - jlong ptr, jlong size) { +JNIEXPORT void JNICALL Java_ai_rapids_cudf_Rmm_freeFromFallbackPinnedPool(JNIEnv* env, + jclass clazz, + jlong ptr, + jlong size) +{ try { cudf::jni::auto_set_device(env); - void *cptr = reinterpret_cast(ptr); + void* cptr = reinterpret_cast(ptr); cudf::io::get_host_memory_resource().deallocate(cptr, size); } CATCH_STD(env, ) diff --git a/java/src/main/native/src/ScalarJni.cpp b/java/src/main/native/src/ScalarJni.cpp index e47728f6acc..6a1ad1a9f32 100644 --- a/java/src/main/native/src/ScalarJni.cpp +++ b/java/src/main/native/src/ScalarJni.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019-2022, NVIDIA CORPORATION. + * Copyright (c) 2019-2024, NVIDIA CORPORATION. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,6 +14,9 @@ * limitations under the License. */ +#include "cudf_jni_apis.hpp" +#include "dtype_utils.hpp" + #include #include #include @@ -21,135 +24,149 @@ #include #include -#include "cudf_jni_apis.hpp" -#include "dtype_utils.hpp" - using cudf::jni::release_as_jlong; extern "C" { -JNIEXPORT void JNICALL Java_ai_rapids_cudf_Scalar_closeScalar(JNIEnv *env, jclass, - jlong scalar_handle) { +JNIEXPORT void JNICALL Java_ai_rapids_cudf_Scalar_closeScalar(JNIEnv* env, + jclass, + jlong scalar_handle) +{ try { cudf::jni::auto_set_device(env); - cudf::scalar *s = reinterpret_cast(scalar_handle); + cudf::scalar* s = reinterpret_cast(scalar_handle); delete s; } CATCH_STD(env, ); } -JNIEXPORT jboolean JNICALL Java_ai_rapids_cudf_Scalar_isScalarValid(JNIEnv *env, jclass, - jlong scalar_handle) { +JNIEXPORT jboolean JNICALL Java_ai_rapids_cudf_Scalar_isScalarValid(JNIEnv* env, + jclass, + jlong scalar_handle) +{ try { cudf::jni::auto_set_device(env); - cudf::scalar *s = reinterpret_cast(scalar_handle); + cudf::scalar* s = reinterpret_cast(scalar_handle); return static_cast(s->is_valid()); } CATCH_STD(env, 0); } -JNIEXPORT jbyte JNICALL Java_ai_rapids_cudf_Scalar_getByte(JNIEnv *env, jclass, - jlong scalar_handle) { +JNIEXPORT jbyte JNICALL Java_ai_rapids_cudf_Scalar_getByte(JNIEnv* env, jclass, jlong scalar_handle) +{ try { cudf::jni::auto_set_device(env); using ScalarType = cudf::scalar_type_t; - auto s = reinterpret_cast(scalar_handle); + auto s = reinterpret_cast(scalar_handle); return static_cast(s->value()); } CATCH_STD(env, 0); } -JNIEXPORT jshort JNICALL Java_ai_rapids_cudf_Scalar_getShort(JNIEnv *env, jclass, - jlong scalar_handle) { +JNIEXPORT jshort JNICALL Java_ai_rapids_cudf_Scalar_getShort(JNIEnv* env, + jclass, + jlong scalar_handle) +{ try { cudf::jni::auto_set_device(env); using ScalarType = cudf::scalar_type_t; - auto s = reinterpret_cast(scalar_handle); + auto s = reinterpret_cast(scalar_handle); return static_cast(s->value()); } CATCH_STD(env, 0); } -JNIEXPORT jint JNICALL Java_ai_rapids_cudf_Scalar_getInt(JNIEnv *env, jclass, jlong scalar_handle) { +JNIEXPORT jint JNICALL Java_ai_rapids_cudf_Scalar_getInt(JNIEnv* env, jclass, jlong scalar_handle) +{ try { cudf::jni::auto_set_device(env); using ScalarType = cudf::scalar_type_t; - auto s = reinterpret_cast(scalar_handle); + auto s = reinterpret_cast(scalar_handle); return static_cast(s->value()); } CATCH_STD(env, 0); } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Scalar_getLong(JNIEnv *env, jclass, - jlong scalar_handle) { +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Scalar_getLong(JNIEnv* env, jclass, jlong scalar_handle) +{ try { cudf::jni::auto_set_device(env); using ScalarType = cudf::scalar_type_t; - auto s = reinterpret_cast(scalar_handle); + auto s = reinterpret_cast(scalar_handle); return static_cast(s->value()); } CATCH_STD(env, 0); } -JNIEXPORT jfloat JNICALL Java_ai_rapids_cudf_Scalar_getFloat(JNIEnv *env, jclass, - jlong scalar_handle) { +JNIEXPORT jfloat JNICALL Java_ai_rapids_cudf_Scalar_getFloat(JNIEnv* env, + jclass, + jlong scalar_handle) +{ try { cudf::jni::auto_set_device(env); using ScalarType = cudf::scalar_type_t; - auto s = reinterpret_cast(scalar_handle); + auto s = reinterpret_cast(scalar_handle); return static_cast(s->value()); } CATCH_STD(env, 0); } -JNIEXPORT jdouble JNICALL Java_ai_rapids_cudf_Scalar_getDouble(JNIEnv *env, jclass, - jlong scalar_handle) { +JNIEXPORT jdouble JNICALL Java_ai_rapids_cudf_Scalar_getDouble(JNIEnv* env, + jclass, + jlong scalar_handle) +{ try { cudf::jni::auto_set_device(env); using ScalarType = cudf::scalar_type_t; - auto s = reinterpret_cast(scalar_handle); + auto s = reinterpret_cast(scalar_handle); return static_cast(s->value()); } CATCH_STD(env, 0); } -JNIEXPORT jbyteArray JNICALL Java_ai_rapids_cudf_Scalar_getBigIntegerBytes(JNIEnv *env, jclass, - jlong scalar_handle) { +JNIEXPORT jbyteArray JNICALL Java_ai_rapids_cudf_Scalar_getBigIntegerBytes(JNIEnv* env, + jclass, + jlong scalar_handle) +{ try { cudf::jni::auto_set_device(env); using ScalarType = cudf::scalar_type_t<__int128_t>; - auto s = reinterpret_cast(scalar_handle); - auto val = s->value(); - jbyte const *ptr = reinterpret_cast(&val); + auto s = reinterpret_cast(scalar_handle); + auto val = s->value(); + jbyte const* ptr = reinterpret_cast(&val); cudf::jni::native_jbyteArray jbytes{env, ptr, sizeof(__int128_t)}; return jbytes.get_jArray(); } CATCH_STD(env, 0); } -JNIEXPORT jbyteArray JNICALL Java_ai_rapids_cudf_Scalar_getUTF8(JNIEnv *env, jclass, - jlong scalar_handle) { +JNIEXPORT jbyteArray JNICALL Java_ai_rapids_cudf_Scalar_getUTF8(JNIEnv* env, + jclass, + jlong scalar_handle) +{ try { cudf::jni::auto_set_device(env); - auto s = reinterpret_cast(scalar_handle); + auto s = reinterpret_cast(scalar_handle); std::string val{s->to_string()}; if (val.size() > 0x7FFFFFFF) { - cudf::jni::throw_java_exception(env, "java/lang/IllegalArgumentException", - "string scalar too large"); + cudf::jni::throw_java_exception( + env, "java/lang/IllegalArgumentException", "string scalar too large"); } - cudf::jni::native_jbyteArray jbytes{env, reinterpret_cast(val.data()), - static_cast(val.size())}; + cudf::jni::native_jbyteArray jbytes{ + env, reinterpret_cast(val.data()), static_cast(val.size())}; return jbytes.get_jArray(); } CATCH_STD(env, 0); } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Scalar_getListAsColumnView(JNIEnv *env, jclass, - jlong scalar_handle) { +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Scalar_getListAsColumnView(JNIEnv* env, + jclass, + jlong scalar_handle) +{ JNI_NULL_CHECK(env, scalar_handle, "scalar handle is null", 0); try { cudf::jni::auto_set_device(env); - auto s = reinterpret_cast(scalar_handle); + auto s = reinterpret_cast(scalar_handle); // Creates a column view in heap with the stack one, to let JVM take care of its // life cycle. return reinterpret_cast(new cudf::column_view(s->view())); @@ -158,12 +175,13 @@ JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Scalar_getListAsColumnView(JNIEnv *e } JNIEXPORT jlongArray JNICALL -Java_ai_rapids_cudf_Scalar_getChildrenFromStructScalar(JNIEnv *env, jclass, jlong scalar_handle) { +Java_ai_rapids_cudf_Scalar_getChildrenFromStructScalar(JNIEnv* env, jclass, jlong scalar_handle) +{ JNI_NULL_CHECK(env, scalar_handle, "scalar handle is null", 0); try { cudf::jni::auto_set_device(env); - const auto s = reinterpret_cast(scalar_handle); - const cudf::table_view &table = s->view(); + const auto s = reinterpret_cast(scalar_handle); + const cudf::table_view& table = s->view(); cudf::jni::native_jpointerArray column_handles(env, table.num_columns()); for (int i = 0; i < table.num_columns(); i++) { column_handles[i] = new cudf::column_view(table.column(i)); @@ -173,215 +191,246 @@ Java_ai_rapids_cudf_Scalar_getChildrenFromStructScalar(JNIEnv *env, jclass, jlon CATCH_STD(env, 0); } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Scalar_makeBool8Scalar(JNIEnv *env, jclass, +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Scalar_makeBool8Scalar(JNIEnv* env, + jclass, jboolean value, - jboolean is_valid) { + jboolean is_valid) +{ try { cudf::jni::auto_set_device(env); std::unique_ptr s = - cudf::make_numeric_scalar(cudf::data_type(cudf::type_id::BOOL8)); + cudf::make_numeric_scalar(cudf::data_type(cudf::type_id::BOOL8)); s->set_valid_async(is_valid); if (is_valid) { using ScalarType = cudf::scalar_type_t; - int8_t val = value ? 1 : 0; - static_cast(s.get())->set_value(val); + int8_t val = value ? 1 : 0; + static_cast(s.get())->set_value(val); } return reinterpret_cast(s.release()); } CATCH_STD(env, 0); } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Scalar_makeInt8Scalar(JNIEnv *env, jclass, jbyte value, - jboolean is_valid) { +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Scalar_makeInt8Scalar(JNIEnv* env, + jclass, + jbyte value, + jboolean is_valid) +{ try { cudf::jni::auto_set_device(env); std::unique_ptr s = - cudf::make_numeric_scalar(cudf::data_type(cudf::type_id::INT8)); + cudf::make_numeric_scalar(cudf::data_type(cudf::type_id::INT8)); s->set_valid_async(is_valid); if (is_valid) { using ScalarType = cudf::scalar_type_t; - static_cast(s.get())->set_value(static_cast(value)); + static_cast(s.get())->set_value(static_cast(value)); } return reinterpret_cast(s.release()); } CATCH_STD(env, 0); } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Scalar_makeUint8Scalar(JNIEnv *env, jclass, jbyte value, - jboolean is_valid) { +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Scalar_makeUint8Scalar(JNIEnv* env, + jclass, + jbyte value, + jboolean is_valid) +{ try { cudf::jni::auto_set_device(env); std::unique_ptr s = - cudf::make_numeric_scalar(cudf::data_type(cudf::type_id::UINT8)); + cudf::make_numeric_scalar(cudf::data_type(cudf::type_id::UINT8)); s->set_valid_async(is_valid); if (is_valid) { using ScalarType = cudf::scalar_type_t; - static_cast(s.get())->set_value(static_cast(value)); + static_cast(s.get())->set_value(static_cast(value)); } return reinterpret_cast(s.release()); } CATCH_STD(env, 0); } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Scalar_makeInt16Scalar(JNIEnv *env, jclass, +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Scalar_makeInt16Scalar(JNIEnv* env, + jclass, jshort value, - jboolean is_valid) { + jboolean is_valid) +{ try { cudf::jni::auto_set_device(env); std::unique_ptr s = - cudf::make_numeric_scalar(cudf::data_type(cudf::type_id::INT16)); + cudf::make_numeric_scalar(cudf::data_type(cudf::type_id::INT16)); s->set_valid_async(is_valid); if (is_valid) { using ScalarType = cudf::scalar_type_t; - static_cast(s.get())->set_value(static_cast(value)); + static_cast(s.get())->set_value(static_cast(value)); } return reinterpret_cast(s.release()); } CATCH_STD(env, 0); } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Scalar_makeUint16Scalar(JNIEnv *env, jclass, +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Scalar_makeUint16Scalar(JNIEnv* env, + jclass, jshort value, - jboolean is_valid) { + jboolean is_valid) +{ try { cudf::jni::auto_set_device(env); std::unique_ptr s = - cudf::make_numeric_scalar(cudf::data_type(cudf::type_id::UINT16)); + cudf::make_numeric_scalar(cudf::data_type(cudf::type_id::UINT16)); s->set_valid_async(is_valid); if (is_valid) { using ScalarType = cudf::scalar_type_t; - static_cast(s.get())->set_value(static_cast(value)); + static_cast(s.get())->set_value(static_cast(value)); } return reinterpret_cast(s.release()); } CATCH_STD(env, 0); } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Scalar_makeDurationDaysScalar(JNIEnv *env, jclass, +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Scalar_makeDurationDaysScalar(JNIEnv* env, + jclass, jint value, - jboolean is_valid) { + jboolean is_valid) +{ try { cudf::jni::auto_set_device(env); std::unique_ptr s = - cudf::make_duration_scalar(cudf::data_type(cudf::type_id::DURATION_DAYS)); + cudf::make_duration_scalar(cudf::data_type(cudf::type_id::DURATION_DAYS)); s->set_valid_async(is_valid); if (is_valid) { using ScalarType = cudf::scalar_type_t; - static_cast(s.get())->set_value(static_cast(value)); + static_cast(s.get())->set_value(static_cast(value)); } return reinterpret_cast(s.release()); } CATCH_STD(env, 0); } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Scalar_makeInt32Scalar(JNIEnv *env, jclass, jint value, - jboolean is_valid) { +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Scalar_makeInt32Scalar(JNIEnv* env, + jclass, + jint value, + jboolean is_valid) +{ try { cudf::jni::auto_set_device(env); std::unique_ptr s = - cudf::make_numeric_scalar(cudf::data_type(cudf::type_id::INT32)); + cudf::make_numeric_scalar(cudf::data_type(cudf::type_id::INT32)); s->set_valid_async(is_valid); if (is_valid) { using ScalarType = cudf::scalar_type_t; - static_cast(s.get())->set_value(static_cast(value)); + static_cast(s.get())->set_value(static_cast(value)); } return reinterpret_cast(s.release()); } CATCH_STD(env, 0); } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Scalar_makeUint32Scalar(JNIEnv *env, jclass, jint value, - jboolean is_valid) { +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Scalar_makeUint32Scalar(JNIEnv* env, + jclass, + jint value, + jboolean is_valid) +{ try { cudf::jni::auto_set_device(env); std::unique_ptr s = - cudf::make_numeric_scalar(cudf::data_type(cudf::type_id::UINT32)); + cudf::make_numeric_scalar(cudf::data_type(cudf::type_id::UINT32)); s->set_valid_async(is_valid); if (is_valid) { using ScalarType = cudf::scalar_type_t; - static_cast(s.get())->set_value(static_cast(value)); + static_cast(s.get())->set_value(static_cast(value)); } return reinterpret_cast(s.release()); } CATCH_STD(env, 0); } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Scalar_makeInt64Scalar(JNIEnv *env, jclass, jlong value, - jboolean is_valid) { +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Scalar_makeInt64Scalar(JNIEnv* env, + jclass, + jlong value, + jboolean is_valid) +{ try { cudf::jni::auto_set_device(env); std::unique_ptr s = - cudf::make_numeric_scalar(cudf::data_type(cudf::type_id::INT64)); + cudf::make_numeric_scalar(cudf::data_type(cudf::type_id::INT64)); s->set_valid_async(is_valid); if (is_valid) { using ScalarType = cudf::scalar_type_t; - static_cast(s.get())->set_value(static_cast(value)); + static_cast(s.get())->set_value(static_cast(value)); } return reinterpret_cast(s.release()); } CATCH_STD(env, 0); } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Scalar_makeUint64Scalar(JNIEnv *env, jclass, +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Scalar_makeUint64Scalar(JNIEnv* env, + jclass, jlong value, - jboolean is_valid) { + jboolean is_valid) +{ try { cudf::jni::auto_set_device(env); std::unique_ptr s = - cudf::make_numeric_scalar(cudf::data_type(cudf::type_id::UINT64)); + cudf::make_numeric_scalar(cudf::data_type(cudf::type_id::UINT64)); s->set_valid_async(is_valid); if (is_valid) { using ScalarType = cudf::scalar_type_t; - static_cast(s.get())->set_value(static_cast(value)); + static_cast(s.get())->set_value(static_cast(value)); } return reinterpret_cast(s.release()); } CATCH_STD(env, 0); } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Scalar_makeFloat32Scalar(JNIEnv *env, jclass, +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Scalar_makeFloat32Scalar(JNIEnv* env, + jclass, jfloat value, - jboolean is_valid) { + jboolean is_valid) +{ try { cudf::jni::auto_set_device(env); std::unique_ptr s = - cudf::make_numeric_scalar(cudf::data_type(cudf::type_id::FLOAT32)); + cudf::make_numeric_scalar(cudf::data_type(cudf::type_id::FLOAT32)); s->set_valid_async(is_valid); if (is_valid) { using ScalarType = cudf::scalar_type_t; - static_cast(s.get())->set_value(static_cast(value)); + static_cast(s.get())->set_value(static_cast(value)); } return reinterpret_cast(s.release()); } CATCH_STD(env, 0); } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Scalar_makeFloat64Scalar(JNIEnv *env, jclass, +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Scalar_makeFloat64Scalar(JNIEnv* env, + jclass, jdouble value, - jboolean is_valid) { + jboolean is_valid) +{ try { cudf::jni::auto_set_device(env); std::unique_ptr s = - cudf::make_numeric_scalar(cudf::data_type(cudf::type_id::FLOAT64)); + cudf::make_numeric_scalar(cudf::data_type(cudf::type_id::FLOAT64)); s->set_valid_async(is_valid); if (is_valid) { using ScalarType = cudf::scalar_type_t; - static_cast(s.get())->set_value(static_cast(value)); + static_cast(s.get())->set_value(static_cast(value)); } return reinterpret_cast(s.release()); } CATCH_STD(env, 0); } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Scalar_makeStringScalar(JNIEnv *env, jclass, +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Scalar_makeStringScalar(JNIEnv* env, + jclass, jbyteArray value, - jboolean is_valid) { + jboolean is_valid) +{ try { cudf::jni::auto_set_device(env); std::string strval; if (is_valid) { cudf::jni::native_jbyteArray jbytes{env, value}; - strval.assign(reinterpret_cast(jbytes.data()), jbytes.size()); + strval.assign(reinterpret_cast(jbytes.data()), jbytes.size()); } auto s = new cudf::string_scalar{strval, static_cast(is_valid)}; @@ -390,117 +439,116 @@ JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Scalar_makeStringScalar(JNIEnv *env, CATCH_STD(env, 0); } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Scalar_makeTimestampDaysScalar(JNIEnv *env, jclass, +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Scalar_makeTimestampDaysScalar(JNIEnv* env, + jclass, jint value, - jboolean is_valid) { + jboolean is_valid) +{ try { cudf::jni::auto_set_device(env); std::unique_ptr s = - cudf::make_timestamp_scalar(cudf::data_type(cudf::type_id::TIMESTAMP_DAYS)); + cudf::make_timestamp_scalar(cudf::data_type(cudf::type_id::TIMESTAMP_DAYS)); s->set_valid_async(is_valid); if (is_valid) { using ScalarType = cudf::scalar_type_t; - static_cast(s.get())->set_value(static_cast(value)); + static_cast(s.get())->set_value(static_cast(value)); } return reinterpret_cast(s.release()); } CATCH_STD(env, 0); } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Scalar_makeDurationTimeScalar(JNIEnv *env, jclass, - jint jdtype_id, - jlong value, - jboolean is_valid) { +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Scalar_makeDurationTimeScalar( + JNIEnv* env, jclass, jint jdtype_id, jlong value, jboolean is_valid) +{ try { cudf::jni::auto_set_device(env); - auto dtype_id = static_cast(jdtype_id); + auto dtype_id = static_cast(jdtype_id); std::unique_ptr s = cudf::make_duration_scalar(cudf::data_type(dtype_id)); s->set_valid_async(is_valid); if (is_valid) { using ScalarType = cudf::scalar_type_t; - static_cast(s.get())->set_value(static_cast(value)); + static_cast(s.get())->set_value(static_cast(value)); } return reinterpret_cast(s.release()); } CATCH_STD(env, 0); } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Scalar_makeTimestampTimeScalar(JNIEnv *env, jclass, - jint jdtype_id, - jlong value, - jboolean is_valid) { +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Scalar_makeTimestampTimeScalar( + JNIEnv* env, jclass, jint jdtype_id, jlong value, jboolean is_valid) +{ try { cudf::jni::auto_set_device(env); - auto dtype_id = static_cast(jdtype_id); + auto dtype_id = static_cast(jdtype_id); std::unique_ptr s = cudf::make_timestamp_scalar(cudf::data_type(dtype_id)); s->set_valid_async(is_valid); if (is_valid) { using ScalarType = cudf::scalar_type_t; - static_cast(s.get())->set_value(static_cast(value)); + static_cast(s.get())->set_value(static_cast(value)); } return reinterpret_cast(s.release()); } CATCH_STD(env, 0); } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Scalar_makeDecimal32Scalar(JNIEnv *env, jclass, - jint value, jint scale, - jboolean is_valid) { +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Scalar_makeDecimal32Scalar( + JNIEnv* env, jclass, jint value, jint scale, jboolean is_valid) +{ try { cudf::jni::auto_set_device(env); auto const value_ = static_cast(value); auto const scale_ = numeric::scale_type{static_cast(scale)}; std::unique_ptr s = - cudf::make_fixed_point_scalar(value_, scale_); + cudf::make_fixed_point_scalar(value_, scale_); s->set_valid_async(is_valid); return reinterpret_cast(s.release()); } CATCH_STD(env, 0); } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Scalar_makeDecimal64Scalar(JNIEnv *env, jclass, - jlong value, jint scale, - jboolean is_valid) { +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Scalar_makeDecimal64Scalar( + JNIEnv* env, jclass, jlong value, jint scale, jboolean is_valid) +{ try { cudf::jni::auto_set_device(env); auto const value_ = static_cast(value); auto const scale_ = numeric::scale_type{static_cast(scale)}; std::unique_ptr s = - cudf::make_fixed_point_scalar(value_, scale_); + cudf::make_fixed_point_scalar(value_, scale_); s->set_valid_async(is_valid); return reinterpret_cast(s.release()); } CATCH_STD(env, 0); } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Scalar_makeDecimal128Scalar(JNIEnv *env, jclass, - jbyteArray value, - jint scale, - jboolean is_valid) { +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Scalar_makeDecimal128Scalar( + JNIEnv* env, jclass, jbyteArray value, jint scale, jboolean is_valid) +{ try { cudf::jni::auto_set_device(env); auto const scale_ = numeric::scale_type{static_cast(scale)}; cudf::jni::native_jbyteArray jbytes{env, value}; - auto const value_ = reinterpret_cast<__int128_t *>(jbytes.data()); + auto const value_ = reinterpret_cast<__int128_t*>(jbytes.data()); std::unique_ptr s = - cudf::make_fixed_point_scalar(*value_, scale_); + cudf::make_fixed_point_scalar(*value_, scale_); s->set_valid_async(is_valid); return reinterpret_cast(s.release()); } CATCH_STD(env, 0); } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Scalar_binaryOpSV(JNIEnv *env, jclass, jlong lhs_ptr, - jlong rhs_view, jint int_op, - jint out_dtype, jint scale) { +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Scalar_binaryOpSV( + JNIEnv* env, jclass, jlong lhs_ptr, jlong rhs_view, jint int_op, jint out_dtype, jint scale) +{ JNI_NULL_CHECK(env, lhs_ptr, "lhs is null", 0); JNI_NULL_CHECK(env, rhs_view, "rhs is null", 0); try { cudf::jni::auto_set_device(env); - cudf::scalar *lhs = reinterpret_cast(lhs_ptr); - auto rhs = reinterpret_cast(rhs_view); + cudf::scalar* lhs = reinterpret_cast(lhs_ptr); + auto rhs = reinterpret_cast(rhs_view); cudf::data_type n_data_type = cudf::jni::make_data_type(out_dtype, scale); - cudf::binary_operator op = static_cast(int_op); + cudf::binary_operator op = static_cast(int_op); if (lhs->type().id() == cudf::type_id::STRUCT) { auto out = make_fixed_width_column(n_data_type, rhs->size(), cudf::mask_state::UNALLOCATED); @@ -512,10 +560,10 @@ JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Scalar_binaryOpSV(JNIEnv *env, jclas out->set_null_mask(std::move(new_mask), new_null_count); } - auto lhs_col = cudf::make_column_from_scalar(*lhs, 1); + auto lhs_col = cudf::make_column_from_scalar(*lhs, 1); auto out_view = out->mutable_view(); cudf::binops::compiled::detail::apply_sorting_struct_binary_op( - out_view, lhs_col->view(), *rhs, true, false, op, cudf::get_default_stream()); + out_view, lhs_col->view(), *rhs, true, false, op, cudf::get_default_stream()); return release_as_jlong(out); } @@ -524,28 +572,32 @@ JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Scalar_binaryOpSV(JNIEnv *env, jclas CATCH_STD(env, 0); } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Scalar_makeListScalar(JNIEnv *env, jclass, +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Scalar_makeListScalar(JNIEnv* env, + jclass, jlong view_handle, - jboolean is_valid) { + jboolean is_valid) +{ JNI_NULL_CHECK(env, view_handle, "Column view should NOT be null", 0); try { cudf::jni::auto_set_device(env); - auto col_view = reinterpret_cast(view_handle); + auto col_view = reinterpret_cast(view_handle); // Instead of calling the `cudf::empty_like` to create an empty column when `is_valid` // is false, always passes the input view to the scalar, to avoid copying the column // twice. // Let the Java layer make sure the view is empty when `is_valid` is false. - cudf::scalar *s = new cudf::list_scalar(*col_view); + cudf::scalar* s = new cudf::list_scalar(*col_view); s->set_valid_async(is_valid); return reinterpret_cast(s); } CATCH_STD(env, 0); } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Scalar_makeStructScalar(JNIEnv *env, jclass, +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Scalar_makeStructScalar(JNIEnv* env, + jclass, jlongArray handles, - jboolean is_valid) { + jboolean is_valid) +{ JNI_NULL_CHECK(env, handles, "native view handles are null", 0) try { cudf::jni::auto_set_device(env); @@ -553,24 +605,29 @@ JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Scalar_makeStructScalar(JNIEnv *env, cudf::jni::native_jpointerArray column_pointers(env, handles); std::vector columns; columns.reserve(column_pointers.size()); - std::transform(column_pointers.data(), column_pointers.data() + column_pointers.size(), - std::back_inserter(columns), [](auto const &col_ptr) { return *col_ptr; }); + std::transform(column_pointers.data(), + column_pointers.data() + column_pointers.size(), + std::back_inserter(columns), + [](auto const& col_ptr) { return *col_ptr; }); auto s = std::make_unique( - cudf::host_span{columns}, is_valid); + cudf::host_span{columns}, is_valid); return reinterpret_cast(s.release()); } CATCH_STD(env, 0); } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Scalar_repeatString(JNIEnv *env, jclass, jlong handle, - jint repeat_times) { +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Scalar_repeatString(JNIEnv* env, + jclass, + jlong handle, + jint repeat_times) +{ JNI_NULL_CHECK(env, handle, "scalar handle is null", 0) try { cudf::jni::auto_set_device(env); - auto const str = *reinterpret_cast(handle); + auto const str = *reinterpret_cast(handle); return reinterpret_cast(cudf::strings::repeat_string(str, repeat_times).release()); } CATCH_STD(env, 0); } -} // extern "C" +} // extern "C" diff --git a/java/src/main/native/src/TableJni.cpp b/java/src/main/native/src/TableJni.cpp index e8616710217..e411b1d5362 100644 --- a/java/src/main/native/src/TableJni.cpp +++ b/java/src/main/native/src/TableJni.cpp @@ -13,10 +13,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include +#include "csv_chunked_writer.hpp" +#include "cudf_jni_apis.hpp" +#include "dtype_utils.hpp" +#include "jni_compiled_expr.hpp" +#include "jni_utils.hpp" +#include "jni_writer_data_sink.hpp" -#include -#include #include #include #include @@ -44,16 +47,16 @@ #include #include #include + #include #include + #include -#include "csv_chunked_writer.hpp" -#include "cudf_jni_apis.hpp" -#include "dtype_utils.hpp" -#include "jni_compiled_expr.hpp" -#include "jni_utils.hpp" -#include "jni_writer_data_sink.hpp" +#include +#include + +#include namespace cudf { namespace jni { @@ -67,9 +70,11 @@ namespace jni { */ struct jni_table_writer_handle_base { explicit jni_table_writer_handle_base( - std::unique_ptr &&sink_, - std::shared_ptr &&stats_) - : sink{std::move(sink_)}, stats{std::move(stats_)} {} + std::unique_ptr&& sink_, + std::shared_ptr&& stats_) + : sink{std::move(sink_)}, stats{std::move(stats_)} + { + } std::unique_ptr sink; std::shared_ptr stats; @@ -77,13 +82,17 @@ struct jni_table_writer_handle_base { template struct jni_table_writer_handle final : public jni_table_writer_handle_base { - explicit jni_table_writer_handle(std::unique_ptr &&writer_) - : jni_table_writer_handle_base(nullptr, nullptr), writer{std::move(writer_)} {} + explicit jni_table_writer_handle(std::unique_ptr&& writer_) + : jni_table_writer_handle_base(nullptr, nullptr), writer{std::move(writer_)} + { + } explicit jni_table_writer_handle( - std::unique_ptr &&writer_, std::unique_ptr &&sink_, - std::shared_ptr &&stats_) - : jni_table_writer_handle_base(std::move(sink_), std::move(stats_)), - writer{std::move(writer_)} {} + std::unique_ptr&& writer_, + std::unique_ptr&& sink_, + std::shared_ptr&& stats_) + : jni_table_writer_handle_base(std::move(sink_), std::move(stats_)), writer{std::move(writer_)} + { + } std::unique_ptr writer; }; @@ -92,16 +101,20 @@ typedef jni_table_writer_handle native_parquet typedef jni_table_writer_handle native_orc_writer_handle; class native_arrow_ipc_writer_handle final { -public: - explicit native_arrow_ipc_writer_handle(const std::vector &col_names, - const std::string &file_name) - : initialized(false), column_names(col_names), file_name(file_name) {} + public: + explicit native_arrow_ipc_writer_handle(const std::vector& col_names, + const std::string& file_name) + : initialized(false), column_names(col_names), file_name(file_name) + { + } - explicit native_arrow_ipc_writer_handle(const std::vector &col_names, - const std::shared_ptr &sink) - : initialized(false), column_names(col_names), file_name(""), sink(sink) {} + explicit native_arrow_ipc_writer_handle(const std::vector& col_names, + const std::shared_ptr& sink) + : initialized(false), column_names(col_names), file_name(""), sink(sink) + { + } -private: + private: bool initialized; std::vector column_names; std::vector columns_meta; @@ -109,23 +122,20 @@ class native_arrow_ipc_writer_handle final { std::shared_ptr sink; std::shared_ptr writer; -public: - void write(std::shared_ptr &arrow_tab, int64_t max_chunk) { + public: + void write(std::shared_ptr& arrow_tab, int64_t max_chunk) + { if (!initialized) { if (!sink) { auto tmp_sink = arrow::io::FileOutputStream::Open(file_name); - if (!tmp_sink.ok()) { - throw std::runtime_error(tmp_sink.status().message()); - } + if (!tmp_sink.ok()) { throw std::runtime_error(tmp_sink.status().message()); } sink = *tmp_sink; } // There is an option to have a file writer too, with metadata auto tmp_writer = arrow::ipc::MakeStreamWriter(sink, arrow_tab->schema()); - if (!tmp_writer.ok()) { - throw std::runtime_error(tmp_writer.status().message()); - } - writer = *tmp_writer; + if (!tmp_writer.ok()) { throw std::runtime_error(tmp_writer.status().message()); } + writer = *tmp_writer; initialized = true; } if (arrow_tab->num_rows() == 0) { @@ -133,7 +143,7 @@ class native_arrow_ipc_writer_handle final { // empty table, so need to write an empty batch explicitly. // For more please see https://issues.apache.org/jira/browse/ARROW-17912. auto empty_batch = arrow::RecordBatch::MakeEmpty(arrow_tab->schema()); - auto status = writer->WriteRecordBatch(*(*empty_batch)); + auto status = writer->WriteRecordBatch(*(*empty_batch)); if (!status.ok()) { throw std::runtime_error("writer failed to write batch with the following error: " + status.ToString()); @@ -147,7 +157,8 @@ class native_arrow_ipc_writer_handle final { } } - void close() { + void close() + { if (initialized) { { auto status = writer->Close(); @@ -167,7 +178,8 @@ class native_arrow_ipc_writer_handle final { initialized = false; } - std::vector get_column_metadata(const cudf::table_view &tview) { + std::vector get_column_metadata(const cudf::table_view& tview) + { if (!column_names.empty() && columns_meta.empty()) { // Rebuild the structure of column meta according to table schema. // All the tables written by this writer should share the same schema, @@ -187,13 +199,13 @@ class native_arrow_ipc_writer_handle final { return columns_meta; } -private: - cudf::column_metadata build_one_column_meta(const cudf::column_view &cview, size_t &idx, - const bool consume_name = true) { + private: + cudf::column_metadata build_one_column_meta(const cudf::column_view& cview, + size_t& idx, + const bool consume_name = true) + { auto col_meta = cudf::column_metadata{}; - if (consume_name) { - col_meta.name = get_column_name(idx++); - } + if (consume_name) { col_meta.name = get_column_name(idx++); } // Process children if (cview.type().id() == cudf::type_id::LIST) { // list type: @@ -213,7 +225,8 @@ class native_arrow_ipc_writer_handle final { return col_meta; } - std::string &get_column_name(const size_t idx) { + std::string& get_column_name(const size_t idx) + { if (idx < 0 || idx >= column_names.size()) { throw cudf::jni::jni_exception("Missing names for columns or nested struct columns"); } @@ -222,49 +235,47 @@ class native_arrow_ipc_writer_handle final { }; class jni_arrow_output_stream final : public arrow::io::OutputStream { -public: - explicit jni_arrow_output_stream(JNIEnv *env, jobject callback, jobject host_memory_allocator) { - if (env->GetJavaVM(&jvm) < 0) { - throw std::runtime_error("GetJavaVM failed"); - } + public: + explicit jni_arrow_output_stream(JNIEnv* env, jobject callback, jobject host_memory_allocator) + { + if (env->GetJavaVM(&jvm) < 0) { throw std::runtime_error("GetJavaVM failed"); } jclass cls = env->GetObjectClass(callback); - if (cls == nullptr) { - throw cudf::jni::jni_exception("class not found"); - } + if (cls == nullptr) { throw cudf::jni::jni_exception("class not found"); } handle_buffer_method = - env->GetMethodID(cls, "handleBuffer", "(Lai/rapids/cudf/HostMemoryBuffer;J)V"); - if (handle_buffer_method == nullptr) { - throw cudf::jni::jni_exception("handleBuffer method"); - } - this->callback = add_global_ref(env, callback); + env->GetMethodID(cls, "handleBuffer", "(Lai/rapids/cudf/HostMemoryBuffer;J)V"); + if (handle_buffer_method == nullptr) { throw cudf::jni::jni_exception("handleBuffer method"); } + this->callback = add_global_ref(env, callback); this->host_memory_allocator = add_global_ref(env, host_memory_allocator); } - virtual ~jni_arrow_output_stream() { + virtual ~jni_arrow_output_stream() + { // This should normally be called by a JVM thread. If the JVM environment is missing then this // is likely being triggered by the C++ runtime during shutdown. In that case the JVM may // already be destroyed and this thread should not try to attach to get an environment. - JNIEnv *env = nullptr; - if (jvm->GetEnv(reinterpret_cast(&env), cudf::jni::MINIMUM_JNI_VERSION) == JNI_OK) { - callback = del_global_ref(env, callback); - current_buffer = del_global_ref(env, current_buffer); + JNIEnv* env = nullptr; + if (jvm->GetEnv(reinterpret_cast(&env), cudf::jni::MINIMUM_JNI_VERSION) == JNI_OK) { + callback = del_global_ref(env, callback); + current_buffer = del_global_ref(env, current_buffer); host_memory_allocator = del_global_ref(env, host_memory_allocator); } - callback = nullptr; - current_buffer = nullptr; + callback = nullptr; + current_buffer = nullptr; host_memory_allocator = nullptr; } - arrow::Status Write(const std::shared_ptr &data) override { + arrow::Status Write(const std::shared_ptr& data) override + { return Write(data->data(), data->size()); } - arrow::Status Write(const void *data, int64_t nbytes) override { - JNIEnv *env = cudf::jni::get_jni_env(jvm); - int64_t left_to_copy = nbytes; - const char *copy_from = static_cast(data); + arrow::Status Write(const void* data, int64_t nbytes) override + { + JNIEnv* env = cudf::jni::get_jni_env(jvm); + int64_t left_to_copy = nbytes; + const char* copy_from = static_cast(data); while (left_to_copy > 0) { long buffer_amount_available = current_buffer_len - current_buffer_written; if (buffer_amount_available <= 0) { @@ -273,8 +284,8 @@ class jni_arrow_output_stream final : public arrow::io::OutputStream { buffer_amount_available = current_buffer_len - current_buffer_written; } long amount_to_copy = - left_to_copy < buffer_amount_available ? left_to_copy : buffer_amount_available; - char *copy_to = current_buffer_data + current_buffer_written; + left_to_copy < buffer_amount_available ? left_to_copy : buffer_amount_available; + char* copy_to = current_buffer_data + current_buffer_written; std::memcpy(copy_to, copy_from, amount_to_copy); copy_from = copy_from + amount_to_copy; @@ -285,25 +296,28 @@ class jni_arrow_output_stream final : public arrow::io::OutputStream { return arrow::Status::OK(); } - arrow::Status Flush() override { + arrow::Status Flush() override + { if (current_buffer_written > 0) { - JNIEnv *env = cudf::jni::get_jni_env(jvm); + JNIEnv* env = cudf::jni::get_jni_env(jvm); handle_buffer(env, current_buffer, current_buffer_written); - current_buffer = del_global_ref(env, current_buffer); - current_buffer_len = 0; - current_buffer_data = nullptr; + current_buffer = del_global_ref(env, current_buffer); + current_buffer_len = 0; + current_buffer_data = nullptr; current_buffer_written = 0; } return arrow::Status::OK(); } - arrow::Status Close() override { - auto ret = Flush(); + arrow::Status Close() override + { + auto ret = Flush(); is_closed = true; return ret; } - arrow::Status Abort() override { + arrow::Status Abort() override + { is_closed = true; return arrow::Status::OK(); } @@ -312,99 +326,93 @@ class jni_arrow_output_stream final : public arrow::io::OutputStream { bool closed() const override { return is_closed; } -private: - void rotate_buffer(JNIEnv *env) { - if (current_buffer != nullptr) { - handle_buffer(env, current_buffer, current_buffer_written); - } - current_buffer = del_global_ref(env, current_buffer); - jobject tmp_buffer = allocate_host_buffer(env, alloc_size, true, host_memory_allocator); - current_buffer = add_global_ref(env, tmp_buffer); - current_buffer_len = get_host_buffer_length(env, current_buffer); - current_buffer_data = reinterpret_cast(get_host_buffer_address(env, current_buffer)); + private: + void rotate_buffer(JNIEnv* env) + { + if (current_buffer != nullptr) { handle_buffer(env, current_buffer, current_buffer_written); } + current_buffer = del_global_ref(env, current_buffer); + jobject tmp_buffer = allocate_host_buffer(env, alloc_size, true, host_memory_allocator); + current_buffer = add_global_ref(env, tmp_buffer); + current_buffer_len = get_host_buffer_length(env, current_buffer); + current_buffer_data = reinterpret_cast(get_host_buffer_address(env, current_buffer)); current_buffer_written = 0; } - void handle_buffer(JNIEnv *env, jobject buffer, jlong len) { + void handle_buffer(JNIEnv* env, jobject buffer, jlong len) + { env->CallVoidMethod(callback, handle_buffer_method, buffer, len); - if (env->ExceptionCheck()) { - throw std::runtime_error("handleBuffer threw an exception"); - } + if (env->ExceptionCheck()) { throw std::runtime_error("handleBuffer threw an exception"); } } - JavaVM *jvm; + JavaVM* jvm; jobject callback; jmethodID handle_buffer_method; - jobject current_buffer = nullptr; - char *current_buffer_data = nullptr; - long current_buffer_len = 0; + jobject current_buffer = nullptr; + char* current_buffer_data = nullptr; + long current_buffer_len = 0; long current_buffer_written = 0; - int64_t total_written = 0; - long alloc_size = MINIMUM_WRITE_BUFFER_SIZE; - bool is_closed = false; + int64_t total_written = 0; + long alloc_size = MINIMUM_WRITE_BUFFER_SIZE; + bool is_closed = false; jobject host_memory_allocator; }; class jni_arrow_input_stream final : public arrow::io::InputStream { -public: - explicit jni_arrow_input_stream(JNIEnv *env, jobject callback) - : mm(arrow::default_cpu_memory_manager()) { - if (env->GetJavaVM(&jvm) < 0) { - throw std::runtime_error("GetJavaVM failed"); - } + public: + explicit jni_arrow_input_stream(JNIEnv* env, jobject callback) + : mm(arrow::default_cpu_memory_manager()) + { + if (env->GetJavaVM(&jvm) < 0) { throw std::runtime_error("GetJavaVM failed"); } jclass cls = env->GetObjectClass(callback); - if (cls == nullptr) { - throw cudf::jni::jni_exception("class not found"); - } + if (cls == nullptr) { throw cudf::jni::jni_exception("class not found"); } read_into_method = env->GetMethodID(cls, "readInto", "(JJ)J"); - if (read_into_method == nullptr) { - throw cudf::jni::jni_exception("readInto method"); - } + if (read_into_method == nullptr) { throw cudf::jni::jni_exception("readInto method"); } this->callback = add_global_ref(env, callback); } - virtual ~jni_arrow_input_stream() { + virtual ~jni_arrow_input_stream() + { // This should normally be called by a JVM thread. If the JVM environment is missing then this // is likely being triggered by the C++ runtime during shutdown. In that case the JVM may // already be destroyed and this thread should not try to attach to get an environment. - JNIEnv *env = nullptr; - if (jvm->GetEnv(reinterpret_cast(&env), cudf::jni::MINIMUM_JNI_VERSION) == JNI_OK) { + JNIEnv* env = nullptr; + if (jvm->GetEnv(reinterpret_cast(&env), cudf::jni::MINIMUM_JNI_VERSION) == JNI_OK) { callback = del_global_ref(env, callback); } callback = nullptr; } - arrow::Result Read(int64_t nbytes, void *out) override { - JNIEnv *env = cudf::jni::get_jni_env(jvm); - jlong ret = read_into(env, ptr_as_jlong(out), nbytes); + arrow::Result Read(int64_t nbytes, void* out) override + { + JNIEnv* env = cudf::jni::get_jni_env(jvm); + jlong ret = read_into(env, ptr_as_jlong(out), nbytes); total_read += ret; return ret; } - arrow::Result> Read(int64_t nbytes) override { - JNIEnv *env = cudf::jni::get_jni_env(jvm); + arrow::Result> Read(int64_t nbytes) override + { + JNIEnv* env = cudf::jni::get_jni_env(jvm); arrow::Result> tmp_buffer = - arrow::AllocateResizableBuffer(nbytes); - if (!tmp_buffer.ok()) { - return tmp_buffer; - } - jlong amount_read = read_into(env, ptr_as_jlong((*tmp_buffer)->data()), nbytes); + arrow::AllocateResizableBuffer(nbytes); + if (!tmp_buffer.ok()) { return tmp_buffer; } + jlong amount_read = read_into(env, ptr_as_jlong((*tmp_buffer)->data()), nbytes); arrow::Status stat = (*tmp_buffer)->Resize(amount_read); - if (!stat.ok()) { - return stat; - } + if (!stat.ok()) { return stat; } return tmp_buffer; } - arrow::Status Close() override { + arrow::Status Close() override + { is_closed = true; return arrow::Status::OK(); } - arrow::Status Abort() override { + arrow::Status Abort() override + { is_closed = true; return arrow::Status::OK(); } @@ -413,57 +421,51 @@ class jni_arrow_input_stream final : public arrow::io::InputStream { bool closed() const override { return is_closed; } -private: - jlong read_into(JNIEnv *env, jlong addr, jlong len) { + private: + jlong read_into(JNIEnv* env, jlong addr, jlong len) + { jlong ret = env->CallLongMethod(callback, read_into_method, addr, len); - if (env->ExceptionCheck()) { - throw std::runtime_error("readInto threw an exception"); - } + if (env->ExceptionCheck()) { throw std::runtime_error("readInto threw an exception"); } return ret; } - JavaVM *jvm; + JavaVM* jvm; jobject callback; jmethodID read_into_method; int64_t total_read = 0; - bool is_closed = false; + bool is_closed = false; std::vector tmp_buffer; std::shared_ptr mm; }; class native_arrow_ipc_reader_handle final { -public: - explicit native_arrow_ipc_reader_handle(const std::string &file_name) { + public: + explicit native_arrow_ipc_reader_handle(const std::string& file_name) + { auto tmp_source = arrow::io::ReadableFile::Open(file_name); - if (!tmp_source.ok()) { - throw std::runtime_error(tmp_source.status().message()); - } - source = *tmp_source; + if (!tmp_source.ok()) { throw std::runtime_error(tmp_source.status().message()); } + source = *tmp_source; auto tmp_reader = arrow::ipc::RecordBatchStreamReader::Open(source); - if (!tmp_reader.ok()) { - throw std::runtime_error(tmp_reader.status().message()); - } + if (!tmp_reader.ok()) { throw std::runtime_error(tmp_reader.status().message()); } reader = *tmp_reader; } explicit native_arrow_ipc_reader_handle(std::shared_ptr source) - : source(source) { + : source(source) + { auto tmp_reader = arrow::ipc::RecordBatchStreamReader::Open(source); - if (!tmp_reader.ok()) { - throw std::runtime_error(tmp_reader.status().message()); - } + if (!tmp_reader.ok()) { throw std::runtime_error(tmp_reader.status().message()); } reader = *tmp_reader; } - std::shared_ptr next(int32_t row_target) { + std::shared_ptr next(int32_t row_target) + { int64_t total_rows = 0; - bool done = false; + bool done = false; std::vector> batches; while (!done) { arrow::Result> batch = reader->Next(); - if (!batch.ok()) { - throw std::runtime_error(batch.status().message()); - } + if (!batch.ok()) { throw std::runtime_error(batch.status().message()); } if (!*batch) { done = true; } else { @@ -477,17 +479,16 @@ class native_arrow_ipc_reader_handle final { return std::unique_ptr(); } arrow::Result> tmp = - arrow::Table::FromRecordBatches(reader->schema(), batches); - if (!tmp.ok()) { - throw std::runtime_error(tmp.status().message()); - } + arrow::Table::FromRecordBatches(reader->schema(), batches); + if (!tmp.ok()) { throw std::runtime_error(tmp.status().message()); } return *tmp; } std::shared_ptr source; std::shared_ptr reader; - void close() { + void close() + { auto status = source->Close(); if (!status.ok()) { throw std::runtime_error("Closing source failed with the following error: " + @@ -496,33 +497,44 @@ class native_arrow_ipc_reader_handle final { } }; -jlongArray convert_table_for_return(JNIEnv *env, std::unique_ptr &&table_result, - std::vector> &&extra_columns) { +jlongArray convert_table_for_return(JNIEnv* env, + std::unique_ptr&& table_result, + std::vector>&& extra_columns) +{ std::vector> ret = table_result->release(); - int table_cols = ret.size(); - int num_columns = table_cols + extra_columns.size(); + int table_cols = ret.size(); + int num_columns = table_cols + extra_columns.size(); cudf::jni::native_jlongArray outcol_handles(env, num_columns); - std::transform(ret.begin(), ret.end(), outcol_handles.begin(), - [](auto &col) { return release_as_jlong(col); }); - std::transform(extra_columns.begin(), extra_columns.end(), outcol_handles.begin() + table_cols, - [](auto &col) { return release_as_jlong(col); }); + std::transform(ret.begin(), ret.end(), outcol_handles.begin(), [](auto& col) { + return release_as_jlong(col); + }); + std::transform( + extra_columns.begin(), extra_columns.end(), outcol_handles.begin() + table_cols, [](auto& col) { + return release_as_jlong(col); + }); return outcol_handles.get_jArray(); } -jlongArray convert_table_for_return(JNIEnv *env, std::unique_ptr &table_result, - std::vector> &&extra_columns) { +jlongArray convert_table_for_return(JNIEnv* env, + std::unique_ptr& table_result, + std::vector>&& extra_columns) +{ return convert_table_for_return(env, std::move(table_result), std::move(extra_columns)); } -jlongArray convert_table_for_return(JNIEnv *env, std::unique_ptr &first_table, - std::unique_ptr &second_table) { +jlongArray convert_table_for_return(JNIEnv* env, + std::unique_ptr& first_table, + std::unique_ptr& second_table) +{ return convert_table_for_return(env, first_table, second_table->release()); } // Convert the JNI boolean array of key column sort order to a vector of cudf::order // for groupby. -std::vector resolve_column_order(JNIEnv *env, jbooleanArray jkeys_sort_desc, - int key_size) { +std::vector resolve_column_order(JNIEnv* env, + jbooleanArray jkeys_sort_desc, + int key_size) +{ cudf::jni::native_jbooleanArray keys_sort_desc(env, jkeys_sort_desc); auto keys_sort_num = keys_sort_desc.size(); // The number of column order should be 0 or equal to the number of key. @@ -532,18 +544,21 @@ std::vector resolve_column_order(JNIEnv *env, jbooleanArray jkeys_s std::vector column_order(keys_sort_num); if (keys_sort_num > 0) { - std::transform(keys_sort_desc.data(), keys_sort_desc.data() + keys_sort_num, - column_order.begin(), [](jboolean is_desc) { - return is_desc ? cudf::order::DESCENDING : cudf::order::ASCENDING; - }); + std::transform( + keys_sort_desc.data(), + keys_sort_desc.data() + keys_sort_num, + column_order.begin(), + [](jboolean is_desc) { return is_desc ? cudf::order::DESCENDING : cudf::order::ASCENDING; }); } return column_order; } // Convert the JNI boolean array of key column null order to a vector of cudf::null_order // for groupby. -std::vector resolve_null_precedence(JNIEnv *env, jbooleanArray jkeys_null_first, - int key_size) { +std::vector resolve_null_precedence(JNIEnv* env, + jbooleanArray jkeys_null_first, + int key_size) +{ cudf::jni::native_jbooleanArray keys_null_first(env, jkeys_null_first); auto null_order_num = keys_null_first.size(); // The number of null order should be 0 or equal to the number of key. @@ -553,8 +568,10 @@ std::vector resolve_null_precedence(JNIEnv *env, jbooleanArray std::vector null_precedence(null_order_num); if (null_order_num > 0) { - std::transform(keys_null_first.data(), keys_null_first.data() + null_order_num, - null_precedence.begin(), [](jboolean null_before) { + std::transform(keys_null_first.data(), + keys_null_first.data() + null_order_num, + null_precedence.begin(), + [](jboolean null_before) { return null_before ? cudf::null_order::BEFORE : cudf::null_order::AFTER; }); } @@ -563,49 +580,63 @@ std::vector resolve_null_precedence(JNIEnv *env, jbooleanArray namespace { -int set_column_metadata( - cudf::io::column_in_metadata &column_metadata, std::vector &col_names, - cudf::jni::native_jbooleanArray &nullability, cudf::jni::native_jbooleanArray &is_int96, - cudf::jni::native_jintArray &precisions, cudf::jni::native_jbooleanArray &is_map, - cudf::jni::native_jbooleanArray &hasParquetFieldIds, - cudf::jni::native_jintArray &parquetFieldIds, cudf::jni::native_jintArray &children, - int num_children, int read_index, cudf::jni::native_jbooleanArray &is_binary) { +int set_column_metadata(cudf::io::column_in_metadata& column_metadata, + std::vector& col_names, + cudf::jni::native_jbooleanArray& nullability, + cudf::jni::native_jbooleanArray& is_int96, + cudf::jni::native_jintArray& precisions, + cudf::jni::native_jbooleanArray& is_map, + cudf::jni::native_jbooleanArray& hasParquetFieldIds, + cudf::jni::native_jintArray& parquetFieldIds, + cudf::jni::native_jintArray& children, + int num_children, + int read_index, + cudf::jni::native_jbooleanArray& is_binary) +{ int write_index = 0; for (int i = 0; i < num_children; i++, write_index++) { cudf::io::column_in_metadata child; child.set_name(col_names[read_index]).set_nullability(nullability[read_index]); - if (precisions[read_index] > -1) { - child.set_decimal_precision(precisions[read_index]); - } - if (!is_int96.is_null()) { - child.set_int96_timestamps(is_int96[read_index]); - } - if (!is_binary.is_null()) { - child.set_output_as_binary(is_binary[read_index]); - } - if (is_map[read_index]) { - child.set_list_column_as_map(); - } + if (precisions[read_index] > -1) { child.set_decimal_precision(precisions[read_index]); } + if (!is_int96.is_null()) { child.set_int96_timestamps(is_int96[read_index]); } + if (!is_binary.is_null()) { child.set_output_as_binary(is_binary[read_index]); } + if (is_map[read_index]) { child.set_list_column_as_map(); } if (!parquetFieldIds.is_null() && hasParquetFieldIds[read_index]) { child.set_parquet_field_id(parquetFieldIds[read_index]); } column_metadata.add_child(child); int childs_children = children[read_index++]; if (childs_children > 0) { - read_index = set_column_metadata( - column_metadata.child(write_index), col_names, nullability, is_int96, precisions, is_map, - hasParquetFieldIds, parquetFieldIds, children, childs_children, read_index, is_binary); + read_index = set_column_metadata(column_metadata.child(write_index), + col_names, + nullability, + is_int96, + precisions, + is_map, + hasParquetFieldIds, + parquetFieldIds, + children, + childs_children, + read_index, + is_binary); } } return read_index; } -void createTableMetaData(JNIEnv *env, jint num_children, jobjectArray &j_col_names, - jintArray &j_children, jbooleanArray &j_col_nullability, - jbooleanArray &j_is_int96, jintArray &j_precisions, - jbooleanArray &j_is_map, cudf::io::table_input_metadata &metadata, - jbooleanArray &j_hasParquetFieldIds, jintArray &j_parquetFieldIds, - jbooleanArray &j_is_binary) { +void createTableMetaData(JNIEnv* env, + jint num_children, + jobjectArray& j_col_names, + jintArray& j_children, + jbooleanArray& j_col_nullability, + jbooleanArray& j_is_int96, + jintArray& j_precisions, + jbooleanArray& j_is_map, + cudf::io::table_input_metadata& metadata, + jbooleanArray& j_hasParquetFieldIds, + jintArray& j_parquetFieldIds, + jbooleanArray& j_is_binary) +{ cudf::jni::auto_set_device(env); cudf::jni::native_jstringArray col_names(env, j_col_names); cudf::jni::native_jbooleanArray col_nullability(env, j_col_nullability); @@ -622,11 +653,11 @@ void createTableMetaData(JNIEnv *env, jint num_children, jobjectArray &j_col_nam int top_level_children = num_children; metadata.column_metadata.resize(top_level_children); - int read_index = 0; // the read_index, which will be used to read the arrays + int read_index = 0; // the read_index, which will be used to read the arrays for (int i = read_index, write_index = 0; i < top_level_children; i++, write_index++) { metadata.column_metadata[write_index] - .set_name(cpp_names[read_index]) - .set_nullability(col_nullability[read_index]); + .set_name(cpp_names[read_index]) + .set_nullability(col_nullability[read_index]); if (precisions[read_index] > -1) { metadata.column_metadata[write_index].set_decimal_precision(precisions[read_index]); } @@ -636,37 +667,46 @@ void createTableMetaData(JNIEnv *env, jint num_children, jobjectArray &j_col_nam if (!is_binary.is_null()) { metadata.column_metadata[write_index].set_output_as_binary(is_binary[read_index]); } - if (is_map[read_index]) { - metadata.column_metadata[write_index].set_list_column_as_map(); - } + if (is_map[read_index]) { metadata.column_metadata[write_index].set_list_column_as_map(); } if (!parquetFieldIds.is_null() && hasParquetFieldIds[read_index]) { metadata.column_metadata[write_index].set_parquet_field_id(parquetFieldIds[read_index]); } int childs_children = children[read_index++]; if (childs_children > 0) { - read_index = - set_column_metadata(metadata.column_metadata[write_index], cpp_names, col_nullability, - is_int96, precisions, is_map, hasParquetFieldIds, parquetFieldIds, - children, childs_children, read_index, is_binary); + read_index = set_column_metadata(metadata.column_metadata[write_index], + cpp_names, + col_nullability, + is_int96, + precisions, + is_map, + hasParquetFieldIds, + parquetFieldIds, + children, + childs_children, + read_index, + is_binary); } } } // Check that window parameters are valid. -bool valid_window_parameters(native_jintArray const &values, - native_jpointerArray const &ops, - native_jintArray const &min_periods, native_jintArray const &preceding, - native_jintArray const &following) { +bool valid_window_parameters(native_jintArray const& values, + native_jpointerArray const& ops, + native_jintArray const& min_periods, + native_jintArray const& preceding, + native_jintArray const& following) +{ return values.size() == ops.size() && values.size() == min_periods.size() && values.size() == preceding.size() && values.size() == following.size(); } // Check that window parameters are valid. -bool valid_window_parameters(native_jintArray const &values, - native_jpointerArray const &ops, - native_jintArray const &min_periods, - native_jpointerArray const &preceding, - native_jpointerArray const &following) { +bool valid_window_parameters(native_jintArray const& values, + native_jpointerArray const& ops, + native_jintArray const& min_periods, + native_jpointerArray const& preceding, + native_jpointerArray const& following) +{ return values.size() == ops.size() && values.size() == min_periods.size() && values.size() == preceding.size() && values.size() == following.size(); } @@ -678,12 +718,13 @@ bool valid_window_parameters(native_jintArray const &values, // 2: Host address of the rmm::device_buffer instance that owns the left gather map data // 3: Device address of the gather map for the right table // 4: Host address of the rmm::device_buffer instance that owns the right gather map data -jlongArray gather_maps_to_java(JNIEnv *env, - std::pair>, - std::unique_ptr>> - maps) { +jlongArray gather_maps_to_java( + JNIEnv* env, + std::pair>, + std::unique_ptr>> maps) +{ // release the underlying device buffer to Java - auto left_map_buffer = std::make_unique(maps.first->release()); + auto left_map_buffer = std::make_unique(maps.first->release()); auto right_map_buffer = std::make_unique(maps.second->release()); cudf::jni::native_jlongArray result(env, 5); result[0] = static_cast(left_map_buffer->size()); @@ -699,27 +740,29 @@ jlongArray gather_maps_to_java(JNIEnv *env, // 0: Size of the gather map in bytes // 1: Device address of the gather map // 2: Host address of the rmm::device_buffer instance that owns the gather map data -jlongArray gather_map_to_java(JNIEnv *env, - std::unique_ptr> map) { +jlongArray gather_map_to_java(JNIEnv* env, + std::unique_ptr> map) +{ // release the underlying device buffer to Java cudf::jni::native_jlongArray result(env, 3); - result[0] = static_cast(map->size() * sizeof(cudf::size_type)); + result[0] = static_cast(map->size() * sizeof(cudf::size_type)); auto gather_map_buffer = std::make_unique(map->release()); - result[1] = ptr_as_jlong(gather_map_buffer->data()); - result[2] = release_as_jlong(gather_map_buffer); + result[1] = ptr_as_jlong(gather_map_buffer->data()); + result[2] = release_as_jlong(gather_map_buffer); return result.get_jArray(); } // Generate gather maps needed to manifest the result of an equi-join between two tables. template -jlongArray join_gather_maps(JNIEnv *env, jlong j_left_keys, jlong j_right_keys, - jboolean compare_nulls_equal, T join_func) { +jlongArray join_gather_maps( + JNIEnv* env, jlong j_left_keys, jlong j_right_keys, jboolean compare_nulls_equal, T join_func) +{ JNI_NULL_CHECK(env, j_left_keys, "left_table is null", NULL); JNI_NULL_CHECK(env, j_right_keys, "right_table is null", NULL); try { cudf::jni::auto_set_device(env); - auto left_keys = reinterpret_cast(j_left_keys); - auto right_keys = reinterpret_cast(j_right_keys); + auto left_keys = reinterpret_cast(j_left_keys); + auto right_keys = reinterpret_cast(j_right_keys); auto nulleq = compare_nulls_equal ? cudf::null_equality::EQUAL : cudf::null_equality::UNEQUAL; return gather_maps_to_java(env, join_func(*left_keys, *right_keys, nulleq)); } @@ -729,14 +772,17 @@ jlongArray join_gather_maps(JNIEnv *env, jlong j_left_keys, jlong j_right_keys, // Generate gather maps needed to manifest the result of an equi-join between a left table and // a hash table built from the join's right table. template -jlongArray hash_join_gather_maps(JNIEnv *env, jlong j_left_keys, jlong j_right_hash_join, - T join_func) { +jlongArray hash_join_gather_maps(JNIEnv* env, + jlong j_left_keys, + jlong j_right_hash_join, + T join_func) +{ JNI_NULL_CHECK(env, j_left_keys, "left table is null", NULL); JNI_NULL_CHECK(env, j_right_hash_join, "hash join is null", NULL); try { cudf::jni::auto_set_device(env); - auto left_keys = reinterpret_cast(j_left_keys); - auto hash_join = reinterpret_cast(j_right_hash_join); + auto left_keys = reinterpret_cast(j_left_keys); + auto hash_join = reinterpret_cast(j_right_hash_join); return gather_maps_to_java(env, join_func(*left_keys, *hash_join)); } CATCH_STD(env, NULL); @@ -744,32 +790,34 @@ jlongArray hash_join_gather_maps(JNIEnv *env, jlong j_left_keys, jlong j_right_h // Generate gather maps needed to manifest the result of a conditional join between two tables. template -jlongArray cond_join_gather_maps(JNIEnv *env, jlong j_left_table, jlong j_right_table, - jlong j_condition, T join_func) { +jlongArray cond_join_gather_maps( + JNIEnv* env, jlong j_left_table, jlong j_right_table, jlong j_condition, T join_func) +{ JNI_NULL_CHECK(env, j_left_table, "left_table is null", NULL); JNI_NULL_CHECK(env, j_right_table, "right_table is null", NULL); JNI_NULL_CHECK(env, j_condition, "condition is null", NULL); try { cudf::jni::auto_set_device(env); - auto left_table = reinterpret_cast(j_left_table); - auto right_table = reinterpret_cast(j_right_table); - auto condition = reinterpret_cast(j_condition); + auto left_table = reinterpret_cast(j_left_table); + auto right_table = reinterpret_cast(j_right_table); + auto condition = reinterpret_cast(j_condition); return gather_maps_to_java( - env, join_func(*left_table, *right_table, condition->get_top_expression())); + env, join_func(*left_table, *right_table, condition->get_top_expression())); } CATCH_STD(env, NULL); } // Generate a gather map needed to manifest the result of a semi/anti join between two tables. template -jlongArray join_gather_single_map(JNIEnv *env, jlong j_left_keys, jlong j_right_keys, - jboolean compare_nulls_equal, T join_func) { +jlongArray join_gather_single_map( + JNIEnv* env, jlong j_left_keys, jlong j_right_keys, jboolean compare_nulls_equal, T join_func) +{ JNI_NULL_CHECK(env, j_left_keys, "left_table is null", NULL); JNI_NULL_CHECK(env, j_right_keys, "right_table is null", NULL); try { cudf::jni::auto_set_device(env); - auto left_keys = reinterpret_cast(j_left_keys); - auto right_keys = reinterpret_cast(j_right_keys); + auto left_keys = reinterpret_cast(j_left_keys); + auto right_keys = reinterpret_cast(j_right_keys); auto nulleq = compare_nulls_equal ? cudf::null_equality::EQUAL : cudf::null_equality::UNEQUAL; return gather_map_to_java(env, join_func(*left_keys, *right_keys, nulleq)); } @@ -779,26 +827,33 @@ jlongArray join_gather_single_map(JNIEnv *env, jlong j_left_keys, jlong j_right_ // Generate a gather map needed to manifest the result of a conditional semi/anti join // between two tables. template -jlongArray cond_join_gather_single_map(JNIEnv *env, jlong j_left_table, jlong j_right_table, - jlong j_condition, T join_func) { +jlongArray cond_join_gather_single_map( + JNIEnv* env, jlong j_left_table, jlong j_right_table, jlong j_condition, T join_func) +{ JNI_NULL_CHECK(env, j_left_table, "left_table is null", NULL); JNI_NULL_CHECK(env, j_right_table, "right_table is null", NULL); JNI_NULL_CHECK(env, j_condition, "condition is null", NULL); try { cudf::jni::auto_set_device(env); - auto left_table = reinterpret_cast(j_left_table); - auto right_table = reinterpret_cast(j_right_table); - auto condition = reinterpret_cast(j_condition); + auto left_table = reinterpret_cast(j_left_table); + auto right_table = reinterpret_cast(j_right_table); + auto condition = reinterpret_cast(j_condition); return gather_map_to_java( - env, join_func(*left_table, *right_table, condition->get_top_expression())); + env, join_func(*left_table, *right_table, condition->get_top_expression())); } CATCH_STD(env, NULL); } template -jlongArray mixed_join_size(JNIEnv *env, jlong j_left_keys, jlong j_right_keys, - jlong j_left_condition, jlong j_right_condition, jlong j_condition, - jboolean j_nulls_equal, T join_size_func) { +jlongArray mixed_join_size(JNIEnv* env, + jlong j_left_keys, + jlong j_right_keys, + jlong j_left_condition, + jlong j_right_condition, + jlong j_condition, + jboolean j_nulls_equal, + T join_size_func) +{ JNI_NULL_CHECK(env, j_left_keys, "left keys table is null", 0); JNI_NULL_CHECK(env, j_right_keys, "right keys table is null", 0); JNI_NULL_CHECK(env, j_left_condition, "left condition table is null", 0); @@ -806,16 +861,19 @@ jlongArray mixed_join_size(JNIEnv *env, jlong j_left_keys, jlong j_right_keys, JNI_NULL_CHECK(env, j_condition, "condition is null", 0); try { cudf::jni::auto_set_device(env); - auto const left_keys = reinterpret_cast(j_left_keys); - auto const right_keys = reinterpret_cast(j_right_keys); - auto const left_condition = reinterpret_cast(j_left_condition); - auto const right_condition = reinterpret_cast(j_right_condition); - auto const condition = reinterpret_cast(j_condition); + auto const left_keys = reinterpret_cast(j_left_keys); + auto const right_keys = reinterpret_cast(j_right_keys); + auto const left_condition = reinterpret_cast(j_left_condition); + auto const right_condition = reinterpret_cast(j_right_condition); + auto const condition = reinterpret_cast(j_condition); auto const nulls_equal = - j_nulls_equal ? cudf::null_equality::EQUAL : cudf::null_equality::UNEQUAL; - auto [join_size, matches_per_row] = - join_size_func(*left_keys, *right_keys, *left_condition, *right_condition, - condition->get_top_expression(), nulls_equal); + j_nulls_equal ? cudf::null_equality::EQUAL : cudf::null_equality::UNEQUAL; + auto [join_size, matches_per_row] = join_size_func(*left_keys, + *right_keys, + *left_condition, + *right_condition, + condition->get_top_expression(), + nulls_equal); if (matches_per_row->size() > std::numeric_limits::max()) { throw std::runtime_error("Too many values in device buffer to convert into a column"); } @@ -823,17 +881,26 @@ jlongArray mixed_join_size(JNIEnv *env, jlong j_left_keys, jlong j_right_keys, auto col_data = matches_per_row->release(); cudf::jni::native_jlongArray result(env, 2); result[0] = static_cast(join_size); - result[1] = ptr_as_jlong(new cudf::column{cudf::data_type{cudf::type_id::INT32}, col_size, - std::move(col_data), rmm::device_buffer{}, 0}); + result[1] = ptr_as_jlong(new cudf::column{cudf::data_type{cudf::type_id::INT32}, + col_size, + std::move(col_data), + rmm::device_buffer{}, + 0}); return result.get_jArray(); } CATCH_STD(env, NULL); } template -jlongArray mixed_join_gather_maps(JNIEnv *env, jlong j_left_keys, jlong j_right_keys, - jlong j_left_condition, jlong j_right_condition, - jlong j_condition, jboolean j_nulls_equal, T join_func) { +jlongArray mixed_join_gather_maps(JNIEnv* env, + jlong j_left_keys, + jlong j_right_keys, + jlong j_left_condition, + jlong j_right_condition, + jlong j_condition, + jboolean j_nulls_equal, + T join_func) +{ JNI_NULL_CHECK(env, j_left_keys, "left keys table is null", 0); JNI_NULL_CHECK(env, j_right_keys, "right keys table is null", 0); JNI_NULL_CHECK(env, j_left_condition, "left condition table is null", 0); @@ -841,24 +908,34 @@ jlongArray mixed_join_gather_maps(JNIEnv *env, jlong j_left_keys, jlong j_right_ JNI_NULL_CHECK(env, j_condition, "condition is null", 0); try { cudf::jni::auto_set_device(env); - auto const left_keys = reinterpret_cast(j_left_keys); - auto const right_keys = reinterpret_cast(j_right_keys); - auto const left_condition = reinterpret_cast(j_left_condition); - auto const right_condition = reinterpret_cast(j_right_condition); - auto const condition = reinterpret_cast(j_condition); + auto const left_keys = reinterpret_cast(j_left_keys); + auto const right_keys = reinterpret_cast(j_right_keys); + auto const left_condition = reinterpret_cast(j_left_condition); + auto const right_condition = reinterpret_cast(j_right_condition); + auto const condition = reinterpret_cast(j_condition); auto const nulls_equal = - j_nulls_equal ? cudf::null_equality::EQUAL : cudf::null_equality::UNEQUAL; + j_nulls_equal ? cudf::null_equality::EQUAL : cudf::null_equality::UNEQUAL; return gather_maps_to_java(env, - join_func(*left_keys, *right_keys, *left_condition, *right_condition, - condition->get_top_expression(), nulls_equal)); + join_func(*left_keys, + *right_keys, + *left_condition, + *right_condition, + condition->get_top_expression(), + nulls_equal)); } CATCH_STD(env, NULL); } template -jlongArray mixed_join_gather_single_map(JNIEnv *env, jlong j_left_keys, jlong j_right_keys, - jlong j_left_condition, jlong j_right_condition, - jlong j_condition, jboolean j_nulls_equal, T join_func) { +jlongArray mixed_join_gather_single_map(JNIEnv* env, + jlong j_left_keys, + jlong j_right_keys, + jlong j_left_condition, + jlong j_right_condition, + jlong j_condition, + jboolean j_nulls_equal, + T join_func) +{ JNI_NULL_CHECK(env, j_left_keys, "left keys table is null", 0); JNI_NULL_CHECK(env, j_right_keys, "right keys table is null", 0); JNI_NULL_CHECK(env, j_left_condition, "left condition table is null", 0); @@ -866,35 +943,46 @@ jlongArray mixed_join_gather_single_map(JNIEnv *env, jlong j_left_keys, jlong j_ JNI_NULL_CHECK(env, j_condition, "condition is null", 0); try { cudf::jni::auto_set_device(env); - auto const left_keys = reinterpret_cast(j_left_keys); - auto const right_keys = reinterpret_cast(j_right_keys); - auto const left_condition = reinterpret_cast(j_left_condition); - auto const right_condition = reinterpret_cast(j_right_condition); - auto const condition = reinterpret_cast(j_condition); + auto const left_keys = reinterpret_cast(j_left_keys); + auto const right_keys = reinterpret_cast(j_right_keys); + auto const left_condition = reinterpret_cast(j_left_condition); + auto const right_condition = reinterpret_cast(j_right_condition); + auto const condition = reinterpret_cast(j_condition); auto const nulls_equal = - j_nulls_equal ? cudf::null_equality::EQUAL : cudf::null_equality::UNEQUAL; + j_nulls_equal ? cudf::null_equality::EQUAL : cudf::null_equality::UNEQUAL; return gather_map_to_java(env, - join_func(*left_keys, *right_keys, *left_condition, *right_condition, - condition->get_top_expression(), nulls_equal)); + join_func(*left_keys, + *right_keys, + *left_condition, + *right_condition, + condition->get_top_expression(), + nulls_equal)); } CATCH_STD(env, NULL); } -std::pair> -get_mixed_size_info(JNIEnv *env, jlong j_output_row_count, jlong j_matches_view) { +std::pair> get_mixed_size_info( + JNIEnv* env, jlong j_output_row_count, jlong j_matches_view) +{ auto const row_count = static_cast(j_output_row_count); - auto const matches = reinterpret_cast(j_matches_view); - return std::make_pair(row_count, cudf::device_span( - matches->template data(), matches->size())); + auto const matches = reinterpret_cast(j_matches_view); + return std::make_pair(row_count, + cudf::device_span( + matches->template data(), matches->size())); } -cudf::column_view remove_validity_from_col(cudf::column_view column_view) { +cudf::column_view remove_validity_from_col(cudf::column_view column_view) +{ if (!cudf::is_compound(column_view.type())) { if (column_view.nullable() && column_view.null_count() == 0) { // null_mask is allocated but no nulls present therefore we create a new column_view without // the null_mask to avoid things blowing up in reading the parquet file - return cudf::column_view(column_view.type(), column_view.size(), column_view.head(), nullptr, - 0, column_view.offset()); + return cudf::column_view(column_view.type(), + column_view.size(), + column_view.head(), + nullptr, + 0, + column_view.offset()); } else { return cudf::column_view(column_view); } @@ -905,17 +993,27 @@ cudf::column_view remove_validity_from_col(cudf::column_view column_view) { children.push_back(remove_validity_from_col(*it)); } if (!column_view.nullable() || column_view.null_count() != 0) { - return cudf::column_view(column_view.type(), column_view.size(), column_view.head(), - column_view.null_mask(), column_view.null_count(), - column_view.offset(), children); + return cudf::column_view(column_view.type(), + column_view.size(), + column_view.head(), + column_view.null_mask(), + column_view.null_count(), + column_view.offset(), + children); } else { - return cudf::column_view(column_view.type(), column_view.size(), column_view.head(), nullptr, - 0, column_view.offset(), children); + return cudf::column_view(column_view.type(), + column_view.size(), + column_view.head(), + nullptr, + 0, + column_view.offset(), + children); } } } -cudf::table_view remove_validity_if_needed(cudf::table_view *input_table_view) { +cudf::table_view remove_validity_if_needed(cudf::table_view* input_table_view) +{ std::vector views; views.reserve(input_table_view->num_columns()); for (auto it = input_table_view->begin(); it != input_table_view->end(); it++) { @@ -925,11 +1023,12 @@ cudf::table_view remove_validity_if_needed(cudf::table_view *input_table_view) { return cudf::table_view(views); } -cudf::io::schema_element read_schema_element(int &index, - cudf::jni::native_jintArray const &children, - cudf::jni::native_jstringArray const &names, - cudf::jni::native_jintArray const &types, - cudf::jni::native_jintArray const &scales) { +cudf::io::schema_element read_schema_element(int& index, + cudf::jni::native_jintArray const& children, + cudf::jni::native_jstringArray const& names, + cudf::jni::native_jintArray const& types, + cudf::jni::native_jintArray const& scales) +{ auto d_type = cudf::data_type{static_cast(types[index]), scales[index]}; if (d_type.id() == cudf::type_id::STRUCT || d_type.id() == cudf::type_id::LIST) { std::map child_elems; @@ -938,8 +1037,8 @@ cudf::io::schema_element read_schema_element(int &index, index++; for (int i = 0; i < num_children; i++) { child_elems.insert( - std::pair{names.get(index).get(), - cudf::jni::read_schema_element(index, children, names, types, scales)}); + std::pair{names.get(index).get(), + cudf::jni::read_schema_element(index, children, names, types, scales)}); } return cudf::io::schema_element{d_type, std::move(child_elems)}; } else { @@ -952,26 +1051,27 @@ cudf::io::schema_element read_schema_element(int &index, } } -void append_flattened_child_counts(cudf::io::column_name_info const &info, - std::vector &counts) { +void append_flattened_child_counts(cudf::io::column_name_info const& info, std::vector& counts) +{ counts.push_back(info.children.size()); - for (cudf::io::column_name_info const &child : info.children) { + for (cudf::io::column_name_info const& child : info.children) { append_flattened_child_counts(child, counts); } } -void append_flattened_child_names(cudf::io::column_name_info const &info, - std::vector &names) { +void append_flattened_child_names(cudf::io::column_name_info const& info, + std::vector& names) +{ names.push_back(info.name); - for (cudf::io::column_name_info const &child : info.children) { + for (cudf::io::column_name_info const& child : info.children) { append_flattened_child_names(child, names); } } -} // namespace +} // namespace -} // namespace jni -} // namespace cudf +} // namespace jni +} // namespace cudf using cudf::jni::convert_table_for_return; using cudf::jni::ptr_as_jlong; @@ -980,24 +1080,28 @@ using cudf::jni::release_as_jlong; extern "C" { // This is a method purely added for testing remove_validity_if_needed method -JNIEXPORT jlongArray JNICALL Java_ai_rapids_cudf_Table_removeNullMasksIfNeeded(JNIEnv *env, jclass, - jlong j_table_view) { +JNIEXPORT jlongArray JNICALL Java_ai_rapids_cudf_Table_removeNullMasksIfNeeded(JNIEnv* env, + jclass, + jlong j_table_view) +{ JNI_NULL_CHECK(env, j_table_view, "table view handle is null", 0); try { - cudf::table_view *tview = reinterpret_cast(j_table_view); + cudf::table_view* tview = reinterpret_cast(j_table_view); cudf::table_view result = cudf::jni::remove_validity_if_needed(tview); cudf::table m_tbl(result); std::vector> cols = m_tbl.release(); auto results = cudf::jni::native_jlongArray(env, cols.size()); - std::transform(cols.begin(), cols.end(), results.begin(), - [](auto &col) { return release_as_jlong(col); }); + std::transform( + cols.begin(), cols.end(), results.begin(), [](auto& col) { return release_as_jlong(col); }); return results.get_jArray(); } CATCH_STD(env, 0); } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Table_createCudfTableView(JNIEnv *env, jclass, - jlongArray j_cudf_columns) { +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Table_createCudfTableView(JNIEnv* env, + jclass, + jlongArray j_cudf_columns) +{ JNI_NULL_CHECK(env, j_cudf_columns, "columns are null", 0); try { @@ -1010,27 +1114,31 @@ JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Table_createCudfTableView(JNIEnv *en CATCH_STD(env, 0); } -JNIEXPORT void JNICALL Java_ai_rapids_cudf_Table_deleteCudfTable(JNIEnv *env, jclass, - jlong j_cudf_table_view) { +JNIEXPORT void JNICALL Java_ai_rapids_cudf_Table_deleteCudfTable(JNIEnv* env, + jclass, + jlong j_cudf_table_view) +{ JNI_NULL_CHECK(env, j_cudf_table_view, "table view handle is null", ); try { cudf::jni::auto_set_device(env); - delete reinterpret_cast(j_cudf_table_view); + delete reinterpret_cast(j_cudf_table_view); } CATCH_STD(env, ); } -JNIEXPORT jlongArray JNICALL Java_ai_rapids_cudf_Table_columnViewsFromPacked(JNIEnv *env, jclass, +JNIEXPORT jlongArray JNICALL Java_ai_rapids_cudf_Table_columnViewsFromPacked(JNIEnv* env, + jclass, jobject buffer_obj, - jlong j_data_address) { + jlong j_data_address) +{ // The GPU data address can be null when the table is empty, so it is not null-checked here. JNI_NULL_CHECK(env, buffer_obj, "metadata is null", nullptr); try { cudf::jni::auto_set_device(env); - void const *metadata_address = env->GetDirectBufferAddress(buffer_obj); + void const* metadata_address = env->GetDirectBufferAddress(buffer_obj); JNI_NULL_CHECK(env, metadata_address, "metadata buffer address is null", nullptr); - cudf::table_view table = cudf::unpack(static_cast(metadata_address), - reinterpret_cast(j_data_address)); + cudf::table_view table = cudf::unpack(static_cast(metadata_address), + reinterpret_cast(j_data_address)); cudf::jni::native_jlongArray views(env, table.num_columns()); for (int i = 0; i < table.num_columns(); i++) { // TODO Exception handling is not ideal, if no exceptions are thrown ownership of the new cv @@ -1051,12 +1159,13 @@ JNIEXPORT jlongArray JNICALL Java_ai_rapids_cudf_Table_columnViewsFromPacked(JNI CATCH_STD(env, nullptr); } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Table_sortOrder(JNIEnv *env, jclass, +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Table_sortOrder(JNIEnv* env, + jclass, jlong j_input_table, jlongArray j_sort_keys_columns, jbooleanArray j_is_descending, - jbooleanArray j_are_nulls_smallest) { - + jbooleanArray j_are_nulls_smallest) +{ // input validations & verifications JNI_NULL_CHECK(env, j_input_table, "input table is null", 0); JNI_NULL_CHECK(env, j_sort_keys_columns, "sort keys columns is null", 0); @@ -1071,19 +1180,21 @@ JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Table_sortOrder(JNIEnv *env, jclass, const cudf::jni::native_jbooleanArray n_is_descending(env, j_is_descending); jsize num_columns_is_desc = n_is_descending.size(); - JNI_ARG_CHECK(env, num_columns_is_desc == num_columns, - "columns and is_descending lengths don't match", 0); + JNI_ARG_CHECK( + env, num_columns_is_desc == num_columns, "columns and is_descending lengths don't match", 0); const cudf::jni::native_jbooleanArray n_are_nulls_smallest(env, j_are_nulls_smallest); jsize num_columns_null_smallest = n_are_nulls_smallest.size(); - JNI_ARG_CHECK(env, num_columns_null_smallest == num_columns, - "columns and is_descending lengths don't match", 0); + JNI_ARG_CHECK(env, + num_columns_null_smallest == num_columns, + "columns and is_descending lengths don't match", + 0); std::vector order = - n_is_descending.transform_if_else(cudf::order::DESCENDING, cudf::order::ASCENDING); + n_is_descending.transform_if_else(cudf::order::DESCENDING, cudf::order::ASCENDING); std::vector null_order = - n_are_nulls_smallest.transform_if_else(cudf::null_order::BEFORE, cudf::null_order::AFTER); + n_are_nulls_smallest.transform_if_else(cudf::null_order::BEFORE, cudf::null_order::AFTER); std::vector sort_keys = n_sort_keys_columns.get_dereferenced(); return release_as_jlong(cudf::sorted_order(cudf::table_view{sort_keys}, order, null_order)); @@ -1091,12 +1202,13 @@ JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Table_sortOrder(JNIEnv *env, jclass, CATCH_STD(env, 0); } -JNIEXPORT jlongArray JNICALL Java_ai_rapids_cudf_Table_orderBy(JNIEnv *env, jclass, +JNIEXPORT jlongArray JNICALL Java_ai_rapids_cudf_Table_orderBy(JNIEnv* env, + jclass, jlong j_input_table, jlongArray j_sort_keys_columns, jbooleanArray j_is_descending, - jbooleanArray j_are_nulls_smallest) { - + jbooleanArray j_are_nulls_smallest) +{ // input validations & verifications JNI_NULL_CHECK(env, j_input_table, "input table is null", NULL); JNI_NULL_CHECK(env, j_sort_keys_columns, "sort keys columns is null", NULL); @@ -1111,36 +1223,39 @@ JNIEXPORT jlongArray JNICALL Java_ai_rapids_cudf_Table_orderBy(JNIEnv *env, jcla const cudf::jni::native_jbooleanArray n_is_descending(env, j_is_descending); jsize num_columns_is_desc = n_is_descending.size(); - JNI_ARG_CHECK(env, num_columns_is_desc == num_columns, - "columns and is_descending lengths don't match", 0); + JNI_ARG_CHECK( + env, num_columns_is_desc == num_columns, "columns and is_descending lengths don't match", 0); const cudf::jni::native_jbooleanArray n_are_nulls_smallest(env, j_are_nulls_smallest); jsize num_columns_null_smallest = n_are_nulls_smallest.size(); - JNI_ARG_CHECK(env, num_columns_null_smallest == num_columns, - "columns and areNullsSmallest lengths don't match", 0); + JNI_ARG_CHECK(env, + num_columns_null_smallest == num_columns, + "columns and areNullsSmallest lengths don't match", + 0); std::vector order = - n_is_descending.transform_if_else(cudf::order::DESCENDING, cudf::order::ASCENDING); + n_is_descending.transform_if_else(cudf::order::DESCENDING, cudf::order::ASCENDING); std::vector null_order = - n_are_nulls_smallest.transform_if_else(cudf::null_order::BEFORE, cudf::null_order::AFTER); + n_are_nulls_smallest.transform_if_else(cudf::null_order::BEFORE, cudf::null_order::AFTER); std::vector sort_keys = n_sort_keys_columns.get_dereferenced(); auto sorted_col = cudf::sorted_order(cudf::table_view{sort_keys}, order, null_order); - auto const input_table = reinterpret_cast(j_input_table); + auto const input_table = reinterpret_cast(j_input_table); return convert_table_for_return(env, cudf::gather(*input_table, sorted_col->view())); } CATCH_STD(env, NULL); } -JNIEXPORT jlongArray JNICALL Java_ai_rapids_cudf_Table_merge(JNIEnv *env, jclass, +JNIEXPORT jlongArray JNICALL Java_ai_rapids_cudf_Table_merge(JNIEnv* env, + jclass, jlongArray j_table_handles, jintArray j_sort_key_indexes, jbooleanArray j_is_descending, - jbooleanArray j_are_nulls_smallest) { - + jbooleanArray j_are_nulls_smallest) +{ // input validations & verifications JNI_NULL_CHECK(env, j_table_handles, "input tables are null", NULL); JNI_NULL_CHECK(env, j_sort_key_indexes, "key indexes is null", NULL); @@ -1156,20 +1271,24 @@ JNIEXPORT jlongArray JNICALL Java_ai_rapids_cudf_Table_merge(JNIEnv *env, jclass const cudf::jni::native_jbooleanArray n_is_descending(env, j_is_descending); jsize num_columns_is_desc = n_is_descending.size(); - JNI_ARG_CHECK(env, num_columns_is_desc == num_columns, - "columns and is_descending lengths don't match", NULL); + JNI_ARG_CHECK(env, + num_columns_is_desc == num_columns, + "columns and is_descending lengths don't match", + NULL); const cudf::jni::native_jbooleanArray n_are_nulls_smallest(env, j_are_nulls_smallest); jsize num_columns_null_smallest = n_are_nulls_smallest.size(); - JNI_ARG_CHECK(env, num_columns_null_smallest == num_columns, - "columns and areNullsSmallest lengths don't match", NULL); + JNI_ARG_CHECK(env, + num_columns_null_smallest == num_columns, + "columns and areNullsSmallest lengths don't match", + NULL); std::vector indexes = n_sort_key_indexes.to_vector(); std::vector order = - n_is_descending.transform_if_else(cudf::order::DESCENDING, cudf::order::ASCENDING); + n_is_descending.transform_if_else(cudf::order::DESCENDING, cudf::order::ASCENDING); std::vector null_order = - n_are_nulls_smallest.transform_if_else(cudf::null_order::BEFORE, cudf::null_order::AFTER); + n_are_nulls_smallest.transform_if_else(cudf::null_order::BEFORE, cudf::null_order::AFTER); std::vector tables = n_table_handles.get_dereferenced(); return convert_table_for_return(env, cudf::merge(tables, indexes, order, null_order)); @@ -1177,11 +1296,23 @@ JNIEXPORT jlongArray JNICALL Java_ai_rapids_cudf_Table_merge(JNIEnv *env, jclass CATCH_STD(env, NULL); } -JNIEXPORT jlongArray JNICALL Java_ai_rapids_cudf_Table_readCSVFromDataSource( - JNIEnv *env, jclass, jobjectArray col_names, jintArray j_types, jintArray j_scales, - jobjectArray filter_col_names, jint header_row, jbyte delim, jint j_quote_style, jbyte quote, - jbyte comment, jobjectArray null_values, jobjectArray true_values, jobjectArray false_values, - jlong ds_handle) { +JNIEXPORT jlongArray JNICALL +Java_ai_rapids_cudf_Table_readCSVFromDataSource(JNIEnv* env, + jclass, + jobjectArray col_names, + jintArray j_types, + jintArray j_scales, + jobjectArray filter_col_names, + jint header_row, + jbyte delim, + jint j_quote_style, + jbyte quote, + jbyte comment, + jobjectArray null_values, + jobjectArray true_values, + jobjectArray false_values, + jlong ds_handle) +{ JNI_NULL_CHECK(env, null_values, "null_values must be supplied, even if it is empty", NULL); JNI_NULL_CHECK(env, ds_handle, "no data source handle given", NULL); @@ -1199,8 +1330,11 @@ JNIEXPORT jlongArray JNICALL Java_ai_rapids_cudf_Table_readCSVFromDataSource( JNI_THROW_NEW(env, cudf::jni::ILLEGAL_ARG_CLASS, "types and scales must match size", NULL); } data_types.reserve(n_types.size()); - std::transform(n_types.begin(), n_types.end(), n_scales.begin(), - std::back_inserter(data_types), [](auto type, auto scale) { + std::transform(n_types.begin(), + n_types.end(), + n_scales.begin(), + std::back_inserter(data_types), + [](auto type, auto scale) { return cudf::data_type{static_cast(type), scale}; }); } @@ -1210,37 +1344,50 @@ JNIEXPORT jlongArray JNICALL Java_ai_rapids_cudf_Table_readCSVFromDataSource( cudf::jni::native_jstringArray n_false_values(env, false_values); cudf::jni::native_jstringArray n_filter_col_names(env, filter_col_names); - auto ds = reinterpret_cast(ds_handle); + auto ds = reinterpret_cast(ds_handle); cudf::io::source_info source{ds}; auto const quote_style = static_cast(j_quote_style); cudf::io::csv_reader_options opts = cudf::io::csv_reader_options::builder(source) - .delimiter(delim) - .header(header_row) - .names(n_col_names.as_cpp_vector()) - .dtypes(data_types) - .use_cols_names(n_filter_col_names.as_cpp_vector()) - .true_values(n_true_values.as_cpp_vector()) - .false_values(n_false_values.as_cpp_vector()) - .na_values(n_null_values.as_cpp_vector()) - .keep_default_na(false) - .na_filter(n_null_values.size() > 0) - .quoting(quote_style) - .quotechar(quote) - .comment(comment) - .build(); + .delimiter(delim) + .header(header_row) + .names(n_col_names.as_cpp_vector()) + .dtypes(data_types) + .use_cols_names(n_filter_col_names.as_cpp_vector()) + .true_values(n_true_values.as_cpp_vector()) + .false_values(n_false_values.as_cpp_vector()) + .na_values(n_null_values.as_cpp_vector()) + .keep_default_na(false) + .na_filter(n_null_values.size() > 0) + .quoting(quote_style) + .quotechar(quote) + .comment(comment) + .build(); return convert_table_for_return(env, cudf::io::read_csv(opts).tbl); } CATCH_STD(env, NULL); } -JNIEXPORT jlongArray JNICALL Java_ai_rapids_cudf_Table_readCSV( - JNIEnv *env, jclass, jobjectArray col_names, jintArray j_types, jintArray j_scales, - jobjectArray filter_col_names, jstring inputfilepath, jlong buffer, jlong buffer_length, - jint header_row, jbyte delim, jint j_quote_style, jbyte quote, jbyte comment, - jobjectArray null_values, jobjectArray true_values, jobjectArray false_values) { +JNIEXPORT jlongArray JNICALL Java_ai_rapids_cudf_Table_readCSV(JNIEnv* env, + jclass, + jobjectArray col_names, + jintArray j_types, + jintArray j_scales, + jobjectArray filter_col_names, + jstring inputfilepath, + jlong buffer, + jlong buffer_length, + jint header_row, + jbyte delim, + jint j_quote_style, + jbyte quote, + jbyte comment, + jobjectArray null_values, + jobjectArray true_values, + jobjectArray false_values) +{ JNI_NULL_CHECK(env, null_values, "null_values must be supplied, even if it is empty", NULL); bool read_buffer = true; @@ -1248,8 +1395,8 @@ JNIEXPORT jlongArray JNICALL Java_ai_rapids_cudf_Table_readCSV( JNI_NULL_CHECK(env, inputfilepath, "input file or buffer must be supplied", NULL); read_buffer = false; } else if (inputfilepath != NULL) { - JNI_THROW_NEW(env, cudf::jni::ILLEGAL_ARG_CLASS, - "cannot pass in both a buffer and an inputfilepath", NULL); + JNI_THROW_NEW( + env, cudf::jni::ILLEGAL_ARG_CLASS, "cannot pass in both a buffer and an inputfilepath", NULL); } else if (buffer_length <= 0) { JNI_THROW_NEW(env, cudf::jni::ILLEGAL_ARG_CLASS, "An empty buffer is not supported", NULL); } @@ -1268,8 +1415,11 @@ JNIEXPORT jlongArray JNICALL Java_ai_rapids_cudf_Table_readCSV( JNI_THROW_NEW(env, cudf::jni::ILLEGAL_ARG_CLASS, "types and scales must match size", NULL); } data_types.reserve(n_types.size()); - std::transform(n_types.begin(), n_types.end(), n_scales.begin(), - std::back_inserter(data_types), [](auto type, auto scale) { + std::transform(n_types.begin(), + n_types.end(), + n_scales.begin(), + std::back_inserter(data_types), + [](auto type, auto scale) { return cudf::data_type{static_cast(type), scale}; }); } @@ -1284,36 +1434,45 @@ JNIEXPORT jlongArray JNICALL Java_ai_rapids_cudf_Table_readCSV( cudf::jni::native_jstringArray n_false_values(env, false_values); cudf::jni::native_jstringArray n_filter_col_names(env, filter_col_names); - auto source = read_buffer ? cudf::io::source_info{reinterpret_cast(buffer), - static_cast(buffer_length)} : - cudf::io::source_info{filename.get()}; + auto source = read_buffer ? cudf::io::source_info{reinterpret_cast(buffer), + static_cast(buffer_length)} + : cudf::io::source_info{filename.get()}; auto const quote_style = static_cast(j_quote_style); cudf::io::csv_reader_options opts = cudf::io::csv_reader_options::builder(source) - .delimiter(delim) - .header(header_row) - .names(n_col_names.as_cpp_vector()) - .dtypes(data_types) - .use_cols_names(n_filter_col_names.as_cpp_vector()) - .true_values(n_true_values.as_cpp_vector()) - .false_values(n_false_values.as_cpp_vector()) - .na_values(n_null_values.as_cpp_vector()) - .keep_default_na(false) - .na_filter(n_null_values.size() > 0) - .quoting(quote_style) - .quotechar(quote) - .comment(comment) - .build(); + .delimiter(delim) + .header(header_row) + .names(n_col_names.as_cpp_vector()) + .dtypes(data_types) + .use_cols_names(n_filter_col_names.as_cpp_vector()) + .true_values(n_true_values.as_cpp_vector()) + .false_values(n_false_values.as_cpp_vector()) + .na_values(n_null_values.as_cpp_vector()) + .keep_default_na(false) + .na_filter(n_null_values.size() > 0) + .quoting(quote_style) + .quotechar(quote) + .comment(comment) + .build(); return convert_table_for_return(env, cudf::io::read_csv(opts).tbl); } CATCH_STD(env, NULL); } -JNIEXPORT void JNICALL Java_ai_rapids_cudf_Table_writeCSVToFile( - JNIEnv *env, jclass, jlong j_table_handle, jobjectArray j_column_names, jboolean include_header, - jstring j_row_delimiter, jbyte j_field_delimiter, jstring j_null_value, jstring j_true_value, - jstring j_false_value, jint j_quote_style, jstring j_output_path) { +JNIEXPORT void JNICALL Java_ai_rapids_cudf_Table_writeCSVToFile(JNIEnv* env, + jclass, + jlong j_table_handle, + jobjectArray j_column_names, + jboolean include_header, + jstring j_row_delimiter, + jbyte j_field_delimiter, + jstring j_null_value, + jstring j_true_value, + jstring j_false_value, + jint j_quote_style, + jstring j_output_path) +{ JNI_NULL_CHECK(env, j_table_handle, "table handle cannot be null.", ); JNI_NULL_CHECK(env, j_column_names, "column name array cannot be null", ); JNI_NULL_CHECK(env, j_row_delimiter, "row delimiter cannot be null", ); @@ -1327,37 +1486,47 @@ JNIEXPORT void JNICALL Java_ai_rapids_cudf_Table_writeCSVToFile( cudf::jni::auto_set_device(env); auto const native_output_path = cudf::jni::native_jstring{env, j_output_path}; - auto const output_path = native_output_path.get(); + auto const output_path = native_output_path.get(); - auto const table = reinterpret_cast(j_table_handle); + auto const table = reinterpret_cast(j_table_handle); auto const n_column_names = cudf::jni::native_jstringArray{env, j_column_names}; - auto const column_names = n_column_names.as_cpp_vector(); + auto const column_names = n_column_names.as_cpp_vector(); auto const line_terminator = cudf::jni::native_jstring{env, j_row_delimiter}; - auto const na_rep = cudf::jni::native_jstring{env, j_null_value}; - auto const true_value = cudf::jni::native_jstring{env, j_true_value}; - auto const false_value = cudf::jni::native_jstring{env, j_false_value}; - auto const quote_style = static_cast(j_quote_style); + auto const na_rep = cudf::jni::native_jstring{env, j_null_value}; + auto const true_value = cudf::jni::native_jstring{env, j_true_value}; + auto const false_value = cudf::jni::native_jstring{env, j_false_value}; + auto const quote_style = static_cast(j_quote_style); auto options = cudf::io::csv_writer_options::builder(cudf::io::sink_info{output_path}, *table) - .names(column_names) - .include_header(static_cast(include_header)) - .line_terminator(line_terminator.get()) - .inter_column_delimiter(j_field_delimiter) - .na_rep(na_rep.get()) - .true_value(true_value.get()) - .false_value(false_value.get()) - .quoting(quote_style); + .names(column_names) + .include_header(static_cast(include_header)) + .line_terminator(line_terminator.get()) + .inter_column_delimiter(j_field_delimiter) + .na_rep(na_rep.get()) + .true_value(true_value.get()) + .false_value(false_value.get()) + .quoting(quote_style); cudf::io::write_csv(options.build()); } CATCH_STD(env, ); } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Table_startWriteCSVToBuffer( - JNIEnv *env, jclass, jobjectArray j_column_names, jboolean include_header, - jstring j_row_delimiter, jbyte j_field_delimiter, jstring j_null_value, jstring j_true_value, - jstring j_false_value, jint j_quote_style, jobject j_buffer, jobject host_memory_allocator) { +JNIEXPORT jlong JNICALL +Java_ai_rapids_cudf_Table_startWriteCSVToBuffer(JNIEnv* env, + jclass, + jobjectArray j_column_names, + jboolean include_header, + jstring j_row_delimiter, + jbyte j_field_delimiter, + jstring j_null_value, + jstring j_true_value, + jstring j_false_value, + jint j_quote_style, + jobject j_buffer, + jobject host_memory_allocator) +{ JNI_NULL_CHECK(env, j_column_names, "column name array cannot be null", 0); JNI_NULL_CHECK(env, j_row_delimiter, "row delimiter cannot be null", 0); JNI_NULL_CHECK(env, j_field_delimiter, "field delimiter cannot be null", 0); @@ -1368,42 +1537,44 @@ JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Table_startWriteCSVToBuffer( cudf::jni::auto_set_device(env); auto data_sink = - std::make_unique(env, j_buffer, host_memory_allocator); + std::make_unique(env, j_buffer, host_memory_allocator); auto const n_column_names = cudf::jni::native_jstringArray{env, j_column_names}; - auto const column_names = n_column_names.as_cpp_vector(); + auto const column_names = n_column_names.as_cpp_vector(); auto const line_terminator = cudf::jni::native_jstring{env, j_row_delimiter}; - auto const na_rep = cudf::jni::native_jstring{env, j_null_value}; - auto const true_value = cudf::jni::native_jstring{env, j_true_value}; - auto const false_value = cudf::jni::native_jstring{env, j_false_value}; - auto const quote_style = static_cast(j_quote_style); + auto const na_rep = cudf::jni::native_jstring{env, j_null_value}; + auto const true_value = cudf::jni::native_jstring{env, j_true_value}; + auto const false_value = cudf::jni::native_jstring{env, j_false_value}; + auto const quote_style = static_cast(j_quote_style); auto options = cudf::io::csv_writer_options::builder(cudf::io::sink_info{data_sink.get()}, cudf::table_view{}) - .names(column_names) - .include_header(static_cast(include_header)) - .line_terminator(line_terminator.get()) - .inter_column_delimiter(j_field_delimiter) - .na_rep(na_rep.get()) - .true_value(true_value.get()) - .false_value(false_value.get()) - .quoting(quote_style) - .build(); + .names(column_names) + .include_header(static_cast(include_header)) + .line_terminator(line_terminator.get()) + .inter_column_delimiter(j_field_delimiter) + .na_rep(na_rep.get()) + .true_value(true_value.get()) + .false_value(false_value.get()) + .quoting(quote_style) + .build(); return ptr_as_jlong(new cudf::jni::io::csv_chunked_writer{options, data_sink}); } CATCH_STD(env, 0); } -JNIEXPORT void JNICALL Java_ai_rapids_cudf_Table_writeCSVChunkToBuffer(JNIEnv *env, jclass, +JNIEXPORT void JNICALL Java_ai_rapids_cudf_Table_writeCSVChunkToBuffer(JNIEnv* env, + jclass, jlong j_writer_handle, - jlong j_table_handle) { + jlong j_table_handle) +{ JNI_NULL_CHECK(env, j_writer_handle, "writer handle cannot be null.", ); JNI_NULL_CHECK(env, j_table_handle, "table handle cannot be null.", ); - auto const table = reinterpret_cast(j_table_handle); - auto writer = reinterpret_cast(j_writer_handle); + auto const table = reinterpret_cast(j_table_handle); + auto writer = reinterpret_cast(j_writer_handle); try { cudf::jni::auto_set_device(env); @@ -1412,13 +1583,15 @@ JNIEXPORT void JNICALL Java_ai_rapids_cudf_Table_writeCSVChunkToBuffer(JNIEnv *e CATCH_STD(env, ); } -JNIEXPORT void JNICALL Java_ai_rapids_cudf_Table_endWriteCSVToBuffer(JNIEnv *env, jclass, - jlong j_writer_handle) { +JNIEXPORT void JNICALL Java_ai_rapids_cudf_Table_endWriteCSVToBuffer(JNIEnv* env, + jclass, + jlong j_writer_handle) +{ JNI_NULL_CHECK(env, j_writer_handle, "writer handle cannot be null.", ); using cudf::jni::io::csv_chunked_writer; auto writer = - std::unique_ptr{reinterpret_cast(j_writer_handle)}; + std::unique_ptr{reinterpret_cast(j_writer_handle)}; try { cudf::jni::auto_set_device(env); @@ -1427,44 +1600,57 @@ JNIEXPORT void JNICALL Java_ai_rapids_cudf_Table_endWriteCSVToBuffer(JNIEnv *env CATCH_STD(env, ); } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Table_readAndInferJSONFromDataSource( - JNIEnv *env, jclass, jboolean day_first, jboolean lines, jboolean recover_with_null, - jboolean normalize_single_quotes, jboolean normalize_whitespace, jboolean mixed_types_as_string, - jboolean keep_quotes, jlong ds_handle) { - +JNIEXPORT jlong JNICALL +Java_ai_rapids_cudf_Table_readAndInferJSONFromDataSource(JNIEnv* env, + jclass, + jboolean day_first, + jboolean lines, + jboolean recover_with_null, + jboolean normalize_single_quotes, + jboolean normalize_whitespace, + jboolean mixed_types_as_string, + jboolean keep_quotes, + jlong ds_handle) +{ JNI_NULL_CHECK(env, ds_handle, "no data source handle given", 0); try { cudf::jni::auto_set_device(env); - auto ds = reinterpret_cast(ds_handle); + auto ds = reinterpret_cast(ds_handle); cudf::io::source_info source{ds}; - auto const recovery_mode = recover_with_null ? - cudf::io::json_recovery_mode_t::RECOVER_WITH_NULL : - cudf::io::json_recovery_mode_t::FAIL; + auto const recovery_mode = recover_with_null ? cudf::io::json_recovery_mode_t::RECOVER_WITH_NULL + : cudf::io::json_recovery_mode_t::FAIL; cudf::io::json_reader_options_builder opts = - cudf::io::json_reader_options::builder(source) - .dayfirst(static_cast(day_first)) - .lines(static_cast(lines)) - .recovery_mode(recovery_mode) - .normalize_single_quotes(static_cast(normalize_single_quotes)) - .normalize_whitespace(static_cast(normalize_whitespace)) - .mixed_types_as_string(mixed_types_as_string) - .keep_quotes(keep_quotes); + cudf::io::json_reader_options::builder(source) + .dayfirst(static_cast(day_first)) + .lines(static_cast(lines)) + .recovery_mode(recovery_mode) + .normalize_single_quotes(static_cast(normalize_single_quotes)) + .normalize_whitespace(static_cast(normalize_whitespace)) + .mixed_types_as_string(mixed_types_as_string) + .keep_quotes(keep_quotes); auto result = - std::make_unique(cudf::io::read_json(opts.build())); + std::make_unique(cudf::io::read_json(opts.build())); return reinterpret_cast(result.release()); } CATCH_STD(env, 0); } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Table_readAndInferJSON( - JNIEnv *env, jclass, jlong buffer, jlong buffer_length, jboolean day_first, jboolean lines, - jboolean recover_with_null, jboolean normalize_single_quotes, jboolean normalize_whitespace, - jboolean mixed_types_as_string, jboolean keep_quotes) { - +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Table_readAndInferJSON(JNIEnv* env, + jclass, + jlong buffer, + jlong buffer_length, + jboolean day_first, + jboolean lines, + jboolean recover_with_null, + jboolean normalize_single_quotes, + jboolean normalize_whitespace, + jboolean mixed_types_as_string, + jboolean keep_quotes) +{ JNI_NULL_CHECK(env, buffer, "buffer cannot be null", 0); if (buffer_length <= 0) { JNI_THROW_NEW(env, cudf::jni::ILLEGAL_ARG_CLASS, "An empty buffer is not supported", 0); @@ -1473,50 +1659,52 @@ JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Table_readAndInferJSON( try { cudf::jni::auto_set_device(env); - auto source = cudf::io::source_info{reinterpret_cast(buffer), + auto source = cudf::io::source_info{reinterpret_cast(buffer), static_cast(buffer_length)}; - auto const recovery_mode = recover_with_null ? - cudf::io::json_recovery_mode_t::RECOVER_WITH_NULL : - cudf::io::json_recovery_mode_t::FAIL; + auto const recovery_mode = recover_with_null ? cudf::io::json_recovery_mode_t::RECOVER_WITH_NULL + : cudf::io::json_recovery_mode_t::FAIL; cudf::io::json_reader_options_builder opts = - cudf::io::json_reader_options::builder(source) - .dayfirst(static_cast(day_first)) - .lines(static_cast(lines)) - .recovery_mode(recovery_mode) - .normalize_single_quotes(static_cast(normalize_single_quotes)) - .normalize_whitespace(static_cast(normalize_whitespace)) - .mixed_types_as_string(mixed_types_as_string) - .keep_quotes(keep_quotes); + cudf::io::json_reader_options::builder(source) + .dayfirst(static_cast(day_first)) + .lines(static_cast(lines)) + .recovery_mode(recovery_mode) + .normalize_single_quotes(static_cast(normalize_single_quotes)) + .normalize_whitespace(static_cast(normalize_whitespace)) + .mixed_types_as_string(mixed_types_as_string) + .keep_quotes(keep_quotes); auto result = - std::make_unique(cudf::io::read_json(opts.build())); + std::make_unique(cudf::io::read_json(opts.build())); return reinterpret_cast(result.release()); } CATCH_STD(env, 0); } -JNIEXPORT void JNICALL Java_ai_rapids_cudf_TableWithMeta_close(JNIEnv *env, jclass, jlong handle) { +JNIEXPORT void JNICALL Java_ai_rapids_cudf_TableWithMeta_close(JNIEnv* env, jclass, jlong handle) +{ JNI_NULL_CHECK(env, handle, "handle is null", ); try { cudf::jni::auto_set_device(env); - delete reinterpret_cast(handle); + delete reinterpret_cast(handle); } CATCH_STD(env, ); } -JNIEXPORT jintArray JNICALL -Java_ai_rapids_cudf_TableWithMeta_getFlattenedChildCounts(JNIEnv *env, jclass, jlong handle) { +JNIEXPORT jintArray JNICALL Java_ai_rapids_cudf_TableWithMeta_getFlattenedChildCounts(JNIEnv* env, + jclass, + jlong handle) +{ JNI_NULL_CHECK(env, handle, "handle is null", nullptr); try { cudf::jni::auto_set_device(env); - auto ptr = reinterpret_cast(handle); + auto ptr = reinterpret_cast(handle); std::vector counts; counts.push_back(ptr->metadata.schema_info.size()); - for (cudf::io::column_name_info const &child : ptr->metadata.schema_info) { + for (cudf::io::column_name_info const& child : ptr->metadata.schema_info) { cudf::jni::append_flattened_child_counts(child, counts); } @@ -1532,21 +1720,22 @@ Java_ai_rapids_cudf_TableWithMeta_getFlattenedChildCounts(JNIEnv *env, jclass, j } JNIEXPORT jobjectArray JNICALL -Java_ai_rapids_cudf_TableWithMeta_getFlattenedColumnNames(JNIEnv *env, jclass, jlong handle) { +Java_ai_rapids_cudf_TableWithMeta_getFlattenedColumnNames(JNIEnv* env, jclass, jlong handle) +{ JNI_NULL_CHECK(env, handle, "handle is null", nullptr); try { cudf::jni::auto_set_device(env); - auto ptr = reinterpret_cast(handle); + auto ptr = reinterpret_cast(handle); std::vector names; names.push_back("ROOT"); - for (cudf::io::column_name_info const &child : ptr->metadata.schema_info) { + for (cudf::io::column_name_info const& child : ptr->metadata.schema_info) { cudf::jni::append_flattened_child_names(child, names); } auto length = names.size(); - auto ret = static_cast( - env->NewObjectArray(length, env->FindClass("java/lang/String"), nullptr)); + auto ret = static_cast( + env->NewObjectArray(length, env->FindClass("java/lang/String"), nullptr)); for (size_t i = 0; i < length; i++) { env->SetObjectArrayElement(ret, i, env->NewStringUTF(names[i].c_str())); } @@ -1556,13 +1745,15 @@ Java_ai_rapids_cudf_TableWithMeta_getFlattenedColumnNames(JNIEnv *env, jclass, j CATCH_STD(env, nullptr); } -JNIEXPORT jlongArray JNICALL Java_ai_rapids_cudf_TableWithMeta_releaseTable(JNIEnv *env, jclass, - jlong handle) { +JNIEXPORT jlongArray JNICALL Java_ai_rapids_cudf_TableWithMeta_releaseTable(JNIEnv* env, + jclass, + jlong handle) +{ JNI_NULL_CHECK(env, handle, "handle is null", nullptr); try { cudf::jni::auto_set_device(env); - auto ptr = reinterpret_cast(handle); + auto ptr = reinterpret_cast(handle); if (ptr->tbl) { return convert_table_for_return(env, ptr->tbl); } else { @@ -1572,12 +1763,22 @@ JNIEXPORT jlongArray JNICALL Java_ai_rapids_cudf_TableWithMeta_releaseTable(JNIE CATCH_STD(env, nullptr); } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Table_readJSONFromDataSource( - JNIEnv *env, jclass, jintArray j_num_children, jobjectArray col_names, jintArray j_types, - jintArray j_scales, jboolean day_first, jboolean lines, jboolean recover_with_null, - jboolean normalize_single_quotes, jboolean normalize_whitespace, jboolean mixed_types_as_string, - jboolean keep_quotes, jlong ds_handle) { - +JNIEXPORT jlong JNICALL +Java_ai_rapids_cudf_Table_readJSONFromDataSource(JNIEnv* env, + jclass, + jintArray j_num_children, + jobjectArray col_names, + jintArray j_types, + jintArray j_scales, + jboolean day_first, + jboolean lines, + jboolean recover_with_null, + jboolean normalize_single_quotes, + jboolean normalize_whitespace, + jboolean mixed_types_as_string, + jboolean keep_quotes, + jlong ds_handle) +{ JNI_NULL_CHECK(env, ds_handle, "no data source handle given", 0); try { @@ -1596,41 +1797,41 @@ JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Table_readJSONFromDataSource( JNI_THROW_NEW(env, cudf::jni::ILLEGAL_ARG_CLASS, "types and num children must match null", 0); } - auto ds = reinterpret_cast(ds_handle); + auto ds = reinterpret_cast(ds_handle); cudf::io::source_info source{ds}; cudf::io::json_recovery_mode_t recovery_mode = - recover_with_null ? cudf::io::json_recovery_mode_t::RECOVER_WITH_NULL : - cudf::io::json_recovery_mode_t::FAIL; + recover_with_null ? cudf::io::json_recovery_mode_t::RECOVER_WITH_NULL + : cudf::io::json_recovery_mode_t::FAIL; cudf::io::json_reader_options_builder opts = - cudf::io::json_reader_options::builder(source) - .dayfirst(static_cast(day_first)) - .lines(static_cast(lines)) - .recovery_mode(recovery_mode) - .normalize_single_quotes(static_cast(normalize_single_quotes)) - .normalize_whitespace(static_cast(normalize_whitespace)) - .mixed_types_as_string(mixed_types_as_string) - .keep_quotes(keep_quotes); + cudf::io::json_reader_options::builder(source) + .dayfirst(static_cast(day_first)) + .lines(static_cast(lines)) + .recovery_mode(recovery_mode) + .normalize_single_quotes(static_cast(normalize_single_quotes)) + .normalize_whitespace(static_cast(normalize_whitespace)) + .mixed_types_as_string(mixed_types_as_string) + .keep_quotes(keep_quotes); if (!n_types.is_null()) { if (n_types.size() != n_scales.size()) { JNI_THROW_NEW(env, cudf::jni::ILLEGAL_ARG_CLASS, "types and scales must match size", 0); } if (n_col_names.size() != n_types.size()) { - JNI_THROW_NEW(env, cudf::jni::ILLEGAL_ARG_CLASS, "types and column names must match size", - 0); + JNI_THROW_NEW( + env, cudf::jni::ILLEGAL_ARG_CLASS, "types and column names must match size", 0); } if (n_children.size() != n_types.size()) { - JNI_THROW_NEW(env, cudf::jni::ILLEGAL_ARG_CLASS, "types and num children must match size", - 0); + JNI_THROW_NEW( + env, cudf::jni::ILLEGAL_ARG_CLASS, "types and num children must match size", 0); } std::map data_types; int at = 0; while (at < n_types.size()) { data_types.insert(std::pair{ - n_col_names.get(at).get(), - cudf::jni::read_schema_element(at, n_children, n_col_names, n_types, n_scales)}); + n_col_names.get(at).get(), + cudf::jni::read_schema_element(at, n_children, n_col_names, n_types, n_scales)}); } opts.dtypes(data_types); } else { @@ -1638,27 +1839,37 @@ JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Table_readJSONFromDataSource( } auto result = - std::make_unique(cudf::io::read_json(opts.build())); + std::make_unique(cudf::io::read_json(opts.build())); return reinterpret_cast(result.release()); } CATCH_STD(env, 0); } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Table_readJSON( - JNIEnv *env, jclass, jintArray j_num_children, jobjectArray col_names, jintArray j_types, - jintArray j_scales, jstring inputfilepath, jlong buffer, jlong buffer_length, - jboolean day_first, jboolean lines, jboolean recover_with_null, - jboolean normalize_single_quotes, jboolean normalize_whitespace, jboolean mixed_types_as_string, - jboolean keep_quotes) { - +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Table_readJSON(JNIEnv* env, + jclass, + jintArray j_num_children, + jobjectArray col_names, + jintArray j_types, + jintArray j_scales, + jstring inputfilepath, + jlong buffer, + jlong buffer_length, + jboolean day_first, + jboolean lines, + jboolean recover_with_null, + jboolean normalize_single_quotes, + jboolean normalize_whitespace, + jboolean mixed_types_as_string, + jboolean keep_quotes) +{ bool read_buffer = true; if (buffer == 0) { JNI_NULL_CHECK(env, inputfilepath, "input file or buffer must be supplied", 0); read_buffer = false; } else if (inputfilepath != NULL) { - JNI_THROW_NEW(env, cudf::jni::ILLEGAL_ARG_CLASS, - "cannot pass in both a buffer and an inputfilepath", 0); + JNI_THROW_NEW( + env, cudf::jni::ILLEGAL_ARG_CLASS, "cannot pass in both a buffer and an inputfilepath", 0); } else if (buffer_length <= 0) { JNI_THROW_NEW(env, cudf::jni::ILLEGAL_ARG_CLASS, "An empty buffer is not supported", 0); } @@ -1684,42 +1895,42 @@ JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Table_readJSON( JNI_THROW_NEW(env, cudf::jni::ILLEGAL_ARG_CLASS, "inputfilepath can't be empty", 0); } - auto source = read_buffer ? cudf::io::source_info{reinterpret_cast(buffer), - static_cast(buffer_length)} : - cudf::io::source_info{filename.get()}; + auto source = read_buffer ? cudf::io::source_info{reinterpret_cast(buffer), + static_cast(buffer_length)} + : cudf::io::source_info{filename.get()}; cudf::io::json_recovery_mode_t recovery_mode = - recover_with_null ? cudf::io::json_recovery_mode_t::RECOVER_WITH_NULL : - cudf::io::json_recovery_mode_t::FAIL; + recover_with_null ? cudf::io::json_recovery_mode_t::RECOVER_WITH_NULL + : cudf::io::json_recovery_mode_t::FAIL; cudf::io::json_reader_options_builder opts = - cudf::io::json_reader_options::builder(source) - .dayfirst(static_cast(day_first)) - .lines(static_cast(lines)) - .recovery_mode(recovery_mode) - .normalize_single_quotes(static_cast(normalize_single_quotes)) - .normalize_whitespace(static_cast(normalize_whitespace)) - .mixed_types_as_string(mixed_types_as_string) - .keep_quotes(keep_quotes); + cudf::io::json_reader_options::builder(source) + .dayfirst(static_cast(day_first)) + .lines(static_cast(lines)) + .recovery_mode(recovery_mode) + .normalize_single_quotes(static_cast(normalize_single_quotes)) + .normalize_whitespace(static_cast(normalize_whitespace)) + .mixed_types_as_string(mixed_types_as_string) + .keep_quotes(keep_quotes); if (!n_types.is_null()) { if (n_types.size() != n_scales.size()) { JNI_THROW_NEW(env, cudf::jni::ILLEGAL_ARG_CLASS, "types and scales must match size", 0); } if (n_col_names.size() != n_types.size()) { - JNI_THROW_NEW(env, cudf::jni::ILLEGAL_ARG_CLASS, "types and column names must match size", - 0); + JNI_THROW_NEW( + env, cudf::jni::ILLEGAL_ARG_CLASS, "types and column names must match size", 0); } if (n_children.size() != n_types.size()) { - JNI_THROW_NEW(env, cudf::jni::ILLEGAL_ARG_CLASS, "types and num children must match size", - 0); + JNI_THROW_NEW( + env, cudf::jni::ILLEGAL_ARG_CLASS, "types and num children must match size", 0); } std::map data_types; int at = 0; while (at < n_types.size()) { data_types.insert(std::pair{ - n_col_names.get(at).get(), - cudf::jni::read_schema_element(at, n_children, n_col_names, n_types, n_scales)}); + n_col_names.get(at).get(), + cudf::jni::read_schema_element(at, n_children, n_col_names, n_types, n_scales)}); } opts.dtypes(data_types); } else { @@ -1727,17 +1938,21 @@ JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Table_readJSON( } auto result = - std::make_unique(cudf::io::read_json(opts.build())); + std::make_unique(cudf::io::read_json(opts.build())); return reinterpret_cast(result.release()); } CATCH_STD(env, 0); } -JNIEXPORT jlongArray JNICALL Java_ai_rapids_cudf_Table_readParquetFromDataSource( - JNIEnv *env, jclass, jobjectArray filter_col_names, jbooleanArray j_col_binary_read, jint unit, - jlong ds_handle) { - +JNIEXPORT jlongArray JNICALL +Java_ai_rapids_cudf_Table_readParquetFromDataSource(JNIEnv* env, + jclass, + jobjectArray filter_col_names, + jbooleanArray j_col_binary_read, + jint unit, + jlong ds_handle) +{ JNI_NULL_CHECK(env, ds_handle, "no data source handle given", 0); JNI_NULL_CHECK(env, j_col_binary_read, "null col_binary_read", 0); @@ -1747,7 +1962,7 @@ JNIEXPORT jlongArray JNICALL Java_ai_rapids_cudf_Table_readParquetFromDataSource cudf::jni::native_jstringArray n_filter_col_names(env, filter_col_names); cudf::jni::native_jbooleanArray n_col_binary_read(env, j_col_binary_read); - auto ds = reinterpret_cast(ds_handle); + auto ds = reinterpret_cast(ds_handle); cudf::io::source_info source{ds}; auto builder = cudf::io::parquet_reader_options::builder(source); @@ -1756,26 +1971,31 @@ JNIEXPORT jlongArray JNICALL Java_ai_rapids_cudf_Table_readParquetFromDataSource } cudf::io::parquet_reader_options opts = - builder.convert_strings_to_categories(false) - .timestamp_type(cudf::data_type(static_cast(unit))) - .build(); + builder.convert_strings_to_categories(false) + .timestamp_type(cudf::data_type(static_cast(unit))) + .build(); return convert_table_for_return(env, cudf::io::read_parquet(opts).tbl); } CATCH_STD(env, NULL); } -JNIEXPORT jlongArray JNICALL Java_ai_rapids_cudf_Table_readParquet( - JNIEnv *env, jclass, jobjectArray filter_col_names, jbooleanArray j_col_binary_read, - jstring inputfilepath, jlong buffer, jlong buffer_length, jint unit) { - +JNIEXPORT jlongArray JNICALL Java_ai_rapids_cudf_Table_readParquet(JNIEnv* env, + jclass, + jobjectArray filter_col_names, + jbooleanArray j_col_binary_read, + jstring inputfilepath, + jlong buffer, + jlong buffer_length, + jint unit) +{ JNI_NULL_CHECK(env, j_col_binary_read, "null col_binary_read", 0); bool read_buffer = true; if (buffer == 0) { JNI_NULL_CHECK(env, inputfilepath, "input file or buffer must be supplied", NULL); read_buffer = false; } else if (inputfilepath != NULL) { - JNI_THROW_NEW(env, cudf::jni::ILLEGAL_ARG_CLASS, - "cannot pass in both a buffer and an inputfilepath", NULL); + JNI_THROW_NEW( + env, cudf::jni::ILLEGAL_ARG_CLASS, "cannot pass in both a buffer and an inputfilepath", NULL); } else if (buffer_length <= 0) { JNI_THROW_NEW(env, cudf::jni::ILLEGAL_ARG_CLASS, "An empty buffer is not supported", NULL); } @@ -1790,9 +2010,9 @@ JNIEXPORT jlongArray JNICALL Java_ai_rapids_cudf_Table_readParquet( cudf::jni::native_jstringArray n_filter_col_names(env, filter_col_names); cudf::jni::native_jbooleanArray n_col_binary_read(env, j_col_binary_read); - auto source = read_buffer ? cudf::io::source_info(reinterpret_cast(buffer), - static_cast(buffer_length)) : - cudf::io::source_info(filename.get()); + auto source = read_buffer ? cudf::io::source_info(reinterpret_cast(buffer), + static_cast(buffer_length)) + : cudf::io::source_info(filename.get()); auto builder = cudf::io::parquet_reader_options::builder(source); if (n_filter_col_names.size() > 0) { @@ -1800,17 +2020,17 @@ JNIEXPORT jlongArray JNICALL Java_ai_rapids_cudf_Table_readParquet( } cudf::io::parquet_reader_options opts = - builder.convert_strings_to_categories(false) - .timestamp_type(cudf::data_type(static_cast(unit))) - .build(); + builder.convert_strings_to_categories(false) + .timestamp_type(cudf::data_type(static_cast(unit))) + .build(); return convert_table_for_return(env, cudf::io::read_parquet(opts).tbl); } CATCH_STD(env, NULL); } JNIEXPORT jlongArray JNICALL Java_ai_rapids_cudf_Table_readAvroFromDataSource( - JNIEnv *env, jclass, jobjectArray filter_col_names, jlong ds_handle) { - + JNIEnv* env, jclass, jobjectArray filter_col_names, jlong ds_handle) +{ JNI_NULL_CHECK(env, ds_handle, "no data source handle given", 0); try { @@ -1818,28 +2038,30 @@ JNIEXPORT jlongArray JNICALL Java_ai_rapids_cudf_Table_readAvroFromDataSource( cudf::jni::native_jstringArray n_filter_col_names(env, filter_col_names); - auto ds = reinterpret_cast(ds_handle); + auto ds = reinterpret_cast(ds_handle); cudf::io::source_info source{ds}; cudf::io::avro_reader_options opts = cudf::io::avro_reader_options::builder(source) - .columns(n_filter_col_names.as_cpp_vector()) - .build(); + .columns(n_filter_col_names.as_cpp_vector()) + .build(); return convert_table_for_return(env, cudf::io::read_avro(opts).tbl); } CATCH_STD(env, NULL); } -JNIEXPORT jlongArray JNICALL Java_ai_rapids_cudf_Table_readAvro(JNIEnv *env, jclass, +JNIEXPORT jlongArray JNICALL Java_ai_rapids_cudf_Table_readAvro(JNIEnv* env, + jclass, jobjectArray filter_col_names, - jstring inputfilepath, jlong buffer, - jlong buffer_length) { - + jstring inputfilepath, + jlong buffer, + jlong buffer_length) +{ const bool read_buffer = (buffer != 0); if (!read_buffer) { JNI_NULL_CHECK(env, inputfilepath, "input file or buffer must be supplied", NULL); } else if (inputfilepath != NULL) { - JNI_THROW_NEW(env, cudf::jni::ILLEGAL_ARG_CLASS, - "cannot pass in both a buffer and an inputfilepath", NULL); + JNI_THROW_NEW( + env, cudf::jni::ILLEGAL_ARG_CLASS, "cannot pass in both a buffer and an inputfilepath", NULL); } else if (buffer_length <= 0) { JNI_THROW_NEW(env, cudf::jni::ILLEGAL_ARG_CLASS, "An empty buffer is not supported", NULL); } @@ -1853,24 +2075,38 @@ JNIEXPORT jlongArray JNICALL Java_ai_rapids_cudf_Table_readAvro(JNIEnv *env, jcl cudf::jni::native_jstringArray n_filter_col_names(env, filter_col_names); - auto source = read_buffer ? cudf::io::source_info(reinterpret_cast(buffer), - static_cast(buffer_length)) : - cudf::io::source_info(filename.get()); + auto source = read_buffer ? cudf::io::source_info(reinterpret_cast(buffer), + static_cast(buffer_length)) + : cudf::io::source_info(filename.get()); cudf::io::avro_reader_options opts = cudf::io::avro_reader_options::builder(source) - .columns(n_filter_col_names.as_cpp_vector()) - .build(); + .columns(n_filter_col_names.as_cpp_vector()) + .build(); return convert_table_for_return(env, cudf::io::read_avro(opts).tbl); } CATCH_STD(env, NULL); } -JNIEXPORT long JNICALL Java_ai_rapids_cudf_Table_writeParquetBufferBegin( - JNIEnv *env, jclass, jobjectArray j_col_names, jint j_num_children, jintArray j_children, - jbooleanArray j_col_nullability, jobjectArray j_metadata_keys, jobjectArray j_metadata_values, - jint j_compression, jint j_stats_freq, jbooleanArray j_isInt96, jintArray j_precisions, - jbooleanArray j_is_map, jbooleanArray j_is_binary, jbooleanArray j_hasParquetFieldIds, - jintArray j_parquetFieldIds, jobject consumer, jobject host_memory_allocator) { +JNIEXPORT long JNICALL +Java_ai_rapids_cudf_Table_writeParquetBufferBegin(JNIEnv* env, + jclass, + jobjectArray j_col_names, + jint j_num_children, + jintArray j_children, + jbooleanArray j_col_nullability, + jobjectArray j_metadata_keys, + jobjectArray j_metadata_values, + jint j_compression, + jint j_stats_freq, + jbooleanArray j_isInt96, + jintArray j_precisions, + jbooleanArray j_is_map, + jbooleanArray j_is_binary, + jbooleanArray j_hasParquetFieldIds, + jintArray j_parquetFieldIds, + jobject consumer, + jobject host_memory_allocator) +{ JNI_NULL_CHECK(env, j_col_names, "null columns", 0); JNI_NULL_CHECK(env, j_col_nullability, "null nullability", 0); JNI_NULL_CHECK(env, j_metadata_keys, "null metadata keys", 0); @@ -1878,23 +2114,34 @@ JNIEXPORT long JNICALL Java_ai_rapids_cudf_Table_writeParquetBufferBegin( JNI_NULL_CHECK(env, consumer, "null consumer", 0); try { std::unique_ptr data_sink( - new cudf::jni::jni_writer_data_sink(env, consumer, host_memory_allocator)); + new cudf::jni::jni_writer_data_sink(env, consumer, host_memory_allocator)); using namespace cudf::io; using namespace cudf::jni; sink_info sink{data_sink.get()}; table_input_metadata metadata; - createTableMetaData(env, j_num_children, j_col_names, j_children, j_col_nullability, j_isInt96, - j_precisions, j_is_map, metadata, j_hasParquetFieldIds, j_parquetFieldIds, + createTableMetaData(env, + j_num_children, + j_col_names, + j_children, + j_col_nullability, + j_isInt96, + j_precisions, + j_is_map, + metadata, + j_hasParquetFieldIds, + j_parquetFieldIds, j_is_binary); - auto meta_keys = cudf::jni::native_jstringArray{env, j_metadata_keys}.as_cpp_vector(); + auto meta_keys = cudf::jni::native_jstringArray{env, j_metadata_keys}.as_cpp_vector(); auto meta_values = cudf::jni::native_jstringArray{env, j_metadata_values}.as_cpp_vector(); std::map kv_metadata; - std::transform(meta_keys.begin(), meta_keys.end(), meta_values.begin(), + std::transform(meta_keys.begin(), + meta_keys.end(), + meta_values.begin(), std::inserter(kv_metadata, kv_metadata.end()), - [](auto const &key, auto const &value) { + [](auto const& key, auto const& value) { // The metadata value will be ignored if it is empty. // We modify it into a space character to workaround such issue. return std::make_pair(key, value.empty() ? std::string(" ") : value); @@ -1902,27 +2149,40 @@ JNIEXPORT long JNICALL Java_ai_rapids_cudf_Table_writeParquetBufferBegin( auto stats = std::make_shared(); chunked_parquet_writer_options opts = - chunked_parquet_writer_options::builder(sink) - .metadata(std::move(metadata)) - .compression(static_cast(j_compression)) - .stats_level(static_cast(j_stats_freq)) - .key_value_metadata({kv_metadata}) - .compression_statistics(stats) - .build(); + chunked_parquet_writer_options::builder(sink) + .metadata(std::move(metadata)) + .compression(static_cast(j_compression)) + .stats_level(static_cast(j_stats_freq)) + .key_value_metadata({kv_metadata}) + .compression_statistics(stats) + .build(); auto writer_ptr = std::make_unique(opts); - cudf::jni::native_parquet_writer_handle *ret = new cudf::jni::native_parquet_writer_handle( - std::move(writer_ptr), std::move(data_sink), std::move(stats)); + cudf::jni::native_parquet_writer_handle* ret = new cudf::jni::native_parquet_writer_handle( + std::move(writer_ptr), std::move(data_sink), std::move(stats)); return ptr_as_jlong(ret); } CATCH_STD(env, 0) } -JNIEXPORT long JNICALL Java_ai_rapids_cudf_Table_writeParquetFileBegin( - JNIEnv *env, jclass, jobjectArray j_col_names, jint j_num_children, jintArray j_children, - jbooleanArray j_col_nullability, jobjectArray j_metadata_keys, jobjectArray j_metadata_values, - jint j_compression, jint j_stats_freq, jbooleanArray j_isInt96, jintArray j_precisions, - jbooleanArray j_is_map, jbooleanArray j_is_binary, jbooleanArray j_hasParquetFieldIds, - jintArray j_parquetFieldIds, jstring j_output_path) { +JNIEXPORT long JNICALL +Java_ai_rapids_cudf_Table_writeParquetFileBegin(JNIEnv* env, + jclass, + jobjectArray j_col_names, + jint j_num_children, + jintArray j_children, + jbooleanArray j_col_nullability, + jobjectArray j_metadata_keys, + jobjectArray j_metadata_values, + jint j_compression, + jint j_stats_freq, + jbooleanArray j_isInt96, + jintArray j_precisions, + jbooleanArray j_is_map, + jbooleanArray j_is_binary, + jbooleanArray j_hasParquetFieldIds, + jintArray j_parquetFieldIds, + jstring j_output_path) +{ JNI_NULL_CHECK(env, j_col_names, "null columns", 0); JNI_NULL_CHECK(env, j_col_nullability, "null nullability", 0); JNI_NULL_CHECK(env, j_metadata_keys, "null metadata keys", 0); @@ -1934,17 +2194,28 @@ JNIEXPORT long JNICALL Java_ai_rapids_cudf_Table_writeParquetFileBegin( using namespace cudf::io; using namespace cudf::jni; table_input_metadata metadata; - createTableMetaData(env, j_num_children, j_col_names, j_children, j_col_nullability, j_isInt96, - j_precisions, j_is_map, metadata, j_hasParquetFieldIds, j_parquetFieldIds, + createTableMetaData(env, + j_num_children, + j_col_names, + j_children, + j_col_nullability, + j_isInt96, + j_precisions, + j_is_map, + metadata, + j_hasParquetFieldIds, + j_parquetFieldIds, j_is_binary); - auto meta_keys = cudf::jni::native_jstringArray{env, j_metadata_keys}.as_cpp_vector(); + auto meta_keys = cudf::jni::native_jstringArray{env, j_metadata_keys}.as_cpp_vector(); auto meta_values = cudf::jni::native_jstringArray{env, j_metadata_values}.as_cpp_vector(); std::map kv_metadata; - std::transform(meta_keys.begin(), meta_keys.end(), meta_values.begin(), + std::transform(meta_keys.begin(), + meta_keys.end(), + meta_values.begin(), std::inserter(kv_metadata, kv_metadata.end()), - [](auto const &key, auto const &value) { + [](auto const& key, auto const& value) { // The metadata value will be ignored if it is empty. // We modify it into a space character to workaround such issue. return std::make_pair(key, value.empty() ? std::string(" ") : value); @@ -1953,33 +2224,33 @@ JNIEXPORT long JNICALL Java_ai_rapids_cudf_Table_writeParquetFileBegin( sink_info sink{output_path.get()}; auto stats = std::make_shared(); chunked_parquet_writer_options opts = - chunked_parquet_writer_options::builder(sink) - .metadata(std::move(metadata)) - .compression(static_cast(j_compression)) - .stats_level(static_cast(j_stats_freq)) - .key_value_metadata({kv_metadata}) - .compression_statistics(stats) - .build(); + chunked_parquet_writer_options::builder(sink) + .metadata(std::move(metadata)) + .compression(static_cast(j_compression)) + .stats_level(static_cast(j_stats_freq)) + .key_value_metadata({kv_metadata}) + .compression_statistics(stats) + .build(); auto writer_ptr = std::make_unique(opts); - cudf::jni::native_parquet_writer_handle *ret = new cudf::jni::native_parquet_writer_handle( - std::move(writer_ptr), nullptr, std::move(stats)); + cudf::jni::native_parquet_writer_handle* ret = + new cudf::jni::native_parquet_writer_handle(std::move(writer_ptr), nullptr, std::move(stats)); return ptr_as_jlong(ret); } CATCH_STD(env, 0) } -JNIEXPORT void JNICALL Java_ai_rapids_cudf_Table_writeParquetChunk(JNIEnv *env, jclass, - jlong j_state, jlong j_table, - jlong mem_size) { +JNIEXPORT void JNICALL Java_ai_rapids_cudf_Table_writeParquetChunk( + JNIEnv* env, jclass, jlong j_state, jlong j_table, jlong mem_size) +{ JNI_NULL_CHECK(env, j_table, "null table", ); JNI_NULL_CHECK(env, j_state, "null state", ); using namespace cudf::io; - cudf::table_view *tview_with_empty_nullmask = reinterpret_cast(j_table); + cudf::table_view* tview_with_empty_nullmask = reinterpret_cast(j_table); cudf::table_view tview = cudf::jni::remove_validity_if_needed(tview_with_empty_nullmask); - cudf::jni::native_parquet_writer_handle *state = - reinterpret_cast(j_state); + cudf::jni::native_parquet_writer_handle* state = + reinterpret_cast(j_state); if (state->sink) { long alloc_size = std::max(cudf::jni::MINIMUM_WRITE_BUFFER_SIZE, mem_size / 2); @@ -1992,13 +2263,13 @@ JNIEXPORT void JNICALL Java_ai_rapids_cudf_Table_writeParquetChunk(JNIEnv *env, CATCH_STD(env, ) } -JNIEXPORT void JNICALL Java_ai_rapids_cudf_Table_writeParquetEnd(JNIEnv *env, jclass, - jlong j_state) { +JNIEXPORT void JNICALL Java_ai_rapids_cudf_Table_writeParquetEnd(JNIEnv* env, jclass, jlong j_state) +{ JNI_NULL_CHECK(env, j_state, "null state", ); using namespace cudf::io; - cudf::jni::native_parquet_writer_handle *state = - reinterpret_cast(j_state); + cudf::jni::native_parquet_writer_handle* state = + reinterpret_cast(j_state); std::unique_ptr make_sure_we_delete(state); try { cudf::jni::auto_set_device(env); @@ -2007,10 +2278,15 @@ JNIEXPORT void JNICALL Java_ai_rapids_cudf_Table_writeParquetEnd(JNIEnv *env, jc CATCH_STD(env, ) } -JNIEXPORT jlongArray JNICALL Java_ai_rapids_cudf_Table_readORCFromDataSource( - JNIEnv *env, jclass, jobjectArray filter_col_names, jboolean usingNumPyTypes, jint unit, - jobjectArray dec128_col_names, jlong ds_handle) { - +JNIEXPORT jlongArray JNICALL +Java_ai_rapids_cudf_Table_readORCFromDataSource(JNIEnv* env, + jclass, + jobjectArray filter_col_names, + jboolean usingNumPyTypes, + jint unit, + jobjectArray dec128_col_names, + jlong ds_handle) +{ JNI_NULL_CHECK(env, ds_handle, "no data source handle given", 0); try { @@ -2020,7 +2296,7 @@ JNIEXPORT jlongArray JNICALL Java_ai_rapids_cudf_Table_readORCFromDataSource( cudf::jni::native_jstringArray n_dec128_col_names(env, dec128_col_names); - auto ds = reinterpret_cast(ds_handle); + auto ds = reinterpret_cast(ds_handle); cudf::io::source_info source{ds}; auto builder = cudf::io::orc_reader_options::builder(source); @@ -2029,26 +2305,33 @@ JNIEXPORT jlongArray JNICALL Java_ai_rapids_cudf_Table_readORCFromDataSource( } cudf::io::orc_reader_options opts = - builder.use_index(false) - .use_np_dtypes(static_cast(usingNumPyTypes)) - .timestamp_type(cudf::data_type(static_cast(unit))) - .decimal128_columns(n_dec128_col_names.as_cpp_vector()) - .build(); + builder.use_index(false) + .use_np_dtypes(static_cast(usingNumPyTypes)) + .timestamp_type(cudf::data_type(static_cast(unit))) + .decimal128_columns(n_dec128_col_names.as_cpp_vector()) + .build(); return convert_table_for_return(env, cudf::io::read_orc(opts).tbl); } CATCH_STD(env, NULL); } -JNIEXPORT jlongArray JNICALL Java_ai_rapids_cudf_Table_readORC( - JNIEnv *env, jclass, jobjectArray filter_col_names, jstring inputfilepath, jlong buffer, - jlong buffer_length, jboolean usingNumPyTypes, jint unit, jobjectArray dec128_col_names) { +JNIEXPORT jlongArray JNICALL Java_ai_rapids_cudf_Table_readORC(JNIEnv* env, + jclass, + jobjectArray filter_col_names, + jstring inputfilepath, + jlong buffer, + jlong buffer_length, + jboolean usingNumPyTypes, + jint unit, + jobjectArray dec128_col_names) +{ bool read_buffer = true; if (buffer == 0) { JNI_NULL_CHECK(env, inputfilepath, "input file or buffer must be supplied", NULL); read_buffer = false; } else if (inputfilepath != NULL) { - JNI_THROW_NEW(env, cudf::jni::ILLEGAL_ARG_CLASS, - "cannot pass in both a buffer and an inputfilepath", NULL); + JNI_THROW_NEW( + env, cudf::jni::ILLEGAL_ARG_CLASS, "cannot pass in both a buffer and an inputfilepath", NULL); } else if (buffer_length <= 0) { JNI_THROW_NEW(env, cudf::jni::ILLEGAL_ARG_CLASS, "An empty buffer is not supported", NULL); } @@ -2064,9 +2347,9 @@ JNIEXPORT jlongArray JNICALL Java_ai_rapids_cudf_Table_readORC( cudf::jni::native_jstringArray n_dec128_col_names(env, dec128_col_names); - auto source = read_buffer ? - cudf::io::source_info(reinterpret_cast(buffer), buffer_length) : - cudf::io::source_info(filename.get()); + auto source = read_buffer + ? cudf::io::source_info(reinterpret_cast(buffer), buffer_length) + : cudf::io::source_info(filename.get()); auto builder = cudf::io::orc_reader_options::builder(source); if (n_filter_col_names.size() > 0) { @@ -2074,21 +2357,31 @@ JNIEXPORT jlongArray JNICALL Java_ai_rapids_cudf_Table_readORC( } cudf::io::orc_reader_options opts = - builder.use_index(false) - .use_np_dtypes(static_cast(usingNumPyTypes)) - .timestamp_type(cudf::data_type(static_cast(unit))) - .decimal128_columns(n_dec128_col_names.as_cpp_vector()) - .build(); + builder.use_index(false) + .use_np_dtypes(static_cast(usingNumPyTypes)) + .timestamp_type(cudf::data_type(static_cast(unit))) + .decimal128_columns(n_dec128_col_names.as_cpp_vector()) + .build(); return convert_table_for_return(env, cudf::io::read_orc(opts).tbl); } CATCH_STD(env, NULL); } -JNIEXPORT long JNICALL Java_ai_rapids_cudf_Table_writeORCBufferBegin( - JNIEnv *env, jclass, jobjectArray j_col_names, jint j_num_children, jintArray j_children, - jbooleanArray j_col_nullability, jobjectArray j_metadata_keys, jobjectArray j_metadata_values, - jint j_compression, jintArray j_precisions, jbooleanArray j_is_map, jobject consumer, - jobject host_memory_allocator) { +JNIEXPORT long JNICALL +Java_ai_rapids_cudf_Table_writeORCBufferBegin(JNIEnv* env, + jclass, + jobjectArray j_col_names, + jint j_num_children, + jintArray j_children, + jbooleanArray j_col_nullability, + jobjectArray j_metadata_keys, + jobjectArray j_metadata_values, + jint j_compression, + jintArray j_precisions, + jbooleanArray j_is_map, + jobject consumer, + jobject host_memory_allocator) +{ JNI_NULL_CHECK(env, j_col_names, "null columns", 0); JNI_NULL_CHECK(env, j_col_nullability, "null nullability", 0); JNI_NULL_CHECK(env, j_metadata_keys, "null metadata keys", 0); @@ -2103,46 +2396,66 @@ JNIEXPORT long JNICALL Java_ai_rapids_cudf_Table_writeORCBufferBegin( jbooleanArray j_is_int96 = NULL; // ORC has no `j_parquetFieldIds`, but `createTableMetaData` needs a lvalue. jbooleanArray j_hasParquetFieldIds = NULL; - jintArray j_parquetFieldIds = NULL; + jintArray j_parquetFieldIds = NULL; // temp stub jbooleanArray j_is_binary = NULL; - createTableMetaData(env, j_num_children, j_col_names, j_children, j_col_nullability, j_is_int96, - j_precisions, j_is_map, metadata, j_hasParquetFieldIds, j_parquetFieldIds, + createTableMetaData(env, + j_num_children, + j_col_names, + j_children, + j_col_nullability, + j_is_int96, + j_precisions, + j_is_map, + metadata, + j_hasParquetFieldIds, + j_parquetFieldIds, j_is_binary); - auto meta_keys = cudf::jni::native_jstringArray{env, j_metadata_keys}.as_cpp_vector(); + auto meta_keys = cudf::jni::native_jstringArray{env, j_metadata_keys}.as_cpp_vector(); auto meta_values = cudf::jni::native_jstringArray{env, j_metadata_values}.as_cpp_vector(); std::map kv_metadata; - std::transform(meta_keys.begin(), meta_keys.end(), meta_values.begin(), + std::transform(meta_keys.begin(), + meta_keys.end(), + meta_values.begin(), std::inserter(kv_metadata, kv_metadata.end()), - [](const std::string &k, const std::string &v) { return std::make_pair(k, v); }); + [](const std::string& k, const std::string& v) { return std::make_pair(k, v); }); std::unique_ptr data_sink( - new cudf::jni::jni_writer_data_sink(env, consumer, host_memory_allocator)); + new cudf::jni::jni_writer_data_sink(env, consumer, host_memory_allocator)); sink_info sink{data_sink.get()}; - auto stats = std::make_shared(); + auto stats = std::make_shared(); chunked_orc_writer_options opts = chunked_orc_writer_options::builder(sink) - .metadata(std::move(metadata)) - .compression(static_cast(j_compression)) - .enable_statistics(ORC_STATISTICS_ROW_GROUP) - .key_value_metadata(kv_metadata) - .compression_statistics(stats) - .build(); - auto writer_ptr = std::make_unique(opts); - cudf::jni::native_orc_writer_handle *ret = new cudf::jni::native_orc_writer_handle( - std::move(writer_ptr), std::move(data_sink), std::move(stats)); + .metadata(std::move(metadata)) + .compression(static_cast(j_compression)) + .enable_statistics(ORC_STATISTICS_ROW_GROUP) + .key_value_metadata(kv_metadata) + .compression_statistics(stats) + .build(); + auto writer_ptr = std::make_unique(opts); + cudf::jni::native_orc_writer_handle* ret = new cudf::jni::native_orc_writer_handle( + std::move(writer_ptr), std::move(data_sink), std::move(stats)); return ptr_as_jlong(ret); } CATCH_STD(env, 0) } -JNIEXPORT long JNICALL Java_ai_rapids_cudf_Table_writeORCFileBegin( - JNIEnv *env, jclass, jobjectArray j_col_names, jint j_num_children, jintArray j_children, - jbooleanArray j_col_nullability, jobjectArray j_metadata_keys, jobjectArray j_metadata_values, - jint j_compression, jintArray j_precisions, jbooleanArray j_is_map, jstring j_output_path) { +JNIEXPORT long JNICALL Java_ai_rapids_cudf_Table_writeORCFileBegin(JNIEnv* env, + jclass, + jobjectArray j_col_names, + jint j_num_children, + jintArray j_children, + jbooleanArray j_col_nullability, + jobjectArray j_metadata_keys, + jobjectArray j_metadata_values, + jint j_compression, + jintArray j_precisions, + jbooleanArray j_is_map, + jstring j_output_path) +{ JNI_NULL_CHECK(env, j_col_names, "null columns", 0); JNI_NULL_CHECK(env, j_col_nullability, "null nullability", 0); JNI_NULL_CHECK(env, j_metadata_keys, "null metadata keys", 0); @@ -2158,48 +2471,60 @@ JNIEXPORT long JNICALL Java_ai_rapids_cudf_Table_writeORCFileBegin( jbooleanArray j_is_int96 = NULL; // ORC has no `j_parquetFieldIds`, but `createTableMetaData` needs a lvalue. jbooleanArray j_hasParquetFieldIds = NULL; - jintArray j_parquetFieldIds = NULL; + jintArray j_parquetFieldIds = NULL; // temp stub jbooleanArray j_is_binary = NULL; - createTableMetaData(env, j_num_children, j_col_names, j_children, j_col_nullability, j_is_int96, - j_precisions, j_is_map, metadata, j_hasParquetFieldIds, j_parquetFieldIds, + createTableMetaData(env, + j_num_children, + j_col_names, + j_children, + j_col_nullability, + j_is_int96, + j_precisions, + j_is_map, + metadata, + j_hasParquetFieldIds, + j_parquetFieldIds, j_is_binary); - auto meta_keys = cudf::jni::native_jstringArray{env, j_metadata_keys}.as_cpp_vector(); + auto meta_keys = cudf::jni::native_jstringArray{env, j_metadata_keys}.as_cpp_vector(); auto meta_values = cudf::jni::native_jstringArray{env, j_metadata_values}.as_cpp_vector(); std::map kv_metadata; - std::transform(meta_keys.begin(), meta_keys.end(), meta_values.begin(), + std::transform(meta_keys.begin(), + meta_keys.end(), + meta_values.begin(), std::inserter(kv_metadata, kv_metadata.end()), - [](const std::string &k, const std::string &v) { return std::make_pair(k, v); }); + [](const std::string& k, const std::string& v) { return std::make_pair(k, v); }); sink_info sink{output_path.get()}; - auto stats = std::make_shared(); + auto stats = std::make_shared(); chunked_orc_writer_options opts = chunked_orc_writer_options::builder(sink) - .metadata(std::move(metadata)) - .compression(static_cast(j_compression)) - .enable_statistics(ORC_STATISTICS_ROW_GROUP) - .key_value_metadata(kv_metadata) - .compression_statistics(stats) - .build(); + .metadata(std::move(metadata)) + .compression(static_cast(j_compression)) + .enable_statistics(ORC_STATISTICS_ROW_GROUP) + .key_value_metadata(kv_metadata) + .compression_statistics(stats) + .build(); auto writer_ptr = std::make_unique(opts); - cudf::jni::native_orc_writer_handle *ret = - new cudf::jni::native_orc_writer_handle(std::move(writer_ptr), nullptr, std::move(stats)); + cudf::jni::native_orc_writer_handle* ret = + new cudf::jni::native_orc_writer_handle(std::move(writer_ptr), nullptr, std::move(stats)); return ptr_as_jlong(ret); } CATCH_STD(env, 0) } -JNIEXPORT void JNICALL Java_ai_rapids_cudf_Table_writeORCChunk(JNIEnv *env, jclass, jlong j_state, - jlong j_table, jlong mem_size) { +JNIEXPORT void JNICALL Java_ai_rapids_cudf_Table_writeORCChunk( + JNIEnv* env, jclass, jlong j_state, jlong j_table, jlong mem_size) +{ JNI_NULL_CHECK(env, j_table, "null table", ); JNI_NULL_CHECK(env, j_state, "null state", ); using namespace cudf::io; - cudf::table_view *tview_orig = reinterpret_cast(j_table); - cudf::table_view tview = cudf::jni::remove_validity_if_needed(tview_orig); - cudf::jni::native_orc_writer_handle *state = - reinterpret_cast(j_state); + cudf::table_view* tview_orig = reinterpret_cast(j_table); + cudf::table_view tview = cudf::jni::remove_validity_if_needed(tview_orig); + cudf::jni::native_orc_writer_handle* state = + reinterpret_cast(j_state); if (state->sink) { long alloc_size = std::max(cudf::jni::MINIMUM_WRITE_BUFFER_SIZE, mem_size / 2); @@ -2212,12 +2537,13 @@ JNIEXPORT void JNICALL Java_ai_rapids_cudf_Table_writeORCChunk(JNIEnv *env, jcla CATCH_STD(env, ) } -JNIEXPORT void JNICALL Java_ai_rapids_cudf_Table_writeORCEnd(JNIEnv *env, jclass, jlong j_state) { +JNIEXPORT void JNICALL Java_ai_rapids_cudf_Table_writeORCEnd(JNIEnv* env, jclass, jlong j_state) +{ JNI_NULL_CHECK(env, j_state, "null state", ); using namespace cudf::io; - cudf::jni::native_orc_writer_handle *state = - reinterpret_cast(j_state); + cudf::jni::native_orc_writer_handle* state = + reinterpret_cast(j_state); std::unique_ptr make_sure_we_delete(state); try { cudf::jni::auto_set_device(env); @@ -2226,25 +2552,24 @@ JNIEXPORT void JNICALL Java_ai_rapids_cudf_Table_writeORCEnd(JNIEnv *env, jclass CATCH_STD(env, ) } -JNIEXPORT jdoubleArray JNICALL Java_ai_rapids_cudf_TableWriter_getWriteStatistics(JNIEnv *env, +JNIEXPORT jdoubleArray JNICALL Java_ai_rapids_cudf_TableWriter_getWriteStatistics(JNIEnv* env, jclass, - jlong j_state) { + jlong j_state) +{ JNI_NULL_CHECK(env, j_state, "null state", nullptr); using namespace cudf::io; - auto const state = reinterpret_cast(j_state); + auto const state = reinterpret_cast(j_state); try { cudf::jni::auto_set_device(env); - if (!state->stats) { - return nullptr; - } + if (!state->stats) { return nullptr; } - auto const &stats = *state->stats; - auto output = cudf::jni::native_jdoubleArray(env, 4); - output[0] = static_cast(stats.num_compressed_bytes()); - output[1] = static_cast(stats.num_failed_bytes()); - output[2] = static_cast(stats.num_skipped_bytes()); - output[3] = static_cast(stats.compression_ratio()); + auto const& stats = *state->stats; + auto output = cudf::jni::native_jdoubleArray(env, 4); + output[0] = static_cast(stats.num_compressed_bytes()); + output[1] = static_cast(stats.num_failed_bytes()); + output[2] = static_cast(stats.num_skipped_bytes()); + output[3] = static_cast(stats.compression_ratio()); return output.get_jArray(); } @@ -2252,8 +2577,8 @@ JNIEXPORT jdoubleArray JNICALL Java_ai_rapids_cudf_TableWriter_getWriteStatistic } JNIEXPORT long JNICALL Java_ai_rapids_cudf_Table_writeArrowIPCBufferBegin( - JNIEnv *env, jclass, jobjectArray j_col_names, jobject consumer, - jobject host_memory_allocator) { + JNIEnv* env, jclass, jobjectArray j_col_names, jobject consumer, jobject host_memory_allocator) +{ JNI_NULL_CHECK(env, j_col_names, "null columns", 0); JNI_NULL_CHECK(env, consumer, "null consumer", 0); try { @@ -2261,18 +2586,20 @@ JNIEXPORT long JNICALL Java_ai_rapids_cudf_Table_writeArrowIPCBufferBegin( cudf::jni::native_jstringArray col_names(env, j_col_names); std::shared_ptr data_sink( - new cudf::jni::jni_arrow_output_stream(env, consumer, host_memory_allocator)); + new cudf::jni::jni_arrow_output_stream(env, consumer, host_memory_allocator)); - cudf::jni::native_arrow_ipc_writer_handle *ret = - new cudf::jni::native_arrow_ipc_writer_handle(col_names.as_cpp_vector(), data_sink); + cudf::jni::native_arrow_ipc_writer_handle* ret = + new cudf::jni::native_arrow_ipc_writer_handle(col_names.as_cpp_vector(), data_sink); return ptr_as_jlong(ret); } CATCH_STD(env, 0) } -JNIEXPORT long JNICALL Java_ai_rapids_cudf_Table_writeArrowIPCFileBegin(JNIEnv *env, jclass, +JNIEXPORT long JNICALL Java_ai_rapids_cudf_Table_writeArrowIPCFileBegin(JNIEnv* env, + jclass, jobjectArray j_col_names, - jstring j_output_path) { + jstring j_output_path) +{ JNI_NULL_CHECK(env, j_col_names, "null columns", 0); JNI_NULL_CHECK(env, j_output_path, "null output path", 0); try { @@ -2280,22 +2607,24 @@ JNIEXPORT long JNICALL Java_ai_rapids_cudf_Table_writeArrowIPCFileBegin(JNIEnv * cudf::jni::native_jstringArray col_names(env, j_col_names); cudf::jni::native_jstring output_path(env, j_output_path); - cudf::jni::native_arrow_ipc_writer_handle *ret = - new cudf::jni::native_arrow_ipc_writer_handle(col_names.as_cpp_vector(), output_path.get()); + cudf::jni::native_arrow_ipc_writer_handle* ret = + new cudf::jni::native_arrow_ipc_writer_handle(col_names.as_cpp_vector(), output_path.get()); return ptr_as_jlong(ret); } CATCH_STD(env, 0) } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Table_convertCudfToArrowTable(JNIEnv *env, jclass, +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Table_convertCudfToArrowTable(JNIEnv* env, + jclass, jlong j_state, - jlong j_table) { + jlong j_table) +{ JNI_NULL_CHECK(env, j_table, "null table", 0); JNI_NULL_CHECK(env, j_state, "null state", 0); - cudf::table_view *tview = reinterpret_cast(j_table); - cudf::jni::native_arrow_ipc_writer_handle *state = - reinterpret_cast(j_state); + cudf::table_view* tview = reinterpret_cast(j_table); + cudf::jni::native_arrow_ipc_writer_handle* state = + reinterpret_cast(j_state); try { cudf::jni::auto_set_device(env); @@ -2311,17 +2640,16 @@ JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Table_convertCudfToArrowTable(JNIEnv CATCH_STD(env, 0) } -JNIEXPORT void JNICALL Java_ai_rapids_cudf_Table_writeArrowIPCArrowChunk(JNIEnv *env, jclass, - jlong j_state, - jlong arrow_table_handle, - jlong max_chunk) { +JNIEXPORT void JNICALL Java_ai_rapids_cudf_Table_writeArrowIPCArrowChunk( + JNIEnv* env, jclass, jlong j_state, jlong arrow_table_handle, jlong max_chunk) +{ JNI_NULL_CHECK(env, arrow_table_handle, "null arrow table", ); JNI_NULL_CHECK(env, j_state, "null state", ); - std::shared_ptr *handle = - reinterpret_cast *>(arrow_table_handle); - cudf::jni::native_arrow_ipc_writer_handle *state = - reinterpret_cast(j_state); + std::shared_ptr* handle = + reinterpret_cast*>(arrow_table_handle); + cudf::jni::native_arrow_ipc_writer_handle* state = + reinterpret_cast(j_state); try { cudf::jni::auto_set_device(env); @@ -2330,12 +2658,14 @@ JNIEXPORT void JNICALL Java_ai_rapids_cudf_Table_writeArrowIPCArrowChunk(JNIEnv CATCH_STD(env, ) } -JNIEXPORT void JNICALL Java_ai_rapids_cudf_Table_writeArrowIPCEnd(JNIEnv *env, jclass, - jlong j_state) { +JNIEXPORT void JNICALL Java_ai_rapids_cudf_Table_writeArrowIPCEnd(JNIEnv* env, + jclass, + jlong j_state) +{ JNI_NULL_CHECK(env, j_state, "null state", ); - cudf::jni::native_arrow_ipc_writer_handle *state = - reinterpret_cast(j_state); + cudf::jni::native_arrow_ipc_writer_handle* state = + reinterpret_cast(j_state); std::unique_ptr make_sure_we_delete(state); try { cudf::jni::auto_set_device(env); @@ -2344,8 +2674,10 @@ JNIEXPORT void JNICALL Java_ai_rapids_cudf_Table_writeArrowIPCEnd(JNIEnv *env, j CATCH_STD(env, ) } -JNIEXPORT long JNICALL Java_ai_rapids_cudf_Table_readArrowIPCFileBegin(JNIEnv *env, jclass, - jstring j_input_path) { +JNIEXPORT long JNICALL Java_ai_rapids_cudf_Table_readArrowIPCFileBegin(JNIEnv* env, + jclass, + jstring j_input_path) +{ JNI_NULL_CHECK(env, j_input_path, "null input path", 0); try { cudf::jni::auto_set_device(env); @@ -2355,25 +2687,29 @@ JNIEXPORT long JNICALL Java_ai_rapids_cudf_Table_readArrowIPCFileBegin(JNIEnv *e CATCH_STD(env, 0) } -JNIEXPORT long JNICALL Java_ai_rapids_cudf_Table_readArrowIPCBufferBegin(JNIEnv *env, jclass, - jobject provider) { +JNIEXPORT long JNICALL Java_ai_rapids_cudf_Table_readArrowIPCBufferBegin(JNIEnv* env, + jclass, + jobject provider) +{ JNI_NULL_CHECK(env, provider, "null provider", 0); try { cudf::jni::auto_set_device(env); std::shared_ptr data_source( - new cudf::jni::jni_arrow_input_stream(env, provider)); + new cudf::jni::jni_arrow_input_stream(env, provider)); return ptr_as_jlong(new cudf::jni::native_arrow_ipc_reader_handle(data_source)); } CATCH_STD(env, 0) } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Table_readArrowIPCChunkToArrowTable(JNIEnv *env, jclass, +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Table_readArrowIPCChunkToArrowTable(JNIEnv* env, + jclass, jlong j_state, - jint row_target) { + jint row_target) +{ JNI_NULL_CHECK(env, j_state, "null state", 0); - cudf::jni::native_arrow_ipc_reader_handle *state = - reinterpret_cast(j_state); + cudf::jni::native_arrow_ipc_reader_handle* state = + reinterpret_cast(j_state); try { cudf::jni::auto_set_device(env); @@ -2385,10 +2721,12 @@ JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Table_readArrowIPCChunkToArrowTable( CATCH_STD(env, 0) } -JNIEXPORT void JNICALL Java_ai_rapids_cudf_Table_closeArrowTable(JNIEnv *env, jclass, - jlong arrow_table_handle) { - std::shared_ptr *handle = - reinterpret_cast *>(arrow_table_handle); +JNIEXPORT void JNICALL Java_ai_rapids_cudf_Table_closeArrowTable(JNIEnv* env, + jclass, + jlong arrow_table_handle) +{ + std::shared_ptr* handle = + reinterpret_cast*>(arrow_table_handle); try { cudf::jni::auto_set_device(env); @@ -2398,11 +2736,12 @@ JNIEXPORT void JNICALL Java_ai_rapids_cudf_Table_closeArrowTable(JNIEnv *env, jc } JNIEXPORT jlongArray JNICALL -Java_ai_rapids_cudf_Table_convertArrowTableToCudf(JNIEnv *env, jclass, jlong arrow_table_handle) { +Java_ai_rapids_cudf_Table_convertArrowTableToCudf(JNIEnv* env, jclass, jlong arrow_table_handle) +{ JNI_NULL_CHECK(env, arrow_table_handle, "null arrow handle", 0); - std::shared_ptr *handle = - reinterpret_cast *>(arrow_table_handle); + std::shared_ptr* handle = + reinterpret_cast*>(arrow_table_handle); try { cudf::jni::auto_set_device(env); @@ -2411,12 +2750,12 @@ Java_ai_rapids_cudf_Table_convertArrowTableToCudf(JNIEnv *env, jclass, jlong arr CATCH_STD(env, 0) } -JNIEXPORT void JNICALL Java_ai_rapids_cudf_Table_readArrowIPCEnd(JNIEnv *env, jclass, - jlong j_state) { +JNIEXPORT void JNICALL Java_ai_rapids_cudf_Table_readArrowIPCEnd(JNIEnv* env, jclass, jlong j_state) +{ JNI_NULL_CHECK(env, j_state, "null state", ); - cudf::jni::native_arrow_ipc_reader_handle *state = - reinterpret_cast(j_state); + cudf::jni::native_arrow_ipc_reader_handle* state = + reinterpret_cast(j_state); std::unique_ptr make_sure_we_delete(state); try { cudf::jni::auto_set_device(env); @@ -2426,523 +2765,772 @@ JNIEXPORT void JNICALL Java_ai_rapids_cudf_Table_readArrowIPCEnd(JNIEnv *env, jc } JNIEXPORT jlongArray JNICALL Java_ai_rapids_cudf_Table_leftJoinGatherMaps( - JNIEnv *env, jclass, jlong j_left_keys, jlong j_right_keys, jboolean compare_nulls_equal) { + JNIEnv* env, jclass, jlong j_left_keys, jlong j_right_keys, jboolean compare_nulls_equal) +{ return cudf::jni::join_gather_maps( - env, j_left_keys, j_right_keys, compare_nulls_equal, - [](cudf::table_view const &left, cudf::table_view const &right, cudf::null_equality nulleq) { - return cudf::left_join(left, right, nulleq); - }); + env, + j_left_keys, + j_right_keys, + compare_nulls_equal, + [](cudf::table_view const& left, cudf::table_view const& right, cudf::null_equality nulleq) { + return cudf::left_join(left, right, nulleq); + }); } JNIEXPORT jlongArray JNICALL Java_ai_rapids_cudf_Table_leftDistinctJoinGatherMap( - JNIEnv *env, jclass, jlong j_left_keys, jlong j_right_keys, jboolean compare_nulls_equal) { + JNIEnv* env, jclass, jlong j_left_keys, jlong j_right_keys, jboolean compare_nulls_equal) +{ return cudf::jni::join_gather_single_map( - env, j_left_keys, j_right_keys, compare_nulls_equal, - [](cudf::table_view const &left, cudf::table_view const &right, cudf::null_equality nulleq) { - auto has_nulls = cudf::has_nested_nulls(left) || cudf::has_nested_nulls(right) ? - cudf::nullable_join::YES : - cudf::nullable_join::NO; - if (cudf::detail::has_nested_columns(right)) { - cudf::distinct_hash_join hash(right, left, has_nulls, nulleq); - return hash.left_join(); - } else { - cudf::distinct_hash_join hash(right, left, has_nulls, nulleq); - return hash.left_join(); - } - }); + env, + j_left_keys, + j_right_keys, + compare_nulls_equal, + [](cudf::table_view const& left, cudf::table_view const& right, cudf::null_equality nulleq) { + auto has_nulls = cudf::has_nested_nulls(left) || cudf::has_nested_nulls(right) + ? cudf::nullable_join::YES + : cudf::nullable_join::NO; + if (cudf::detail::has_nested_columns(right)) { + cudf::distinct_hash_join hash(right, left, has_nulls, nulleq); + return hash.left_join(); + } else { + cudf::distinct_hash_join hash(right, left, has_nulls, nulleq); + return hash.left_join(); + } + }); } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Table_leftJoinRowCount(JNIEnv *env, jclass, +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Table_leftJoinRowCount(JNIEnv* env, + jclass, jlong j_left_table, - jlong j_right_hash_join) { + jlong j_right_hash_join) +{ JNI_NULL_CHECK(env, j_left_table, "left table is null", 0); JNI_NULL_CHECK(env, j_right_hash_join, "right hash join is null", 0); try { cudf::jni::auto_set_device(env); - auto left_table = reinterpret_cast(j_left_table); - auto hash_join = reinterpret_cast(j_right_hash_join); - auto row_count = hash_join->left_join_size(*left_table); + auto left_table = reinterpret_cast(j_left_table); + auto hash_join = reinterpret_cast(j_right_hash_join); + auto row_count = hash_join->left_join_size(*left_table); return static_cast(row_count); } CATCH_STD(env, 0); } JNIEXPORT jlongArray JNICALL Java_ai_rapids_cudf_Table_leftHashJoinGatherMaps( - JNIEnv *env, jclass, jlong j_left_table, jlong j_right_hash_join) { + JNIEnv* env, jclass, jlong j_left_table, jlong j_right_hash_join) +{ return cudf::jni::hash_join_gather_maps( - env, j_left_table, j_right_hash_join, - [](cudf::table_view const &left, cudf::hash_join const &hash) { - return hash.left_join(left); - }); + env, + j_left_table, + j_right_hash_join, + [](cudf::table_view const& left, cudf::hash_join const& hash) { return hash.left_join(left); }); } JNIEXPORT jlongArray JNICALL Java_ai_rapids_cudf_Table_leftHashJoinGatherMapsWithCount( - JNIEnv *env, jclass, jlong j_left_table, jlong j_right_hash_join, jlong j_output_row_count) { + JNIEnv* env, jclass, jlong j_left_table, jlong j_right_hash_join, jlong j_output_row_count) +{ auto output_row_count = static_cast(j_output_row_count); return cudf::jni::hash_join_gather_maps( - env, j_left_table, j_right_hash_join, - [output_row_count](cudf::table_view const &left, cudf::hash_join const &hash) { - return hash.left_join(left, output_row_count); - }); + env, + j_left_table, + j_right_hash_join, + [output_row_count](cudf::table_view const& left, cudf::hash_join const& hash) { + return hash.left_join(left, output_row_count); + }); } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Table_conditionalLeftJoinRowCount(JNIEnv *env, jclass, - jlong j_left_table, - jlong j_right_table, - jlong j_condition) { +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Table_conditionalLeftJoinRowCount( + JNIEnv* env, jclass, jlong j_left_table, jlong j_right_table, jlong j_condition) +{ JNI_NULL_CHECK(env, j_left_table, "left_table is null", 0); JNI_NULL_CHECK(env, j_right_table, "right_table is null", 0); JNI_NULL_CHECK(env, j_condition, "condition is null", 0); try { cudf::jni::auto_set_device(env); - auto left_table = reinterpret_cast(j_left_table); - auto right_table = reinterpret_cast(j_right_table); - auto condition = reinterpret_cast(j_condition); - auto row_count = cudf::conditional_left_join_size(*left_table, *right_table, - condition->get_top_expression()); + auto left_table = reinterpret_cast(j_left_table); + auto right_table = reinterpret_cast(j_right_table); + auto condition = reinterpret_cast(j_condition); + auto row_count = + cudf::conditional_left_join_size(*left_table, *right_table, condition->get_top_expression()); return static_cast(row_count); } CATCH_STD(env, 0); } JNIEXPORT jlongArray JNICALL Java_ai_rapids_cudf_Table_conditionalLeftJoinGatherMaps( - JNIEnv *env, jclass, jlong j_left_table, jlong j_right_table, jlong j_condition) { - return cudf::jni::cond_join_gather_maps( - env, j_left_table, j_right_table, j_condition, - [](cudf::table_view const &left, cudf::table_view const &right, - cudf::ast::expression const &cond_expr) { - return cudf::conditional_left_join(left, right, cond_expr); - }); + JNIEnv* env, jclass, jlong j_left_table, jlong j_right_table, jlong j_condition) +{ + return cudf::jni::cond_join_gather_maps(env, + j_left_table, + j_right_table, + j_condition, + [](cudf::table_view const& left, + cudf::table_view const& right, + cudf::ast::expression const& cond_expr) { + return cudf::conditional_left_join( + left, right, cond_expr); + }); } -JNIEXPORT jlongArray JNICALL Java_ai_rapids_cudf_Table_conditionalLeftJoinGatherMapsWithCount( - JNIEnv *env, jclass, jlong j_left_table, jlong j_right_table, jlong j_condition, - jlong j_row_count) { +JNIEXPORT jlongArray JNICALL +Java_ai_rapids_cudf_Table_conditionalLeftJoinGatherMapsWithCount(JNIEnv* env, + jclass, + jlong j_left_table, + jlong j_right_table, + jlong j_condition, + jlong j_row_count) +{ auto row_count = static_cast(j_row_count); - return cudf::jni::cond_join_gather_maps( - env, j_left_table, j_right_table, j_condition, - [row_count](cudf::table_view const &left, cudf::table_view const &right, - cudf::ast::expression const &cond_expr) { - return cudf::conditional_left_join(left, right, cond_expr, row_count); - }); -} - -JNIEXPORT jlongArray JNICALL Java_ai_rapids_cudf_Table_mixedLeftJoinSize( - JNIEnv *env, jclass, jlong j_left_keys, jlong j_right_keys, jlong j_left_condition, - jlong j_right_condition, jlong j_condition, jboolean j_nulls_equal) { + return cudf::jni::cond_join_gather_maps(env, + j_left_table, + j_right_table, + j_condition, + [row_count](cudf::table_view const& left, + cudf::table_view const& right, + cudf::ast::expression const& cond_expr) { + return cudf::conditional_left_join( + left, right, cond_expr, row_count); + }); +} + +JNIEXPORT jlongArray JNICALL Java_ai_rapids_cudf_Table_mixedLeftJoinSize(JNIEnv* env, + jclass, + jlong j_left_keys, + jlong j_right_keys, + jlong j_left_condition, + jlong j_right_condition, + jlong j_condition, + jboolean j_nulls_equal) +{ return cudf::jni::mixed_join_size( - env, j_left_keys, j_right_keys, j_left_condition, j_right_condition, j_condition, - j_nulls_equal, - [](cudf::table_view const &left_keys, cudf::table_view const &right_keys, - cudf::table_view const &left_condition, cudf::table_view const &right_condition, - cudf::ast::expression const &condition, cudf::null_equality nulls_equal) { - return cudf::mixed_left_join_size(left_keys, right_keys, left_condition, right_condition, - condition, nulls_equal); - }); + env, + j_left_keys, + j_right_keys, + j_left_condition, + j_right_condition, + j_condition, + j_nulls_equal, + [](cudf::table_view const& left_keys, + cudf::table_view const& right_keys, + cudf::table_view const& left_condition, + cudf::table_view const& right_condition, + cudf::ast::expression const& condition, + cudf::null_equality nulls_equal) { + return cudf::mixed_left_join_size( + left_keys, right_keys, left_condition, right_condition, condition, nulls_equal); + }); } -JNIEXPORT jlongArray JNICALL Java_ai_rapids_cudf_Table_mixedLeftJoinGatherMaps( - JNIEnv *env, jclass, jlong j_left_keys, jlong j_right_keys, jlong j_left_condition, - jlong j_right_condition, jlong j_condition, jboolean j_nulls_equal) { +JNIEXPORT jlongArray JNICALL +Java_ai_rapids_cudf_Table_mixedLeftJoinGatherMaps(JNIEnv* env, + jclass, + jlong j_left_keys, + jlong j_right_keys, + jlong j_left_condition, + jlong j_right_condition, + jlong j_condition, + jboolean j_nulls_equal) +{ return cudf::jni::mixed_join_gather_maps( - env, j_left_keys, j_right_keys, j_left_condition, j_right_condition, j_condition, - j_nulls_equal, - [](cudf::table_view const &left_keys, cudf::table_view const &right_keys, - cudf::table_view const &left_condition, cudf::table_view const &right_condition, - cudf::ast::expression const &condition, cudf::null_equality nulls_equal) { - return cudf::mixed_left_join(left_keys, right_keys, left_condition, right_condition, - condition, nulls_equal); - }); + env, + j_left_keys, + j_right_keys, + j_left_condition, + j_right_condition, + j_condition, + j_nulls_equal, + [](cudf::table_view const& left_keys, + cudf::table_view const& right_keys, + cudf::table_view const& left_condition, + cudf::table_view const& right_condition, + cudf::ast::expression const& condition, + cudf::null_equality nulls_equal) { + return cudf::mixed_left_join( + left_keys, right_keys, left_condition, right_condition, condition, nulls_equal); + }); } -JNIEXPORT jlongArray JNICALL Java_ai_rapids_cudf_Table_mixedLeftJoinGatherMapsWithSize( - JNIEnv *env, jclass, jlong j_left_keys, jlong j_right_keys, jlong j_left_condition, - jlong j_right_condition, jlong j_condition, jboolean j_nulls_equal, jlong j_output_row_count, - jlong j_matches_view) { +JNIEXPORT jlongArray JNICALL +Java_ai_rapids_cudf_Table_mixedLeftJoinGatherMapsWithSize(JNIEnv* env, + jclass, + jlong j_left_keys, + jlong j_right_keys, + jlong j_left_condition, + jlong j_right_condition, + jlong j_condition, + jboolean j_nulls_equal, + jlong j_output_row_count, + jlong j_matches_view) +{ auto size_info = cudf::jni::get_mixed_size_info(env, j_output_row_count, j_matches_view); return cudf::jni::mixed_join_gather_maps( - env, j_left_keys, j_right_keys, j_left_condition, j_right_condition, j_condition, - j_nulls_equal, - [&size_info](cudf::table_view const &left_keys, cudf::table_view const &right_keys, - cudf::table_view const &left_condition, cudf::table_view const &right_condition, - cudf::ast::expression const &condition, cudf::null_equality nulls_equal) { - return cudf::mixed_left_join(left_keys, right_keys, left_condition, right_condition, - condition, nulls_equal, size_info); - }); + env, + j_left_keys, + j_right_keys, + j_left_condition, + j_right_condition, + j_condition, + j_nulls_equal, + [&size_info](cudf::table_view const& left_keys, + cudf::table_view const& right_keys, + cudf::table_view const& left_condition, + cudf::table_view const& right_condition, + cudf::ast::expression const& condition, + cudf::null_equality nulls_equal) { + return cudf::mixed_left_join( + left_keys, right_keys, left_condition, right_condition, condition, nulls_equal, size_info); + }); } JNIEXPORT jlongArray JNICALL Java_ai_rapids_cudf_Table_innerJoinGatherMaps( - JNIEnv *env, jclass, jlong j_left_keys, jlong j_right_keys, jboolean compare_nulls_equal) { + JNIEnv* env, jclass, jlong j_left_keys, jlong j_right_keys, jboolean compare_nulls_equal) +{ return cudf::jni::join_gather_maps( - env, j_left_keys, j_right_keys, compare_nulls_equal, - [](cudf::table_view const &left, cudf::table_view const &right, cudf::null_equality nulleq) { - return cudf::inner_join(left, right, nulleq); - }); + env, + j_left_keys, + j_right_keys, + compare_nulls_equal, + [](cudf::table_view const& left, cudf::table_view const& right, cudf::null_equality nulleq) { + return cudf::inner_join(left, right, nulleq); + }); } JNIEXPORT jlongArray JNICALL Java_ai_rapids_cudf_Table_innerDistinctJoinGatherMaps( - JNIEnv *env, jclass, jlong j_left_keys, jlong j_right_keys, jboolean compare_nulls_equal) { + JNIEnv* env, jclass, jlong j_left_keys, jlong j_right_keys, jboolean compare_nulls_equal) +{ return cudf::jni::join_gather_maps( - env, j_left_keys, j_right_keys, compare_nulls_equal, - [](cudf::table_view const &left, cudf::table_view const &right, cudf::null_equality nulleq) { - auto has_nulls = cudf::has_nested_nulls(left) || cudf::has_nested_nulls(right) ? - cudf::nullable_join::YES : - cudf::nullable_join::NO; - std::pair>, - std::unique_ptr>> - maps; - if (cudf::detail::has_nested_columns(right)) { - cudf::distinct_hash_join hash(right, left, has_nulls, nulleq); - maps = hash.inner_join(); - } else { - cudf::distinct_hash_join hash(right, left, has_nulls, nulleq); - maps = hash.inner_join(); - } - // Unique join returns {right map, left map} but all the other joins - // return {left map, right map}. Swap here to make it consistent. - return std::make_pair(std::move(maps.second), std::move(maps.first)); - }); + env, + j_left_keys, + j_right_keys, + compare_nulls_equal, + [](cudf::table_view const& left, cudf::table_view const& right, cudf::null_equality nulleq) { + auto has_nulls = cudf::has_nested_nulls(left) || cudf::has_nested_nulls(right) + ? cudf::nullable_join::YES + : cudf::nullable_join::NO; + std::pair>, + std::unique_ptr>> + maps; + if (cudf::detail::has_nested_columns(right)) { + cudf::distinct_hash_join hash(right, left, has_nulls, nulleq); + maps = hash.inner_join(); + } else { + cudf::distinct_hash_join hash(right, left, has_nulls, nulleq); + maps = hash.inner_join(); + } + // Unique join returns {right map, left map} but all the other joins + // return {left map, right map}. Swap here to make it consistent. + return std::make_pair(std::move(maps.second), std::move(maps.first)); + }); } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Table_innerJoinRowCount(JNIEnv *env, jclass, +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Table_innerJoinRowCount(JNIEnv* env, + jclass, jlong j_left_table, - jlong j_right_hash_join) { + jlong j_right_hash_join) +{ JNI_NULL_CHECK(env, j_left_table, "left table is null", 0); JNI_NULL_CHECK(env, j_right_hash_join, "right hash join is null", 0); try { cudf::jni::auto_set_device(env); - auto left_table = reinterpret_cast(j_left_table); - auto hash_join = reinterpret_cast(j_right_hash_join); - auto row_count = hash_join->inner_join_size(*left_table); + auto left_table = reinterpret_cast(j_left_table); + auto hash_join = reinterpret_cast(j_right_hash_join); + auto row_count = hash_join->inner_join_size(*left_table); return static_cast(row_count); } CATCH_STD(env, 0); } JNIEXPORT jlongArray JNICALL Java_ai_rapids_cudf_Table_innerHashJoinGatherMaps( - JNIEnv *env, jclass, jlong j_left_table, jlong j_right_hash_join) { + JNIEnv* env, jclass, jlong j_left_table, jlong j_right_hash_join) +{ return cudf::jni::hash_join_gather_maps( - env, j_left_table, j_right_hash_join, - [](cudf::table_view const &left, cudf::hash_join const &hash) { - return hash.inner_join(left); - }); + env, + j_left_table, + j_right_hash_join, + [](cudf::table_view const& left, cudf::hash_join const& hash) { + return hash.inner_join(left); + }); } JNIEXPORT jlongArray JNICALL Java_ai_rapids_cudf_Table_innerHashJoinGatherMapsWithCount( - JNIEnv *env, jclass, jlong j_left_table, jlong j_right_hash_join, jlong j_output_row_count) { + JNIEnv* env, jclass, jlong j_left_table, jlong j_right_hash_join, jlong j_output_row_count) +{ auto output_row_count = static_cast(j_output_row_count); return cudf::jni::hash_join_gather_maps( - env, j_left_table, j_right_hash_join, - [output_row_count](cudf::table_view const &left, cudf::hash_join const &hash) { - return hash.inner_join(left, output_row_count); - }); + env, + j_left_table, + j_right_hash_join, + [output_row_count](cudf::table_view const& left, cudf::hash_join const& hash) { + return hash.inner_join(left, output_row_count); + }); } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Table_conditionalInnerJoinRowCount(JNIEnv *env, jclass, - jlong j_left_table, - jlong j_right_table, - jlong j_condition) { +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Table_conditionalInnerJoinRowCount( + JNIEnv* env, jclass, jlong j_left_table, jlong j_right_table, jlong j_condition) +{ JNI_NULL_CHECK(env, j_left_table, "left_table is null", 0); JNI_NULL_CHECK(env, j_right_table, "right_table is null", 0); JNI_NULL_CHECK(env, j_condition, "condition is null", 0); try { cudf::jni::auto_set_device(env); - auto left_table = reinterpret_cast(j_left_table); - auto right_table = reinterpret_cast(j_right_table); - auto condition = reinterpret_cast(j_condition); - auto row_count = cudf::conditional_inner_join_size(*left_table, *right_table, - condition->get_top_expression()); + auto left_table = reinterpret_cast(j_left_table); + auto right_table = reinterpret_cast(j_right_table); + auto condition = reinterpret_cast(j_condition); + auto row_count = + cudf::conditional_inner_join_size(*left_table, *right_table, condition->get_top_expression()); return static_cast(row_count); } CATCH_STD(env, 0); } JNIEXPORT jlongArray JNICALL Java_ai_rapids_cudf_Table_conditionalInnerJoinGatherMaps( - JNIEnv *env, jclass, jlong j_left_table, jlong j_right_table, jlong j_condition) { - return cudf::jni::cond_join_gather_maps( - env, j_left_table, j_right_table, j_condition, - [](cudf::table_view const &left, cudf::table_view const &right, - cudf::ast::expression const &cond_expr) { - return cudf::conditional_inner_join(left, right, cond_expr); - }); + JNIEnv* env, jclass, jlong j_left_table, jlong j_right_table, jlong j_condition) +{ + return cudf::jni::cond_join_gather_maps(env, + j_left_table, + j_right_table, + j_condition, + [](cudf::table_view const& left, + cudf::table_view const& right, + cudf::ast::expression const& cond_expr) { + return cudf::conditional_inner_join( + left, right, cond_expr); + }); } -JNIEXPORT jlongArray JNICALL Java_ai_rapids_cudf_Table_conditionalInnerJoinGatherMapsWithCount( - JNIEnv *env, jclass, jlong j_left_table, jlong j_right_table, jlong j_condition, - jlong j_row_count) { +JNIEXPORT jlongArray JNICALL +Java_ai_rapids_cudf_Table_conditionalInnerJoinGatherMapsWithCount(JNIEnv* env, + jclass, + jlong j_left_table, + jlong j_right_table, + jlong j_condition, + jlong j_row_count) +{ auto row_count = static_cast(j_row_count); - return cudf::jni::cond_join_gather_maps( - env, j_left_table, j_right_table, j_condition, - [row_count](cudf::table_view const &left, cudf::table_view const &right, - cudf::ast::expression const &cond_expr) { - return cudf::conditional_inner_join(left, right, cond_expr, row_count); - }); -} - -JNIEXPORT jlongArray JNICALL Java_ai_rapids_cudf_Table_mixedInnerJoinSize( - JNIEnv *env, jclass, jlong j_left_keys, jlong j_right_keys, jlong j_left_condition, - jlong j_right_condition, jlong j_condition, jboolean j_nulls_equal) { + return cudf::jni::cond_join_gather_maps(env, + j_left_table, + j_right_table, + j_condition, + [row_count](cudf::table_view const& left, + cudf::table_view const& right, + cudf::ast::expression const& cond_expr) { + return cudf::conditional_inner_join( + left, right, cond_expr, row_count); + }); +} + +JNIEXPORT jlongArray JNICALL Java_ai_rapids_cudf_Table_mixedInnerJoinSize(JNIEnv* env, + jclass, + jlong j_left_keys, + jlong j_right_keys, + jlong j_left_condition, + jlong j_right_condition, + jlong j_condition, + jboolean j_nulls_equal) +{ return cudf::jni::mixed_join_size( - env, j_left_keys, j_right_keys, j_left_condition, j_right_condition, j_condition, - j_nulls_equal, - [](cudf::table_view const &left_keys, cudf::table_view const &right_keys, - cudf::table_view const &left_condition, cudf::table_view const &right_condition, - cudf::ast::expression const &condition, cudf::null_equality nulls_equal) { - return cudf::mixed_inner_join_size(left_keys, right_keys, left_condition, right_condition, - condition, nulls_equal); - }); + env, + j_left_keys, + j_right_keys, + j_left_condition, + j_right_condition, + j_condition, + j_nulls_equal, + [](cudf::table_view const& left_keys, + cudf::table_view const& right_keys, + cudf::table_view const& left_condition, + cudf::table_view const& right_condition, + cudf::ast::expression const& condition, + cudf::null_equality nulls_equal) { + return cudf::mixed_inner_join_size( + left_keys, right_keys, left_condition, right_condition, condition, nulls_equal); + }); } -JNIEXPORT jlongArray JNICALL Java_ai_rapids_cudf_Table_mixedInnerJoinGatherMaps( - JNIEnv *env, jclass, jlong j_left_keys, jlong j_right_keys, jlong j_left_condition, - jlong j_right_condition, jlong j_condition, jboolean j_nulls_equal) { +JNIEXPORT jlongArray JNICALL +Java_ai_rapids_cudf_Table_mixedInnerJoinGatherMaps(JNIEnv* env, + jclass, + jlong j_left_keys, + jlong j_right_keys, + jlong j_left_condition, + jlong j_right_condition, + jlong j_condition, + jboolean j_nulls_equal) +{ return cudf::jni::mixed_join_gather_maps( - env, j_left_keys, j_right_keys, j_left_condition, j_right_condition, j_condition, - j_nulls_equal, - [](cudf::table_view const &left_keys, cudf::table_view const &right_keys, - cudf::table_view const &left_condition, cudf::table_view const &right_condition, - cudf::ast::expression const &condition, cudf::null_equality nulls_equal) { - return cudf::mixed_inner_join(left_keys, right_keys, left_condition, right_condition, - condition, nulls_equal); - }); + env, + j_left_keys, + j_right_keys, + j_left_condition, + j_right_condition, + j_condition, + j_nulls_equal, + [](cudf::table_view const& left_keys, + cudf::table_view const& right_keys, + cudf::table_view const& left_condition, + cudf::table_view const& right_condition, + cudf::ast::expression const& condition, + cudf::null_equality nulls_equal) { + return cudf::mixed_inner_join( + left_keys, right_keys, left_condition, right_condition, condition, nulls_equal); + }); } -JNIEXPORT jlongArray JNICALL Java_ai_rapids_cudf_Table_mixedInnerJoinGatherMapsWithSize( - JNIEnv *env, jclass, jlong j_left_keys, jlong j_right_keys, jlong j_left_condition, - jlong j_right_condition, jlong j_condition, jboolean j_nulls_equal, jlong j_output_row_count, - jlong j_matches_view) { +JNIEXPORT jlongArray JNICALL +Java_ai_rapids_cudf_Table_mixedInnerJoinGatherMapsWithSize(JNIEnv* env, + jclass, + jlong j_left_keys, + jlong j_right_keys, + jlong j_left_condition, + jlong j_right_condition, + jlong j_condition, + jboolean j_nulls_equal, + jlong j_output_row_count, + jlong j_matches_view) +{ auto size_info = cudf::jni::get_mixed_size_info(env, j_output_row_count, j_matches_view); return cudf::jni::mixed_join_gather_maps( - env, j_left_keys, j_right_keys, j_left_condition, j_right_condition, j_condition, - j_nulls_equal, - [&size_info](cudf::table_view const &left_keys, cudf::table_view const &right_keys, - cudf::table_view const &left_condition, cudf::table_view const &right_condition, - cudf::ast::expression const &condition, cudf::null_equality nulls_equal) { - return cudf::mixed_inner_join(left_keys, right_keys, left_condition, right_condition, - condition, nulls_equal, size_info); - }); + env, + j_left_keys, + j_right_keys, + j_left_condition, + j_right_condition, + j_condition, + j_nulls_equal, + [&size_info](cudf::table_view const& left_keys, + cudf::table_view const& right_keys, + cudf::table_view const& left_condition, + cudf::table_view const& right_condition, + cudf::ast::expression const& condition, + cudf::null_equality nulls_equal) { + return cudf::mixed_inner_join( + left_keys, right_keys, left_condition, right_condition, condition, nulls_equal, size_info); + }); } JNIEXPORT jlongArray JNICALL Java_ai_rapids_cudf_Table_fullJoinGatherMaps( - JNIEnv *env, jclass, jlong j_left_keys, jlong j_right_keys, jboolean compare_nulls_equal) { + JNIEnv* env, jclass, jlong j_left_keys, jlong j_right_keys, jboolean compare_nulls_equal) +{ return cudf::jni::join_gather_maps( - env, j_left_keys, j_right_keys, compare_nulls_equal, - [](cudf::table_view const &left, cudf::table_view const &right, cudf::null_equality nulleq) { - return cudf::full_join(left, right, nulleq); - }); + env, + j_left_keys, + j_right_keys, + compare_nulls_equal, + [](cudf::table_view const& left, cudf::table_view const& right, cudf::null_equality nulleq) { + return cudf::full_join(left, right, nulleq); + }); } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Table_fullJoinRowCount(JNIEnv *env, jclass, +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Table_fullJoinRowCount(JNIEnv* env, + jclass, jlong j_left_table, - jlong j_right_hash_join) { + jlong j_right_hash_join) +{ JNI_NULL_CHECK(env, j_left_table, "left table is null", 0); JNI_NULL_CHECK(env, j_right_hash_join, "right hash join is null", 0); try { cudf::jni::auto_set_device(env); - auto left_table = reinterpret_cast(j_left_table); - auto hash_join = reinterpret_cast(j_right_hash_join); - auto row_count = hash_join->full_join_size(*left_table); + auto left_table = reinterpret_cast(j_left_table); + auto hash_join = reinterpret_cast(j_right_hash_join); + auto row_count = hash_join->full_join_size(*left_table); return static_cast(row_count); } CATCH_STD(env, 0); } JNIEXPORT jlongArray JNICALL Java_ai_rapids_cudf_Table_fullHashJoinGatherMaps( - JNIEnv *env, jclass, jlong j_left_table, jlong j_right_hash_join) { + JNIEnv* env, jclass, jlong j_left_table, jlong j_right_hash_join) +{ return cudf::jni::hash_join_gather_maps( - env, j_left_table, j_right_hash_join, - [](cudf::table_view const &left, cudf::hash_join const &hash) { - return hash.full_join(left); - }); + env, + j_left_table, + j_right_hash_join, + [](cudf::table_view const& left, cudf::hash_join const& hash) { return hash.full_join(left); }); } JNIEXPORT jlongArray JNICALL Java_ai_rapids_cudf_Table_fullHashJoinGatherMapsWithCount( - JNIEnv *env, jclass, jlong j_left_table, jlong j_right_hash_join, jlong j_output_row_count) { + JNIEnv* env, jclass, jlong j_left_table, jlong j_right_hash_join, jlong j_output_row_count) +{ auto output_row_count = static_cast(j_output_row_count); return cudf::jni::hash_join_gather_maps( - env, j_left_table, j_right_hash_join, - [output_row_count](cudf::table_view const &left, cudf::hash_join const &hash) { - return hash.full_join(left, output_row_count); - }); + env, + j_left_table, + j_right_hash_join, + [output_row_count](cudf::table_view const& left, cudf::hash_join const& hash) { + return hash.full_join(left, output_row_count); + }); } JNIEXPORT jlongArray JNICALL Java_ai_rapids_cudf_Table_conditionalFullJoinGatherMaps( - JNIEnv *env, jclass, jlong j_left_table, jlong j_right_table, jlong j_condition) { - return cudf::jni::cond_join_gather_maps( - env, j_left_table, j_right_table, j_condition, - [](cudf::table_view const &left, cudf::table_view const &right, - cudf::ast::expression const &cond_expr) { - return cudf::conditional_full_join(left, right, cond_expr); - }); + JNIEnv* env, jclass, jlong j_left_table, jlong j_right_table, jlong j_condition) +{ + return cudf::jni::cond_join_gather_maps(env, + j_left_table, + j_right_table, + j_condition, + [](cudf::table_view const& left, + cudf::table_view const& right, + cudf::ast::expression const& cond_expr) { + return cudf::conditional_full_join( + left, right, cond_expr); + }); } -JNIEXPORT jlongArray JNICALL Java_ai_rapids_cudf_Table_mixedFullJoinGatherMaps( - JNIEnv *env, jclass, jlong j_left_keys, jlong j_right_keys, jlong j_left_condition, - jlong j_right_condition, jlong j_condition, jboolean j_nulls_equal) { +JNIEXPORT jlongArray JNICALL +Java_ai_rapids_cudf_Table_mixedFullJoinGatherMaps(JNIEnv* env, + jclass, + jlong j_left_keys, + jlong j_right_keys, + jlong j_left_condition, + jlong j_right_condition, + jlong j_condition, + jboolean j_nulls_equal) +{ return cudf::jni::mixed_join_gather_maps( - env, j_left_keys, j_right_keys, j_left_condition, j_right_condition, j_condition, - j_nulls_equal, - [](cudf::table_view const &left_keys, cudf::table_view const &right_keys, - cudf::table_view const &left_condition, cudf::table_view const &right_condition, - cudf::ast::expression const &condition, cudf::null_equality nulls_equal) { - return cudf::mixed_full_join(left_keys, right_keys, left_condition, right_condition, - condition, nulls_equal); - }); + env, + j_left_keys, + j_right_keys, + j_left_condition, + j_right_condition, + j_condition, + j_nulls_equal, + [](cudf::table_view const& left_keys, + cudf::table_view const& right_keys, + cudf::table_view const& left_condition, + cudf::table_view const& right_condition, + cudf::ast::expression const& condition, + cudf::null_equality nulls_equal) { + return cudf::mixed_full_join( + left_keys, right_keys, left_condition, right_condition, condition, nulls_equal); + }); } JNIEXPORT jlongArray JNICALL Java_ai_rapids_cudf_Table_leftSemiJoinGatherMap( - JNIEnv *env, jclass, jlong j_left_keys, jlong j_right_keys, jboolean compare_nulls_equal) { + JNIEnv* env, jclass, jlong j_left_keys, jlong j_right_keys, jboolean compare_nulls_equal) +{ return cudf::jni::join_gather_single_map( - env, j_left_keys, j_right_keys, compare_nulls_equal, - [](cudf::table_view const &left, cudf::table_view const &right, cudf::null_equality nulleq) { - return cudf::left_semi_join(left, right, nulleq); - }); + env, + j_left_keys, + j_right_keys, + compare_nulls_equal, + [](cudf::table_view const& left, cudf::table_view const& right, cudf::null_equality nulleq) { + return cudf::left_semi_join(left, right, nulleq); + }); } JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Table_conditionalLeftSemiJoinRowCount( - JNIEnv *env, jclass, jlong j_left_table, jlong j_right_table, jlong j_condition) { + JNIEnv* env, jclass, jlong j_left_table, jlong j_right_table, jlong j_condition) +{ JNI_NULL_CHECK(env, j_left_table, "left_table is null", 0); JNI_NULL_CHECK(env, j_right_table, "right_table is null", 0); JNI_NULL_CHECK(env, j_condition, "condition is null", 0); try { cudf::jni::auto_set_device(env); - auto left_table = reinterpret_cast(j_left_table); - auto right_table = reinterpret_cast(j_right_table); - auto condition = reinterpret_cast(j_condition); - auto row_count = cudf::conditional_left_semi_join_size(*left_table, *right_table, - condition->get_top_expression()); + auto left_table = reinterpret_cast(j_left_table); + auto right_table = reinterpret_cast(j_right_table); + auto condition = reinterpret_cast(j_condition); + auto row_count = cudf::conditional_left_semi_join_size( + *left_table, *right_table, condition->get_top_expression()); return static_cast(row_count); } CATCH_STD(env, 0); } JNIEXPORT jlongArray JNICALL Java_ai_rapids_cudf_Table_conditionalLeftSemiJoinGatherMap( - JNIEnv *env, jclass, jlong j_left_table, jlong j_right_table, jlong j_condition) { - return cudf::jni::cond_join_gather_single_map( - env, j_left_table, j_right_table, j_condition, - [](cudf::table_view const &left, cudf::table_view const &right, - cudf::ast::expression const &cond_expr) { - return cudf::conditional_left_semi_join(left, right, cond_expr); - }); + JNIEnv* env, jclass, jlong j_left_table, jlong j_right_table, jlong j_condition) +{ + return cudf::jni::cond_join_gather_single_map(env, + j_left_table, + j_right_table, + j_condition, + [](cudf::table_view const& left, + cudf::table_view const& right, + cudf::ast::expression const& cond_expr) { + return cudf::conditional_left_semi_join( + left, right, cond_expr); + }); } -JNIEXPORT jlongArray JNICALL Java_ai_rapids_cudf_Table_conditionalLeftSemiJoinGatherMapWithCount( - JNIEnv *env, jclass, jlong j_left_table, jlong j_right_table, jlong j_condition, - jlong j_row_count) { +JNIEXPORT jlongArray JNICALL +Java_ai_rapids_cudf_Table_conditionalLeftSemiJoinGatherMapWithCount(JNIEnv* env, + jclass, + jlong j_left_table, + jlong j_right_table, + jlong j_condition, + jlong j_row_count) +{ auto row_count = static_cast(j_row_count); return cudf::jni::cond_join_gather_single_map( - env, j_left_table, j_right_table, j_condition, - [row_count](cudf::table_view const &left, cudf::table_view const &right, - cudf::ast::expression const &cond_expr) { - return cudf::conditional_left_semi_join(left, right, cond_expr, row_count); - }); + env, + j_left_table, + j_right_table, + j_condition, + [row_count](cudf::table_view const& left, + cudf::table_view const& right, + cudf::ast::expression const& cond_expr) { + return cudf::conditional_left_semi_join(left, right, cond_expr, row_count); + }); } -JNIEXPORT jlongArray JNICALL Java_ai_rapids_cudf_Table_mixedLeftSemiJoinGatherMap( - JNIEnv *env, jclass, jlong j_left_keys, jlong j_right_keys, jlong j_left_condition, - jlong j_right_condition, jlong j_condition, jboolean j_nulls_equal) { +JNIEXPORT jlongArray JNICALL +Java_ai_rapids_cudf_Table_mixedLeftSemiJoinGatherMap(JNIEnv* env, + jclass, + jlong j_left_keys, + jlong j_right_keys, + jlong j_left_condition, + jlong j_right_condition, + jlong j_condition, + jboolean j_nulls_equal) +{ return cudf::jni::mixed_join_gather_single_map( - env, j_left_keys, j_right_keys, j_left_condition, j_right_condition, j_condition, - j_nulls_equal, - [](cudf::table_view const &left_keys, cudf::table_view const &right_keys, - cudf::table_view const &left_condition, cudf::table_view const &right_condition, - cudf::ast::expression const &condition, cudf::null_equality nulls_equal) { - return cudf::mixed_left_semi_join(left_keys, right_keys, left_condition, right_condition, - condition, nulls_equal); - }); + env, + j_left_keys, + j_right_keys, + j_left_condition, + j_right_condition, + j_condition, + j_nulls_equal, + [](cudf::table_view const& left_keys, + cudf::table_view const& right_keys, + cudf::table_view const& left_condition, + cudf::table_view const& right_condition, + cudf::ast::expression const& condition, + cudf::null_equality nulls_equal) { + return cudf::mixed_left_semi_join( + left_keys, right_keys, left_condition, right_condition, condition, nulls_equal); + }); } JNIEXPORT jlongArray JNICALL Java_ai_rapids_cudf_Table_leftAntiJoinGatherMap( - JNIEnv *env, jclass, jlong j_left_keys, jlong j_right_keys, jboolean compare_nulls_equal) { + JNIEnv* env, jclass, jlong j_left_keys, jlong j_right_keys, jboolean compare_nulls_equal) +{ return cudf::jni::join_gather_single_map( - env, j_left_keys, j_right_keys, compare_nulls_equal, - [](cudf::table_view const &left, cudf::table_view const &right, cudf::null_equality nulleq) { - return cudf::left_anti_join(left, right, nulleq); - }); + env, + j_left_keys, + j_right_keys, + compare_nulls_equal, + [](cudf::table_view const& left, cudf::table_view const& right, cudf::null_equality nulleq) { + return cudf::left_anti_join(left, right, nulleq); + }); } JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Table_conditionalLeftAntiJoinRowCount( - JNIEnv *env, jclass, jlong j_left_table, jlong j_right_table, jlong j_condition) { + JNIEnv* env, jclass, jlong j_left_table, jlong j_right_table, jlong j_condition) +{ JNI_NULL_CHECK(env, j_left_table, "left_table is null", 0); JNI_NULL_CHECK(env, j_right_table, "right_table is null", 0); JNI_NULL_CHECK(env, j_condition, "condition is null", 0); try { cudf::jni::auto_set_device(env); - auto left_table = reinterpret_cast(j_left_table); - auto right_table = reinterpret_cast(j_right_table); - auto condition = reinterpret_cast(j_condition); - auto row_count = cudf::conditional_left_anti_join_size(*left_table, *right_table, - condition->get_top_expression()); + auto left_table = reinterpret_cast(j_left_table); + auto right_table = reinterpret_cast(j_right_table); + auto condition = reinterpret_cast(j_condition); + auto row_count = cudf::conditional_left_anti_join_size( + *left_table, *right_table, condition->get_top_expression()); return static_cast(row_count); } CATCH_STD(env, 0); } JNIEXPORT jlongArray JNICALL Java_ai_rapids_cudf_Table_conditionalLeftAntiJoinGatherMap( - JNIEnv *env, jclass, jlong j_left_table, jlong j_right_table, jlong j_condition) { - return cudf::jni::cond_join_gather_single_map( - env, j_left_table, j_right_table, j_condition, - [](cudf::table_view const &left, cudf::table_view const &right, - cudf::ast::expression const &cond_expr) { - return cudf::conditional_left_anti_join(left, right, cond_expr); - }); + JNIEnv* env, jclass, jlong j_left_table, jlong j_right_table, jlong j_condition) +{ + return cudf::jni::cond_join_gather_single_map(env, + j_left_table, + j_right_table, + j_condition, + [](cudf::table_view const& left, + cudf::table_view const& right, + cudf::ast::expression const& cond_expr) { + return cudf::conditional_left_anti_join( + left, right, cond_expr); + }); } -JNIEXPORT jlongArray JNICALL Java_ai_rapids_cudf_Table_conditionalLeftAntiJoinGatherMapWithCount( - JNIEnv *env, jclass, jlong j_left_table, jlong j_right_table, jlong j_condition, - jlong j_row_count) { +JNIEXPORT jlongArray JNICALL +Java_ai_rapids_cudf_Table_conditionalLeftAntiJoinGatherMapWithCount(JNIEnv* env, + jclass, + jlong j_left_table, + jlong j_right_table, + jlong j_condition, + jlong j_row_count) +{ auto row_count = static_cast(j_row_count); return cudf::jni::cond_join_gather_single_map( - env, j_left_table, j_right_table, j_condition, - [row_count](cudf::table_view const &left, cudf::table_view const &right, - cudf::ast::expression const &cond_expr) { - return cudf::conditional_left_anti_join(left, right, cond_expr, row_count); - }); + env, + j_left_table, + j_right_table, + j_condition, + [row_count](cudf::table_view const& left, + cudf::table_view const& right, + cudf::ast::expression const& cond_expr) { + return cudf::conditional_left_anti_join(left, right, cond_expr, row_count); + }); } -JNIEXPORT jlongArray JNICALL Java_ai_rapids_cudf_Table_mixedLeftAntiJoinGatherMap( - JNIEnv *env, jclass, jlong j_left_keys, jlong j_right_keys, jlong j_left_condition, - jlong j_right_condition, jlong j_condition, jboolean j_nulls_equal) { +JNIEXPORT jlongArray JNICALL +Java_ai_rapids_cudf_Table_mixedLeftAntiJoinGatherMap(JNIEnv* env, + jclass, + jlong j_left_keys, + jlong j_right_keys, + jlong j_left_condition, + jlong j_right_condition, + jlong j_condition, + jboolean j_nulls_equal) +{ return cudf::jni::mixed_join_gather_single_map( - env, j_left_keys, j_right_keys, j_left_condition, j_right_condition, j_condition, - j_nulls_equal, - [](cudf::table_view const &left_keys, cudf::table_view const &right_keys, - cudf::table_view const &left_condition, cudf::table_view const &right_condition, - cudf::ast::expression const &condition, cudf::null_equality nulls_equal) { - return cudf::mixed_left_anti_join(left_keys, right_keys, left_condition, right_condition, - condition, nulls_equal); - }); -} - -JNIEXPORT jlongArray JNICALL Java_ai_rapids_cudf_Table_crossJoin(JNIEnv *env, jclass, + env, + j_left_keys, + j_right_keys, + j_left_condition, + j_right_condition, + j_condition, + j_nulls_equal, + [](cudf::table_view const& left_keys, + cudf::table_view const& right_keys, + cudf::table_view const& left_condition, + cudf::table_view const& right_condition, + cudf::ast::expression const& condition, + cudf::null_equality nulls_equal) { + return cudf::mixed_left_anti_join( + left_keys, right_keys, left_condition, right_condition, condition, nulls_equal); + }); +} + +JNIEXPORT jlongArray JNICALL Java_ai_rapids_cudf_Table_crossJoin(JNIEnv* env, + jclass, jlong left_table, - jlong right_table) { + jlong right_table) +{ JNI_NULL_CHECK(env, left_table, "left_table is null", NULL); JNI_NULL_CHECK(env, right_table, "right_table is null", NULL); try { cudf::jni::auto_set_device(env); - auto const left = reinterpret_cast(left_table); - auto const right = reinterpret_cast(right_table); + auto const left = reinterpret_cast(left_table); + auto const right = reinterpret_cast(right_table); return convert_table_for_return(env, cudf::cross_join(*left, *right)); } CATCH_STD(env, NULL); } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Table_interleaveColumns(JNIEnv *env, jclass, - jlongArray j_cudf_table_view) { - +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Table_interleaveColumns(JNIEnv* env, + jclass, + jlongArray j_cudf_table_view) +{ JNI_NULL_CHECK(env, j_cudf_table_view, "table is null", 0); try { cudf::jni::auto_set_device(env); - cudf::table_view *table_view = reinterpret_cast(j_cudf_table_view); + cudf::table_view* table_view = reinterpret_cast(j_cudf_table_view); return release_as_jlong(cudf::interleave_columns(*table_view)); } CATCH_STD(env, 0); } -JNIEXPORT jlongArray JNICALL Java_ai_rapids_cudf_Table_concatenate(JNIEnv *env, jclass, - jlongArray table_handles) { +JNIEXPORT jlongArray JNICALL Java_ai_rapids_cudf_Table_concatenate(JNIEnv* env, + jclass, + jlongArray table_handles) +{ JNI_NULL_CHECK(env, table_handles, "input tables are null", NULL); try { cudf::jni::auto_set_device(env); @@ -2953,12 +3541,13 @@ JNIEXPORT jlongArray JNICALL Java_ai_rapids_cudf_Table_concatenate(JNIEnv *env, CATCH_STD(env, NULL); } -JNIEXPORT jlongArray JNICALL Java_ai_rapids_cudf_Table_partition(JNIEnv *env, jclass, +JNIEXPORT jlongArray JNICALL Java_ai_rapids_cudf_Table_partition(JNIEnv* env, + jclass, jlong input_table, jlong partition_column, jint number_of_partitions, - jintArray output_offsets) { - + jintArray output_offsets) +{ JNI_NULL_CHECK(env, input_table, "input table is null", NULL); JNI_NULL_CHECK(env, partition_column, "partition_column is null", NULL); JNI_NULL_CHECK(env, output_offsets, "output_offsets is null", NULL); @@ -2966,11 +3555,11 @@ JNIEXPORT jlongArray JNICALL Java_ai_rapids_cudf_Table_partition(JNIEnv *env, jc try { cudf::jni::auto_set_device(env); - auto const n_input_table = reinterpret_cast(input_table); - auto const n_part_column = reinterpret_cast(partition_column); + auto const n_input_table = reinterpret_cast(input_table); + auto const n_part_column = reinterpret_cast(partition_column); auto [partitioned_table, partition_offsets] = - cudf::partition(*n_input_table, *n_part_column, number_of_partitions); + cudf::partition(*n_input_table, *n_part_column, number_of_partitions); // for what ever reason partition returns the length of the result at then // end and hash partition/round robin do not, so skip the last entry for @@ -2983,10 +3572,15 @@ JNIEXPORT jlongArray JNICALL Java_ai_rapids_cudf_Table_partition(JNIEnv *env, jc CATCH_STD(env, NULL); } -JNIEXPORT jlongArray JNICALL Java_ai_rapids_cudf_Table_hashPartition( - JNIEnv *env, jclass, jlong input_table, jintArray columns_to_hash, jint hash_function, - jint number_of_partitions, jint seed, jintArray output_offsets) { - +JNIEXPORT jlongArray JNICALL Java_ai_rapids_cudf_Table_hashPartition(JNIEnv* env, + jclass, + jlong input_table, + jintArray columns_to_hash, + jint hash_function, + jint number_of_partitions, + jint seed, + jintArray output_offsets) +{ JNI_NULL_CHECK(env, input_table, "input table is null", NULL); JNI_NULL_CHECK(env, columns_to_hash, "columns_to_hash is null", NULL); JNI_NULL_CHECK(env, output_offsets, "output_offsets is null", NULL); @@ -2994,9 +3588,9 @@ JNIEXPORT jlongArray JNICALL Java_ai_rapids_cudf_Table_hashPartition( try { cudf::jni::auto_set_device(env); - auto const hash_func = static_cast(hash_function); - auto const hash_seed = static_cast(seed); - auto const n_input_table = reinterpret_cast(input_table); + auto const hash_func = static_cast(hash_function); + auto const hash_seed = static_cast(seed); + auto const n_input_table = reinterpret_cast(input_table); cudf::jni::native_jintArray n_columns_to_hash(env, columns_to_hash); JNI_ARG_CHECK(env, n_columns_to_hash.size() > 0, "columns_to_hash is zero", NULL); @@ -3004,7 +3598,7 @@ JNIEXPORT jlongArray JNICALL Java_ai_rapids_cudf_Table_hashPartition( n_columns_to_hash.end()); auto [partitioned_table, partition_offsets] = cudf::hash_partition( - *n_input_table, columns_to_hash_vec, number_of_partitions, hash_func, hash_seed); + *n_input_table, columns_to_hash_vec, number_of_partitions, hash_func, hash_seed); cudf::jni::native_jintArray n_output_offsets(env, output_offsets); std::copy(partition_offsets.begin(), partition_offsets.end(), n_output_offsets.begin()); @@ -3014,9 +3608,13 @@ JNIEXPORT jlongArray JNICALL Java_ai_rapids_cudf_Table_hashPartition( CATCH_STD(env, NULL); } -JNIEXPORT jlongArray JNICALL Java_ai_rapids_cudf_Table_roundRobinPartition( - JNIEnv *env, jclass, jlong input_table, jint num_partitions, jint start_partition, - jintArray output_offsets) { +JNIEXPORT jlongArray JNICALL Java_ai_rapids_cudf_Table_roundRobinPartition(JNIEnv* env, + jclass, + jlong input_table, + jint num_partitions, + jint start_partition, + jintArray output_offsets) +{ JNI_NULL_CHECK(env, input_table, "input table is null", NULL); JNI_NULL_CHECK(env, output_offsets, "output_offsets is null", NULL); JNI_ARG_CHECK(env, num_partitions > 0, "num_partitions <= 0", NULL); @@ -3024,10 +3622,10 @@ JNIEXPORT jlongArray JNICALL Java_ai_rapids_cudf_Table_roundRobinPartition( try { cudf::jni::auto_set_device(env); - auto n_input_table = reinterpret_cast(input_table); + auto n_input_table = reinterpret_cast(input_table); auto [partitioned_table, partition_offsets] = - cudf::round_robin_partition(*n_input_table, num_partitions, start_partition); + cudf::round_robin_partition(*n_input_table, num_partitions, start_partition); cudf::jni::native_jintArray n_output_offsets(env, output_offsets); std::copy(partition_offsets.begin(), partition_offsets.end(), n_output_offsets.begin()); @@ -3037,10 +3635,18 @@ JNIEXPORT jlongArray JNICALL Java_ai_rapids_cudf_Table_roundRobinPartition( CATCH_STD(env, NULL); } -JNIEXPORT jlongArray JNICALL Java_ai_rapids_cudf_Table_groupByAggregate( - JNIEnv *env, jclass, jlong input_table, jintArray keys, jintArray aggregate_column_indices, - jlongArray agg_instances, jboolean ignore_null_keys, jboolean jkey_sorted, - jbooleanArray jkeys_sort_desc, jbooleanArray jkeys_null_first) { +JNIEXPORT jlongArray JNICALL +Java_ai_rapids_cudf_Table_groupByAggregate(JNIEnv* env, + jclass, + jlong input_table, + jintArray keys, + jintArray aggregate_column_indices, + jlongArray agg_instances, + jboolean ignore_null_keys, + jboolean jkey_sorted, + jbooleanArray jkeys_sort_desc, + jbooleanArray jkeys_null_first) +{ JNI_NULL_CHECK(env, input_table, "input table is null", NULL); JNI_NULL_CHECK(env, keys, "input keys are null", NULL); JNI_NULL_CHECK(env, aggregate_column_indices, "input aggregate_column_indices are null", NULL); @@ -3048,7 +3654,7 @@ JNIEXPORT jlongArray JNICALL Java_ai_rapids_cudf_Table_groupByAggregate( try { cudf::jni::auto_set_device(env); - cudf::table_view *n_input_table = reinterpret_cast(input_table); + cudf::table_view* n_input_table = reinterpret_cast(input_table); cudf::jni::native_jintArray n_keys(env, keys); cudf::jni::native_jintArray n_values(env, aggregate_column_indices); cudf::jni::native_jpointerArray n_agg_instances(env, agg_instances); @@ -3059,11 +3665,14 @@ JNIEXPORT jlongArray JNICALL Java_ai_rapids_cudf_Table_groupByAggregate( } cudf::table_view n_keys_table(n_keys_cols); - auto column_order = cudf::jni::resolve_column_order(env, jkeys_sort_desc, n_keys.size()); + auto column_order = cudf::jni::resolve_column_order(env, jkeys_sort_desc, n_keys.size()); auto null_precedence = cudf::jni::resolve_null_precedence(env, jkeys_null_first, n_keys.size()); cudf::groupby::groupby grouper( - n_keys_table, ignore_null_keys ? cudf::null_policy::EXCLUDE : cudf::null_policy::INCLUDE, - jkey_sorted ? cudf::sorted::YES : cudf::sorted::NO, column_order, null_precedence); + n_keys_table, + ignore_null_keys ? cudf::null_policy::EXCLUDE : cudf::null_policy::INCLUDE, + jkey_sorted ? cudf::sorted::YES : cudf::sorted::NO, + column_order, + null_precedence); // Aggregates are passed in already grouped by column, so we just need to fill it in // as we go. @@ -3074,12 +3683,11 @@ JNIEXPORT jlongArray JNICALL Java_ai_rapids_cudf_Table_groupByAggregate( cudf::groupby::aggregation_request req; int col_index = n_values[i]; - cudf::groupby_aggregation *agg = - dynamic_cast(n_agg_instances[i]); - JNI_ARG_CHECK(env, agg != nullptr, "aggregation is not an instance of groupby_aggregation", - nullptr); + cudf::groupby_aggregation* agg = dynamic_cast(n_agg_instances[i]); + JNI_ARG_CHECK( + env, agg != nullptr, "aggregation is not an instance of groupby_aggregation", nullptr); std::unique_ptr cloned( - dynamic_cast(agg->clone().release())); + dynamic_cast(agg->clone().release())); if (col_index == previous_index) { requests.back().aggregations.push_back(std::move(cloned)); @@ -3092,7 +3700,7 @@ JNIEXPORT jlongArray JNICALL Java_ai_rapids_cudf_Table_groupByAggregate( } std::pair, std::vector> result = - grouper.aggregate(requests); + grouper.aggregate(requests); std::vector> result_columns; int agg_result_size = result.second.size(); @@ -3107,10 +3715,18 @@ JNIEXPORT jlongArray JNICALL Java_ai_rapids_cudf_Table_groupByAggregate( CATCH_STD(env, NULL); } -JNIEXPORT jlongArray JNICALL Java_ai_rapids_cudf_Table_groupByScan( - JNIEnv *env, jclass, jlong input_table, jintArray keys, jintArray aggregate_column_indices, - jlongArray agg_instances, jboolean ignore_null_keys, jboolean jkey_sorted, - jbooleanArray jkeys_sort_desc, jbooleanArray jkeys_null_first) { +JNIEXPORT jlongArray JNICALL +Java_ai_rapids_cudf_Table_groupByScan(JNIEnv* env, + jclass, + jlong input_table, + jintArray keys, + jintArray aggregate_column_indices, + jlongArray agg_instances, + jboolean ignore_null_keys, + jboolean jkey_sorted, + jbooleanArray jkeys_sort_desc, + jbooleanArray jkeys_null_first) +{ JNI_NULL_CHECK(env, input_table, "input table is null", NULL); JNI_NULL_CHECK(env, keys, "input keys are null", NULL); JNI_NULL_CHECK(env, aggregate_column_indices, "input aggregate_column_indices are null", NULL); @@ -3118,7 +3734,7 @@ JNIEXPORT jlongArray JNICALL Java_ai_rapids_cudf_Table_groupByScan( try { cudf::jni::auto_set_device(env); - cudf::table_view *n_input_table = reinterpret_cast(input_table); + cudf::table_view* n_input_table = reinterpret_cast(input_table); cudf::jni::native_jintArray n_keys(env, keys); cudf::jni::native_jintArray n_values(env, aggregate_column_indices); cudf::jni::native_jpointerArray n_agg_instances(env, agg_instances); @@ -3129,11 +3745,14 @@ JNIEXPORT jlongArray JNICALL Java_ai_rapids_cudf_Table_groupByScan( } cudf::table_view n_keys_table(n_keys_cols); - auto column_order = cudf::jni::resolve_column_order(env, jkeys_sort_desc, n_keys.size()); + auto column_order = cudf::jni::resolve_column_order(env, jkeys_sort_desc, n_keys.size()); auto null_precedence = cudf::jni::resolve_null_precedence(env, jkeys_null_first, n_keys.size()); cudf::groupby::groupby grouper( - n_keys_table, ignore_null_keys ? cudf::null_policy::EXCLUDE : cudf::null_policy::INCLUDE, - jkey_sorted ? cudf::sorted::YES : cudf::sorted::NO, column_order, null_precedence); + n_keys_table, + ignore_null_keys ? cudf::null_policy::EXCLUDE : cudf::null_policy::INCLUDE, + jkey_sorted ? cudf::sorted::YES : cudf::sorted::NO, + column_order, + null_precedence); // Aggregates are passed in already grouped by column, so we just need to fill it in // as we go. @@ -3144,12 +3763,12 @@ JNIEXPORT jlongArray JNICALL Java_ai_rapids_cudf_Table_groupByScan( cudf::groupby::scan_request req; int col_index = n_values[i]; - cudf::groupby_scan_aggregation *agg = - dynamic_cast(n_agg_instances[i]); - JNI_ARG_CHECK(env, agg != nullptr, - "aggregation is not an instance of groupby_scan_aggregation", nullptr); + cudf::groupby_scan_aggregation* agg = + dynamic_cast(n_agg_instances[i]); + JNI_ARG_CHECK( + env, agg != nullptr, "aggregation is not an instance of groupby_scan_aggregation", nullptr); std::unique_ptr cloned( - dynamic_cast(agg->clone().release())); + dynamic_cast(agg->clone().release())); if (col_index == previous_index) { requests.back().aggregations.push_back(std::move(cloned)); @@ -3162,7 +3781,7 @@ JNIEXPORT jlongArray JNICALL Java_ai_rapids_cudf_Table_groupByScan( } std::pair, std::vector> result = - grouper.scan(requests); + grouper.scan(requests); std::vector> result_columns; int agg_result_size = result.second.size(); @@ -3177,10 +3796,18 @@ JNIEXPORT jlongArray JNICALL Java_ai_rapids_cudf_Table_groupByScan( CATCH_STD(env, NULL); } -JNIEXPORT jlongArray JNICALL Java_ai_rapids_cudf_Table_groupByReplaceNulls( - JNIEnv *env, jclass, jlong input_table, jintArray keys, jintArray replace_column_indices, - jbooleanArray is_preceding, jboolean ignore_null_keys, jboolean jkey_sorted, - jbooleanArray jkeys_sort_desc, jbooleanArray jkeys_null_first) { +JNIEXPORT jlongArray JNICALL +Java_ai_rapids_cudf_Table_groupByReplaceNulls(JNIEnv* env, + jclass, + jlong input_table, + jintArray keys, + jintArray replace_column_indices, + jbooleanArray is_preceding, + jboolean ignore_null_keys, + jboolean jkey_sorted, + jbooleanArray jkeys_sort_desc, + jbooleanArray jkeys_null_first) +{ JNI_NULL_CHECK(env, input_table, "input table is null", NULL); JNI_NULL_CHECK(env, keys, "input keys are null", NULL); JNI_NULL_CHECK(env, replace_column_indices, "input replace_column_indices are null", NULL); @@ -3188,7 +3815,7 @@ JNIEXPORT jlongArray JNICALL Java_ai_rapids_cudf_Table_groupByReplaceNulls( try { cudf::jni::auto_set_device(env); - cudf::table_view *n_input_table = reinterpret_cast(input_table); + cudf::table_view* n_input_table = reinterpret_cast(input_table); cudf::jni::native_jintArray n_keys(env, keys); cudf::jni::native_jintArray n_values(env, replace_column_indices); cudf::jni::native_jbooleanArray n_is_preceding(env, is_preceding); @@ -3199,11 +3826,14 @@ JNIEXPORT jlongArray JNICALL Java_ai_rapids_cudf_Table_groupByReplaceNulls( } cudf::table_view n_keys_table(n_keys_cols); - auto column_order = cudf::jni::resolve_column_order(env, jkeys_sort_desc, n_keys.size()); + auto column_order = cudf::jni::resolve_column_order(env, jkeys_sort_desc, n_keys.size()); auto null_precedence = cudf::jni::resolve_null_precedence(env, jkeys_null_first, n_keys.size()); cudf::groupby::groupby grouper( - n_keys_table, ignore_null_keys ? cudf::null_policy::EXCLUDE : cudf::null_policy::INCLUDE, - jkey_sorted ? cudf::sorted::YES : cudf::sorted::NO, column_order, null_precedence); + n_keys_table, + ignore_null_keys ? cudf::null_policy::EXCLUDE : cudf::null_policy::INCLUDE, + jkey_sorted ? cudf::sorted::YES : cudf::sorted::NO, + column_order, + null_precedence); // Aggregates are passed in already grouped by column, so we just need to fill it in // as we go. @@ -3215,7 +3845,7 @@ JNIEXPORT jlongArray JNICALL Java_ai_rapids_cudf_Table_groupByReplaceNulls( cudf::table_view n_replace_table(n_replace_cols); std::vector policies = n_is_preceding.transform_if_else( - cudf::replace_policy::PRECEDING, cudf::replace_policy::FOLLOWING); + cudf::replace_policy::PRECEDING, cudf::replace_policy::FOLLOWING); auto [keys, results] = grouper.replace_nulls(n_replace_table, policies); return convert_table_for_return(env, keys, results); @@ -3223,48 +3853,51 @@ JNIEXPORT jlongArray JNICALL Java_ai_rapids_cudf_Table_groupByReplaceNulls( CATCH_STD(env, NULL); } -JNIEXPORT jlongArray JNICALL Java_ai_rapids_cudf_Table_filter(JNIEnv *env, jclass, - jlong input_jtable, jlong mask_jcol) { +JNIEXPORT jlongArray JNICALL Java_ai_rapids_cudf_Table_filter(JNIEnv* env, + jclass, + jlong input_jtable, + jlong mask_jcol) +{ JNI_NULL_CHECK(env, input_jtable, "input table is null", 0); JNI_NULL_CHECK(env, mask_jcol, "mask column is null", 0); try { cudf::jni::auto_set_device(env); - auto const input = reinterpret_cast(input_jtable); - auto const mask = reinterpret_cast(mask_jcol); + auto const input = reinterpret_cast(input_jtable); + auto const mask = reinterpret_cast(mask_jcol); return convert_table_for_return(env, cudf::apply_boolean_mask(*input, *mask)); } CATCH_STD(env, 0); } -JNIEXPORT jint JNICALL Java_ai_rapids_cudf_Table_distinctCount(JNIEnv *env, jclass, +JNIEXPORT jint JNICALL Java_ai_rapids_cudf_Table_distinctCount(JNIEnv* env, + jclass, jlong input_jtable, - jboolean nulls_equal) { + jboolean nulls_equal) +{ JNI_NULL_CHECK(env, input_jtable, "input table is null", 0); try { cudf::jni::auto_set_device(env); - auto const input = reinterpret_cast(input_jtable); + auto const input = reinterpret_cast(input_jtable); - return cudf::distinct_count(*input, nulls_equal ? cudf::null_equality::EQUAL : - cudf::null_equality::UNEQUAL); + return cudf::distinct_count( + *input, nulls_equal ? cudf::null_equality::EQUAL : cudf::null_equality::UNEQUAL); } CATCH_STD(env, 0); } -JNIEXPORT jlongArray JNICALL Java_ai_rapids_cudf_Table_dropDuplicates(JNIEnv *env, jclass, - jlong input_jtable, - jintArray key_columns, - jint keep, - jboolean nulls_equal) { +JNIEXPORT jlongArray JNICALL Java_ai_rapids_cudf_Table_dropDuplicates( + JNIEnv* env, jclass, jlong input_jtable, jintArray key_columns, jint keep, jboolean nulls_equal) +{ JNI_NULL_CHECK(env, input_jtable, "input table is null", 0); JNI_NULL_CHECK(env, key_columns, "input key_columns is null", 0); try { cudf::jni::auto_set_device(env); - auto const input = reinterpret_cast(input_jtable); + auto const input = reinterpret_cast(input_jtable); static_assert(sizeof(jint) == sizeof(cudf::size_type), "Integer types mismatched."); auto const native_keys_indices = cudf::jni::native_jintArray(env, key_columns); auto const keys_indices = - std::vector(native_keys_indices.begin(), native_keys_indices.end()); + std::vector(native_keys_indices.begin(), native_keys_indices.end()); auto const keep_option = [&] { switch (keep) { case 0: return cudf::duplicate_keep_option::KEEP_ANY; @@ -3272,54 +3905,60 @@ JNIEXPORT jlongArray JNICALL Java_ai_rapids_cudf_Table_dropDuplicates(JNIEnv *en case 2: return cudf::duplicate_keep_option::KEEP_LAST; case 3: return cudf::duplicate_keep_option::KEEP_NONE; default: - JNI_THROW_NEW(env, cudf::jni::ILLEGAL_ARG_CLASS, "Invalid `keep` option", + JNI_THROW_NEW(env, + cudf::jni::ILLEGAL_ARG_CLASS, + "Invalid `keep` option", cudf::duplicate_keep_option::KEEP_ANY); } }(); auto result = - cudf::distinct(*input, keys_indices, keep_option, - nulls_equal ? cudf::null_equality::EQUAL : cudf::null_equality::UNEQUAL, - cudf::nan_equality::ALL_EQUAL, rmm::mr::get_current_device_resource()); + cudf::distinct(*input, + keys_indices, + keep_option, + nulls_equal ? cudf::null_equality::EQUAL : cudf::null_equality::UNEQUAL, + cudf::nan_equality::ALL_EQUAL, + rmm::mr::get_current_device_resource()); return convert_table_for_return(env, result); } CATCH_STD(env, 0); } -JNIEXPORT jlongArray JNICALL Java_ai_rapids_cudf_Table_gather(JNIEnv *env, jclass, jlong j_input, - jlong j_map, jboolean check_bounds) { +JNIEXPORT jlongArray JNICALL Java_ai_rapids_cudf_Table_gather( + JNIEnv* env, jclass, jlong j_input, jlong j_map, jboolean check_bounds) +{ JNI_NULL_CHECK(env, j_input, "input table is null", 0); JNI_NULL_CHECK(env, j_map, "map column is null", 0); try { cudf::jni::auto_set_device(env); - auto const input = reinterpret_cast(j_input); - auto const map = reinterpret_cast(j_map); + auto const input = reinterpret_cast(j_input); + auto const map = reinterpret_cast(j_map); auto bounds_policy = - check_bounds ? cudf::out_of_bounds_policy::NULLIFY : cudf::out_of_bounds_policy::DONT_CHECK; + check_bounds ? cudf::out_of_bounds_policy::NULLIFY : cudf::out_of_bounds_policy::DONT_CHECK; return convert_table_for_return(env, cudf::gather(*input, *map, bounds_policy)); } CATCH_STD(env, 0); } -JNIEXPORT jlongArray JNICALL Java_ai_rapids_cudf_Table_scatterTable(JNIEnv *env, jclass, - jlong j_input, jlong j_map, - jlong j_target) { +JNIEXPORT jlongArray JNICALL Java_ai_rapids_cudf_Table_scatterTable( + JNIEnv* env, jclass, jlong j_input, jlong j_map, jlong j_target) +{ JNI_NULL_CHECK(env, j_input, "input table is null", 0); JNI_NULL_CHECK(env, j_map, "map column is null", 0); JNI_NULL_CHECK(env, j_target, "target table is null", 0); try { cudf::jni::auto_set_device(env); - auto const input = reinterpret_cast(j_input); - auto const map = reinterpret_cast(j_map); - auto const target = reinterpret_cast(j_target); + auto const input = reinterpret_cast(j_input); + auto const map = reinterpret_cast(j_map); + auto const target = reinterpret_cast(j_target); return convert_table_for_return(env, cudf::scatter(*input, *map, *target)); } CATCH_STD(env, 0); } -JNIEXPORT jlongArray JNICALL Java_ai_rapids_cudf_Table_scatterScalars(JNIEnv *env, jclass, - jlongArray j_input, - jlong j_map, jlong j_target) { +JNIEXPORT jlongArray JNICALL Java_ai_rapids_cudf_Table_scatterScalars( + JNIEnv* env, jclass, jlongArray j_input, jlong j_map, jlong j_target) +{ JNI_NULL_CHECK(env, j_input, "input scalars array is null", 0); JNI_NULL_CHECK(env, j_map, "map column is null", 0); JNI_NULL_CHECK(env, j_target, "target table is null", 0); @@ -3327,81 +3966,94 @@ JNIEXPORT jlongArray JNICALL Java_ai_rapids_cudf_Table_scatterScalars(JNIEnv *en cudf::jni::auto_set_device(env); auto const scalars_array = cudf::jni::native_jpointerArray(env, j_input); std::vector> input; - std::transform(scalars_array.begin(), scalars_array.end(), std::back_inserter(input), - [](auto &scalar) { return std::ref(*scalar); }); - auto const map = reinterpret_cast(j_map); - auto const target = reinterpret_cast(j_target); + std::transform( + scalars_array.begin(), scalars_array.end(), std::back_inserter(input), [](auto& scalar) { + return std::ref(*scalar); + }); + auto const map = reinterpret_cast(j_map); + auto const target = reinterpret_cast(j_target); return convert_table_for_return(env, cudf::scatter(input, *map, *target)); } CATCH_STD(env, 0); } -JNIEXPORT jlongArray JNICALL Java_ai_rapids_cudf_Table_repeatStaticCount(JNIEnv *env, jclass, +JNIEXPORT jlongArray JNICALL Java_ai_rapids_cudf_Table_repeatStaticCount(JNIEnv* env, + jclass, jlong input_jtable, - jint count) { + jint count) +{ JNI_NULL_CHECK(env, input_jtable, "input table is null", 0); try { cudf::jni::auto_set_device(env); - auto const input = reinterpret_cast(input_jtable); + auto const input = reinterpret_cast(input_jtable); return convert_table_for_return(env, cudf::repeat(*input, count)); } CATCH_STD(env, 0); } -JNIEXPORT jlongArray JNICALL Java_ai_rapids_cudf_Table_repeatColumnCount(JNIEnv *env, jclass, +JNIEXPORT jlongArray JNICALL Java_ai_rapids_cudf_Table_repeatColumnCount(JNIEnv* env, + jclass, jlong input_jtable, - jlong count_jcol) { + jlong count_jcol) +{ JNI_NULL_CHECK(env, input_jtable, "input table is null", 0); JNI_NULL_CHECK(env, count_jcol, "count column is null", 0); try { cudf::jni::auto_set_device(env); - auto const input = reinterpret_cast(input_jtable); - auto const count = reinterpret_cast(count_jcol); + auto const input = reinterpret_cast(input_jtable); + auto const count = reinterpret_cast(count_jcol); return convert_table_for_return(env, cudf::repeat(*input, *count)); } CATCH_STD(env, 0); } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Table_bound(JNIEnv *env, jclass, jlong input_jtable, +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Table_bound(JNIEnv* env, + jclass, + jlong input_jtable, jlong values_jtable, jbooleanArray desc_flags, jbooleanArray are_nulls_smallest, - jboolean is_upper_bound) { + jboolean is_upper_bound) +{ JNI_NULL_CHECK(env, input_jtable, "input table is null", 0); JNI_NULL_CHECK(env, values_jtable, "values table is null", 0); using cudf::column; using cudf::table_view; try { cudf::jni::auto_set_device(env); - table_view *input = reinterpret_cast(input_jtable); - table_view *values = reinterpret_cast(values_jtable); + table_view* input = reinterpret_cast(input_jtable); + table_view* values = reinterpret_cast(values_jtable); cudf::jni::native_jbooleanArray const n_desc_flags(env, desc_flags); cudf::jni::native_jbooleanArray const n_are_nulls_smallest(env, are_nulls_smallest); std::vector column_desc_flags{ - n_desc_flags.transform_if_else(cudf::order::DESCENDING, cudf::order::ASCENDING)}; + n_desc_flags.transform_if_else(cudf::order::DESCENDING, cudf::order::ASCENDING)}; std::vector column_null_orders{ - n_are_nulls_smallest.transform_if_else(cudf::null_order::BEFORE, cudf::null_order::AFTER)}; + n_are_nulls_smallest.transform_if_else(cudf::null_order::BEFORE, cudf::null_order::AFTER)}; - JNI_ARG_CHECK(env, (column_desc_flags.size() == column_null_orders.size()), - "null-order and sort-order size mismatch", 0); + JNI_ARG_CHECK(env, + (column_desc_flags.size() == column_null_orders.size()), + "null-order and sort-order size mismatch", + 0); return release_as_jlong( - is_upper_bound ? cudf::upper_bound(*input, *values, column_desc_flags, column_null_orders) : - cudf::lower_bound(*input, *values, column_desc_flags, column_null_orders)); + is_upper_bound ? cudf::upper_bound(*input, *values, column_desc_flags, column_null_orders) + : cudf::lower_bound(*input, *values, column_desc_flags, column_null_orders)); } CATCH_STD(env, 0); } -JNIEXPORT jobjectArray JNICALL Java_ai_rapids_cudf_Table_contiguousSplit(JNIEnv *env, jclass, +JNIEXPORT jobjectArray JNICALL Java_ai_rapids_cudf_Table_contiguousSplit(JNIEnv* env, + jclass, jlong input_table, - jintArray split_indices) { + jintArray split_indices) +{ JNI_NULL_CHECK(env, input_table, "native handle is null", 0); JNI_NULL_CHECK(env, split_indices, "split indices are null", 0); try { cudf::jni::auto_set_device(env); - cudf::table_view *n_table = reinterpret_cast(input_table); + cudf::table_view* n_table = reinterpret_cast(input_table); cudf::jni::native_jintArray n_split_indices(env, split_indices); std::vector indices(n_split_indices.data(), @@ -3409,42 +4061,50 @@ JNIEXPORT jobjectArray JNICALL Java_ai_rapids_cudf_Table_contiguousSplit(JNIEnv std::vector result = cudf::contiguous_split(*n_table, indices); cudf::jni::native_jobjectArray n_result = - cudf::jni::contiguous_table_array(env, result.size()); + cudf::jni::contiguous_table_array(env, result.size()); for (size_t i = 0; i < result.size(); i++) { n_result.set( - i, cudf::jni::contiguous_table_from(env, result[i].data, result[i].table.num_rows())); + i, cudf::jni::contiguous_table_from(env, result[i].data, result[i].table.num_rows())); } return n_result.wrapped(); } CATCH_STD(env, NULL); } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Table_makeChunkedPack(JNIEnv *env, jclass, - jlong input_table, - jlong bounce_buffer_size, - jlong memoryResourceHandle) { +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Table_makeChunkedPack( + JNIEnv* env, jclass, jlong input_table, jlong bounce_buffer_size, jlong memoryResourceHandle) +{ JNI_NULL_CHECK(env, input_table, "native handle is null", 0); try { cudf::jni::auto_set_device(env); - cudf::table_view *n_table = reinterpret_cast(input_table); + cudf::table_view* n_table = reinterpret_cast(input_table); // `temp_mr` is the memory resource that `cudf::chunked_pack` will use to create temporary // and scratch memory only. - auto temp_mr = memoryResourceHandle != 0 ? - reinterpret_cast(memoryResourceHandle) : - rmm::mr::get_current_device_resource(); + auto temp_mr = memoryResourceHandle != 0 + ? reinterpret_cast(memoryResourceHandle) + : rmm::mr::get_current_device_resource(); auto chunked_pack = cudf::chunked_pack::create(*n_table, bounce_buffer_size, temp_mr); return reinterpret_cast(chunked_pack.release()); } CATCH_STD(env, 0); } -JNIEXPORT jlongArray JNICALL Java_ai_rapids_cudf_Table_rollingWindowAggregate( - JNIEnv *env, jclass, jlong j_input_table, jintArray j_keys, jlongArray j_default_output, - jintArray j_aggregate_column_indices, jlongArray j_agg_instances, jintArray j_min_periods, - jintArray j_preceding, jintArray j_following, jbooleanArray j_unbounded_preceding, - jbooleanArray j_unbounded_following, jboolean ignore_null_keys) { - +JNIEXPORT jlongArray JNICALL +Java_ai_rapids_cudf_Table_rollingWindowAggregate(JNIEnv* env, + jclass, + jlong j_input_table, + jintArray j_keys, + jlongArray j_default_output, + jintArray j_aggregate_column_indices, + jlongArray j_agg_instances, + jintArray j_min_periods, + jintArray j_preceding, + jintArray j_following, + jbooleanArray j_unbounded_preceding, + jbooleanArray j_unbounded_following, + jboolean ignore_null_keys) +{ JNI_NULL_CHECK(env, j_input_table, "input table is null", NULL); JNI_NULL_CHECK(env, j_keys, "input keys are null", NULL); JNI_NULL_CHECK(env, j_aggregate_column_indices, "input aggregate_column_indices are null", NULL); @@ -3457,7 +4117,7 @@ JNIEXPORT jlongArray JNICALL Java_ai_rapids_cudf_Table_rollingWindowAggregate( using cudf::jni::valid_window_parameters; // Convert from j-types to native. - cudf::table_view *input_table{reinterpret_cast(j_input_table)}; + cudf::table_view* input_table{reinterpret_cast(j_input_table)}; cudf::jni::native_jintArray keys{env, j_keys}; cudf::jni::native_jintArray values{env, j_aggregate_column_indices}; cudf::jni::native_jpointerArray agg_instances(env, j_agg_instances); @@ -3469,37 +4129,47 @@ JNIEXPORT jlongArray JNICALL Java_ai_rapids_cudf_Table_rollingWindowAggregate( cudf::jni::native_jbooleanArray unbounded_following{env, j_unbounded_following}; if (not valid_window_parameters(values, agg_instances, min_periods, preceding, following)) { - JNI_THROW_NEW(env, cudf::jni::ILLEGAL_ARG_CLASS, + JNI_THROW_NEW(env, + cudf::jni::ILLEGAL_ARG_CLASS, "Number of aggregation columns must match number of agg ops, and window-specs", nullptr); } // Extract table-view. cudf::table_view groupby_keys{ - input_table->select(std::vector(keys.data(), keys.data() + keys.size()))}; + input_table->select(std::vector(keys.data(), keys.data() + keys.size()))}; std::vector> result_columns; for (int i(0); i < values.size(); ++i) { - cudf::rolling_aggregation *agg = dynamic_cast(agg_instances[i]); - JNI_ARG_CHECK(env, agg != nullptr, "aggregation is not an instance of rolling_aggregation", - nullptr); - - int agg_column_index = values[i]; - auto const preceding_window_bounds = unbounded_preceding[i] ? - cudf::window_bounds::unbounded() : - cudf::window_bounds::get(preceding[i]); - auto const following_window_bounds = unbounded_following[i] ? - cudf::window_bounds::unbounded() : - cudf::window_bounds::get(following[i]); + cudf::rolling_aggregation* agg = dynamic_cast(agg_instances[i]); + JNI_ARG_CHECK( + env, agg != nullptr, "aggregation is not an instance of rolling_aggregation", nullptr); + + int agg_column_index = values[i]; + auto const preceding_window_bounds = unbounded_preceding[i] + ? cudf::window_bounds::unbounded() + : cudf::window_bounds::get(preceding[i]); + auto const following_window_bounds = unbounded_following[i] + ? cudf::window_bounds::unbounded() + : cudf::window_bounds::get(following[i]); if (default_output[i] != nullptr) { - result_columns.emplace_back(cudf::grouped_rolling_window( - groupby_keys, input_table->column(agg_column_index), *default_output[i], - preceding_window_bounds, following_window_bounds, min_periods[i], *agg)); + result_columns.emplace_back( + cudf::grouped_rolling_window(groupby_keys, + input_table->column(agg_column_index), + *default_output[i], + preceding_window_bounds, + following_window_bounds, + min_periods[i], + *agg)); } else { - result_columns.emplace_back(cudf::grouped_rolling_window( - groupby_keys, input_table->column(agg_column_index), preceding_window_bounds, - following_window_bounds, min_periods[i], *agg)); + result_columns.emplace_back( + cudf::grouped_rolling_window(groupby_keys, + input_table->column(agg_column_index), + preceding_window_bounds, + following_window_bounds, + min_periods[i], + *agg)); } } @@ -3509,13 +4179,22 @@ JNIEXPORT jlongArray JNICALL Java_ai_rapids_cudf_Table_rollingWindowAggregate( CATCH_STD(env, NULL); } -JNIEXPORT jlongArray JNICALL Java_ai_rapids_cudf_Table_rangeRollingWindowAggregate( - JNIEnv *env, jclass, jlong j_input_table, jintArray j_keys, jintArray j_orderby_column_indices, - jbooleanArray j_is_orderby_ascending, jintArray j_aggregate_column_indices, - jlongArray j_agg_instances, jintArray j_min_periods, jlongArray j_preceding, - jlongArray j_following, jintArray j_preceding_extent, jintArray j_following_extent, - jboolean ignore_null_keys) { - +JNIEXPORT jlongArray JNICALL +Java_ai_rapids_cudf_Table_rangeRollingWindowAggregate(JNIEnv* env, + jclass, + jlong j_input_table, + jintArray j_keys, + jintArray j_orderby_column_indices, + jbooleanArray j_is_orderby_ascending, + jintArray j_aggregate_column_indices, + jlongArray j_agg_instances, + jintArray j_min_periods, + jlongArray j_preceding, + jlongArray j_following, + jintArray j_preceding_extent, + jintArray j_following_extent, + jboolean ignore_null_keys) +{ JNI_NULL_CHECK(env, j_input_table, "input table is null", NULL); JNI_NULL_CHECK(env, j_keys, "input keys are null", NULL); JNI_NULL_CHECK(env, j_orderby_column_indices, "input orderby_column_indices are null", NULL); @@ -3531,7 +4210,7 @@ JNIEXPORT jlongArray JNICALL Java_ai_rapids_cudf_Table_rangeRollingWindowAggrega using cudf::jni::valid_window_parameters; // Convert from j-types to native. - cudf::table_view *input_table{reinterpret_cast(j_input_table)}; + cudf::table_view* input_table{reinterpret_cast(j_input_table)}; cudf::jni::native_jintArray keys{env, j_keys}; cudf::jni::native_jintArray orderbys{env, j_orderby_column_indices}; cudf::jni::native_jbooleanArray orderbys_ascending{env, j_is_orderby_ascending}; @@ -3544,21 +4223,22 @@ JNIEXPORT jlongArray JNICALL Java_ai_rapids_cudf_Table_rangeRollingWindowAggrega cudf::jni::native_jpointerArray following(env, j_following); if (not valid_window_parameters(values, agg_instances, min_periods, preceding, following)) { - JNI_THROW_NEW(env, cudf::jni::ILLEGAL_ARG_CLASS, + JNI_THROW_NEW(env, + cudf::jni::ILLEGAL_ARG_CLASS, "Number of aggregation columns must match number of agg ops, and window-specs", nullptr); } // Extract table-view. cudf::table_view groupby_keys{ - input_table->select(std::vector(keys.data(), keys.data() + keys.size()))}; + input_table->select(std::vector(keys.data(), keys.data() + keys.size()))}; std::vector> result_columns; for (int i(0); i < values.size(); ++i) { - int agg_column_index = values[i]; - cudf::column_view const &order_by_column = input_table->column(orderbys[i]); - cudf::data_type order_by_type = order_by_column.type(); - cudf::data_type duration_type = order_by_type; + int agg_column_index = values[i]; + cudf::column_view const& order_by_column = input_table->column(orderbys[i]); + cudf::data_type order_by_type = order_by_column.type(); + cudf::data_type duration_type = order_by_type; // Range extents are defined as: // a) 0 == CURRENT ROW @@ -3566,8 +4246,8 @@ JNIEXPORT jlongArray JNICALL Java_ai_rapids_cudf_Table_rangeRollingWindowAggrega // c) 2 == UNBOUNDED // Must set unbounded_type for only the BOUNDED case. auto constexpr CURRENT_ROW = 0; - auto constexpr BOUNDED = 1; - auto constexpr UNBOUNDED = 2; + auto constexpr BOUNDED = 1; + auto constexpr UNBOUNDED = 2; if (preceding_extent[i] != BOUNDED || following_extent[i] != BOUNDED) { switch (order_by_type.id()) { case cudf::type_id::TIMESTAMP_DAYS: @@ -3589,11 +4269,11 @@ JNIEXPORT jlongArray JNICALL Java_ai_rapids_cudf_Table_rangeRollingWindowAggrega } } - cudf::rolling_aggregation *agg = dynamic_cast(agg_instances[i]); - JNI_ARG_CHECK(env, agg != nullptr, "aggregation is not an instance of rolling_aggregation", - nullptr); + cudf::rolling_aggregation* agg = dynamic_cast(agg_instances[i]); + JNI_ARG_CHECK( + env, agg != nullptr, "aggregation is not an instance of rolling_aggregation", nullptr); - auto const make_window_bounds = [&](auto const &range_extent, auto const *p_scalar) { + auto const make_window_bounds = [&](auto const& range_extent, auto const* p_scalar) { if (range_extent == CURRENT_ROW) { return cudf::range_window_bounds::current_row(duration_type); } else if (range_extent == UNBOUNDED) { @@ -3604,11 +4284,14 @@ JNIEXPORT jlongArray JNICALL Java_ai_rapids_cudf_Table_rangeRollingWindowAggrega }; result_columns.emplace_back(cudf::grouped_range_rolling_window( - groupby_keys, order_by_column, - orderbys_ascending[i] ? cudf::order::ASCENDING : cudf::order::DESCENDING, - input_table->column(agg_column_index), - make_window_bounds(preceding_extent[i], preceding[i]), - make_window_bounds(following_extent[i], following[i]), min_periods[i], *agg)); + groupby_keys, + order_by_column, + orderbys_ascending[i] ? cudf::order::ASCENDING : cudf::order::DESCENDING, + input_table->column(agg_column_index), + make_window_bounds(preceding_extent[i], preceding[i]), + make_window_bounds(following_extent[i], following[i]), + min_periods[i], + *agg)); } auto result_table = std::make_unique(std::move(result_columns)); @@ -3617,72 +4300,88 @@ JNIEXPORT jlongArray JNICALL Java_ai_rapids_cudf_Table_rangeRollingWindowAggrega CATCH_STD(env, NULL); } -JNIEXPORT jlongArray JNICALL Java_ai_rapids_cudf_Table_explode(JNIEnv *env, jclass, +JNIEXPORT jlongArray JNICALL Java_ai_rapids_cudf_Table_explode(JNIEnv* env, + jclass, jlong input_jtable, - jint column_index) { + jint column_index) +{ JNI_NULL_CHECK(env, input_jtable, "explode: input table is null", 0); try { cudf::jni::auto_set_device(env); - auto const input_table = reinterpret_cast(input_jtable); - auto const col_index = static_cast(column_index); + auto const input_table = reinterpret_cast(input_jtable); + auto const col_index = static_cast(column_index); return convert_table_for_return(env, cudf::explode(*input_table, col_index)); } CATCH_STD(env, 0); } -JNIEXPORT jlongArray JNICALL Java_ai_rapids_cudf_Table_explodePosition(JNIEnv *env, jclass, +JNIEXPORT jlongArray JNICALL Java_ai_rapids_cudf_Table_explodePosition(JNIEnv* env, + jclass, jlong input_jtable, - jint column_index) { + jint column_index) +{ JNI_NULL_CHECK(env, input_jtable, "explode: input table is null", 0); try { cudf::jni::auto_set_device(env); - auto const input_table = reinterpret_cast(input_jtable); - auto const col_index = static_cast(column_index); + auto const input_table = reinterpret_cast(input_jtable); + auto const col_index = static_cast(column_index); return convert_table_for_return(env, cudf::explode_position(*input_table, col_index)); } CATCH_STD(env, 0); } -JNIEXPORT jlongArray JNICALL Java_ai_rapids_cudf_Table_explodeOuter(JNIEnv *env, jclass, +JNIEXPORT jlongArray JNICALL Java_ai_rapids_cudf_Table_explodeOuter(JNIEnv* env, + jclass, jlong input_jtable, - jint column_index) { + jint column_index) +{ JNI_NULL_CHECK(env, input_jtable, "explode: input table is null", 0); try { cudf::jni::auto_set_device(env); - auto const input_table = reinterpret_cast(input_jtable); - auto const col_index = static_cast(column_index); + auto const input_table = reinterpret_cast(input_jtable); + auto const col_index = static_cast(column_index); return convert_table_for_return(env, cudf::explode_outer(*input_table, col_index)); } CATCH_STD(env, 0); } -JNIEXPORT jlongArray JNICALL Java_ai_rapids_cudf_Table_explodeOuterPosition(JNIEnv *env, jclass, +JNIEXPORT jlongArray JNICALL Java_ai_rapids_cudf_Table_explodeOuterPosition(JNIEnv* env, + jclass, jlong input_jtable, - jint column_index) { + jint column_index) +{ JNI_NULL_CHECK(env, input_jtable, "explode: input table is null", 0); try { cudf::jni::auto_set_device(env); - auto const input_table = reinterpret_cast(input_jtable); - auto const col_index = static_cast(column_index); + auto const input_table = reinterpret_cast(input_jtable); + auto const col_index = static_cast(column_index); return convert_table_for_return(env, cudf::explode_outer_position(*input_table, col_index)); } CATCH_STD(env, 0); } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Table_rowBitCount(JNIEnv *env, jclass, jlong j_table) { +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Table_rowBitCount(JNIEnv* env, jclass, jlong j_table) +{ JNI_NULL_CHECK(env, j_table, "table is null", 0); try { cudf::jni::auto_set_device(env); - auto const input_table = reinterpret_cast(j_table); + auto const input_table = reinterpret_cast(j_table); return release_as_jlong(cudf::row_bit_count(*input_table)); } CATCH_STD(env, 0); } -JNIEXPORT jobject JNICALL Java_ai_rapids_cudf_Table_contiguousSplitGroups( - JNIEnv *env, jclass, jlong jinput_table, jintArray jkey_indices, jboolean jignore_null_keys, - jboolean jkey_sorted, jbooleanArray jkeys_sort_desc, jbooleanArray jkeys_null_first, - jboolean genUniqKeys) { +JNIEXPORT jobject JNICALL +Java_ai_rapids_cudf_Table_contiguousSplitGroups(JNIEnv* env, + jclass, + jlong jinput_table, + jintArray jkey_indices, + jboolean jignore_null_keys, + jboolean jkey_sorted, + jbooleanArray jkeys_sort_desc, + jbooleanArray jkeys_null_first, + jboolean genUniqKeys) +{ JNI_NULL_CHECK(env, jinput_table, "table native handle is null", 0); JNI_NULL_CHECK(env, jkey_indices, "key indices are null", 0); // Two main steps to split the groups in the input table. @@ -3693,7 +4392,7 @@ JNIEXPORT jobject JNICALL Java_ai_rapids_cudf_Table_contiguousSplitGroups( try { cudf::jni::auto_set_device(env); cudf::jni::native_jintArray n_key_indices(env, jkey_indices); - auto const input_table = reinterpret_cast(jinput_table); + auto const input_table = reinterpret_cast(jinput_table); // Prepares arguments for the groupby: // (keys, null_handling, keys_are_sorted, column_order, null_precedence) @@ -3701,15 +4400,15 @@ JNIEXPORT jobject JNICALL Java_ai_rapids_cudf_Table_contiguousSplitGroups( n_key_indices.data() + n_key_indices.size()); auto keys = input_table->select(key_indices); auto null_handling = - jignore_null_keys ? cudf::null_policy::EXCLUDE : cudf::null_policy::INCLUDE; + jignore_null_keys ? cudf::null_policy::EXCLUDE : cudf::null_policy::INCLUDE; auto keys_are_sorted = jkey_sorted ? cudf::sorted::YES : cudf::sorted::NO; auto column_order = cudf::jni::resolve_column_order(env, jkeys_sort_desc, key_indices.size()); auto null_precedence = - cudf::jni::resolve_null_precedence(env, jkeys_null_first, key_indices.size()); + cudf::jni::resolve_null_precedence(env, jkeys_null_first, key_indices.size()); // Constructs a groupby - cudf::groupby::groupby grouper(keys, null_handling, keys_are_sorted, column_order, - null_precedence); + cudf::groupby::groupby grouper( + keys, null_handling, keys_are_sorted, column_order, null_precedence); // 1) Gets the groups(keys, offsets, values) from groupby. // @@ -3736,14 +4435,14 @@ JNIEXPORT jobject JNICALL Java_ai_rapids_cudf_Table_contiguousSplitGroups( // original order of columns (same order with that in input table). std::vector grouped_cols(key_indices.size() + num_value_cols); // key columns - auto key_view = groups.keys->view(); + auto key_view = groups.keys->view(); auto key_view_it = key_view.begin(); for (auto key_id : key_indices) { grouped_cols.at(key_id) = std::move(*key_view_it); key_view_it++; } // value columns - auto value_view = groups.values->view(); + auto value_view = groups.values->view(); auto value_view_it = value_view.begin(); for (auto value_id : value_indices) { grouped_cols.at(value_id) = std::move(*value_view_it); @@ -3752,11 +4451,11 @@ JNIEXPORT jobject JNICALL Java_ai_rapids_cudf_Table_contiguousSplitGroups( cudf::table_view grouped_table(grouped_cols); // When no key columns, uses the input table instead, because the output // of 'get_groups' is empty. - auto &grouped_view = key_indices.empty() ? *input_table : grouped_table; + auto& grouped_view = key_indices.empty() ? *input_table : grouped_table; // Resolves the split indices from offsets vector directly to avoid copying. Since // the offsets vector may be very large if there are too many small groups. - std::vector &split_indices = groups.offsets; + std::vector& split_indices = groups.offsets; // Offsets layout is [0, split indices..., num_rows] or [0] for empty keys, so // need to removes the first and last elements. First remove last one. split_indices.pop_back(); @@ -3765,23 +4464,21 @@ JNIEXPORT jobject JNICALL Java_ai_rapids_cudf_Table_contiguousSplitGroups( std::unique_ptr group_by_result_table; if (genUniqKeys) { // generate gather map column from `split_indices` - auto begin = std::cbegin(split_indices); - auto end = std::cend(split_indices); + auto begin = std::cbegin(split_indices); + auto end = std::cend(split_indices); auto const size = cudf::distance(begin, end); - auto const vec = thrust::host_vector(begin, end); - auto buf = rmm::device_buffer{vec.data(), size * sizeof(cudf::size_type), - cudf::get_default_stream()}; + auto const vec = thrust::host_vector(begin, end); + auto buf = + rmm::device_buffer{vec.data(), size * sizeof(cudf::size_type), cudf::get_default_stream()}; auto gather_map_col = std::make_unique( - cudf::data_type{cudf::type_id::INT32}, size, std::move(buf), rmm::device_buffer{}, 0); + cudf::data_type{cudf::type_id::INT32}, size, std::move(buf), rmm::device_buffer{}, 0); // gather the first key in each group to remove duplicated ones. group_by_result_table = cudf::gather(groups.keys->view(), gather_map_col->view()); } // remove the first 0 if it exists - if (!split_indices.empty()) { - split_indices.erase(split_indices.begin()); - } + if (!split_indices.empty()) { split_indices.erase(split_indices.begin()); } // 2) Splits the groups. std::vector result = cudf::contiguous_split(grouped_view, split_indices); @@ -3791,10 +4488,10 @@ JNIEXPORT jobject JNICALL Java_ai_rapids_cudf_Table_contiguousSplitGroups( // Returns the split result. cudf::jni::native_jobjectArray n_result = - cudf::jni::contiguous_table_array(env, result.size()); + cudf::jni::contiguous_table_array(env, result.size()); for (size_t i = 0; i < result.size(); i++) { n_result.set( - i, cudf::jni::contiguous_table_from(env, result[i].data, result[i].table.num_rows())); + i, cudf::jni::contiguous_table_from(env, result[i].data, result[i].table.num_rows())); } jobjectArray groups_array = n_result.wrapped(); @@ -3809,17 +4506,17 @@ JNIEXPORT jobject JNICALL Java_ai_rapids_cudf_Table_contiguousSplitGroups( CATCH_STD(env, NULL); } -JNIEXPORT jlongArray JNICALL Java_ai_rapids_cudf_Table_sample(JNIEnv *env, jclass, jlong j_input, - jlong n, jboolean replacement, - jlong seed) { +JNIEXPORT jlongArray JNICALL Java_ai_rapids_cudf_Table_sample( + JNIEnv* env, jclass, jlong j_input, jlong n, jboolean replacement, jlong seed) +{ JNI_NULL_CHECK(env, j_input, "input table is null", 0); try { cudf::jni::auto_set_device(env); - auto const input = reinterpret_cast(j_input); + auto const input = reinterpret_cast(j_input); auto sample_with_replacement = - replacement ? cudf::sample_with_replacement::TRUE : cudf::sample_with_replacement::FALSE; + replacement ? cudf::sample_with_replacement::TRUE : cudf::sample_with_replacement::FALSE; return convert_table_for_return(env, cudf::sample(*input, n, sample_with_replacement, seed)); } CATCH_STD(env, 0); } -} // extern "C" +} // extern "C" diff --git a/java/src/main/native/src/aggregation128_utils.cu b/java/src/main/native/src/aggregation128_utils.cu index d722aaa84fe..a32e7d27085 100644 --- a/java/src/main/native/src/aggregation128_utils.cu +++ b/java/src/main/native/src/aggregation128_utils.cu @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2023, NVIDIA CORPORATION. + * Copyright (c) 2022-2024, NVIDIA CORPORATION. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,118 +14,131 @@ * limitations under the License. */ -#include -#include -#include +#include "aggregation128_utils.hpp" -#include #include #include #include + #include + +#include #include #include #include -#include "aggregation128_utils.hpp" +#include +#include +#include namespace { // Functor to reassemble a 128-bit value from four 64-bit chunks with overflow detection. class chunk_assembler : public thrust::unary_function { -public: - chunk_assembler(bool *overflows, uint64_t const *chunks0, uint64_t const *chunks1, - uint64_t const *chunks2, int64_t const *chunks3) - : overflows(overflows), chunks0(chunks0), chunks1(chunks1), chunks2(chunks2), - chunks3(chunks3) {} + public: + chunk_assembler(bool* overflows, + uint64_t const* chunks0, + uint64_t const* chunks1, + uint64_t const* chunks2, + int64_t const* chunks3) + : overflows(overflows), chunks0(chunks0), chunks1(chunks1), chunks2(chunks2), chunks3(chunks3) + { + } - __device__ __int128_t operator()(cudf::size_type i) const { + __device__ __int128_t operator()(cudf::size_type i) const + { // Starting with the least significant input and moving to the most significant, propagate the // upper 32-bits of the previous column into the next column, i.e.: propagate the "carry" bits // of each 64-bit chunk into the next chunk. - uint64_t const c0 = chunks0[i]; - uint64_t const c1 = chunks1[i] + (c0 >> 32); - uint64_t const c2 = chunks2[i] + (c1 >> 32); - int64_t const c3 = chunks3[i] + (c2 >> 32); + uint64_t const c0 = chunks0[i]; + uint64_t const c1 = chunks1[i] + (c0 >> 32); + uint64_t const c2 = chunks2[i] + (c1 >> 32); + int64_t const c3 = chunks3[i] + (c2 >> 32); uint64_t const lower64 = (c1 << 32) | static_cast(c0); - int64_t const upper64 = (c3 << 32) | static_cast(c2); + int64_t const upper64 = (c3 << 32) | static_cast(c2); // check for overflow by ensuring the sign bit matches the top carry bits int32_t const replicated_sign_bit = static_cast(c3) >> 31; - int32_t const top_carry_bits = static_cast(c3 >> 32); - overflows[i] = (replicated_sign_bit != top_carry_bits); + int32_t const top_carry_bits = static_cast(c3 >> 32); + overflows[i] = (replicated_sign_bit != top_carry_bits); return (static_cast<__int128_t>(upper64) << 64) | lower64; } -private: + private: // output column for overflow detected - bool *const overflows; + bool* const overflows; // input columns for the four 64-bit values - uint64_t const *const chunks0; - uint64_t const *const chunks1; - uint64_t const *const chunks2; - int64_t const *const chunks3; + uint64_t const* const chunks0; + uint64_t const* const chunks1; + uint64_t const* const chunks2; + int64_t const* const chunks3; }; -} // anonymous namespace +} // anonymous namespace namespace cudf::jni { // Extract a 32-bit chunk from a 128-bit value. -std::unique_ptr extract_chunk32(cudf::column_view const &in_col, cudf::data_type type, - int chunk_idx, rmm::cuda_stream_view stream) { +std::unique_ptr extract_chunk32(cudf::column_view const& in_col, + cudf::data_type type, + int chunk_idx, + rmm::cuda_stream_view stream) +{ CUDF_EXPECTS(in_col.type().id() == cudf::type_id::DECIMAL128, "not a 128-bit type"); CUDF_EXPECTS(chunk_idx >= 0 && chunk_idx < 4, "invalid chunk index"); CUDF_EXPECTS(type.id() == cudf::type_id::INT32 || type.id() == cudf::type_id::UINT32, "not a 32-bit integer type"); auto const num_rows = in_col.size(); auto out_col = - cudf::make_fixed_width_column(type, num_rows, copy_bitmask(in_col), in_col.null_count()); - auto out_view = out_col->mutable_view(); + cudf::make_fixed_width_column(type, num_rows, copy_bitmask(in_col), in_col.null_count()); + auto out_view = out_col->mutable_view(); auto const in_begin = in_col.begin(); // Build an iterator for every fourth 32-bit value, i.e.: one "chunk" of a __int128_t value thrust::transform_iterator transform_iter{ - thrust::counting_iterator{0}, - cuda::proclaim_return_type([] __device__(auto i) { return i * 4; })}; + thrust::counting_iterator{0}, + cuda::proclaim_return_type([] __device__(auto i) { return i * 4; })}; thrust::permutation_iterator stride_iter{in_begin + chunk_idx, transform_iter}; - thrust::copy(rmm::exec_policy(stream), stride_iter, stride_iter + num_rows, - out_view.data()); + thrust::copy( + rmm::exec_policy(stream), stride_iter, stride_iter + num_rows, out_view.data()); return out_col; } // Reassemble a column of 128-bit values from four 64-bit integer columns with overflow detection. -std::unique_ptr assemble128_from_sum(cudf::table_view const &chunks_table, +std::unique_ptr assemble128_from_sum(cudf::table_view const& chunks_table, cudf::data_type output_type, - rmm::cuda_stream_view stream) { + rmm::cuda_stream_view stream) +{ CUDF_EXPECTS(output_type.id() == cudf::type_id::DECIMAL128, "not a 128-bit type"); CUDF_EXPECTS(chunks_table.num_columns() == 4, "must be 4 column table"); auto const num_rows = chunks_table.num_rows(); - auto const chunks0 = chunks_table.column(0); - auto const chunks1 = chunks_table.column(1); - auto const chunks2 = chunks_table.column(2); - auto const chunks3 = chunks_table.column(3); + auto const chunks0 = chunks_table.column(0); + auto const chunks1 = chunks_table.column(1); + auto const chunks2 = chunks_table.column(2); + auto const chunks3 = chunks_table.column(3); CUDF_EXPECTS(cudf::size_of(chunks0.type()) == 8 && cudf::size_of(chunks1.type()) == 8 && - cudf::size_of(chunks2.type()) == 8 && - chunks3.type().id() == cudf::type_id::INT64, + cudf::size_of(chunks2.type()) == 8 && chunks3.type().id() == cudf::type_id::INT64, "chunks type mismatch"); std::vector> columns; - columns.push_back(cudf::make_fixed_width_column(cudf::data_type{cudf::type_id::BOOL8}, num_rows, - copy_bitmask(chunks0), chunks0.null_count())); - columns.push_back(cudf::make_fixed_width_column(output_type, num_rows, copy_bitmask(chunks0), - chunks0.null_count())); + columns.push_back(cudf::make_fixed_width_column( + cudf::data_type{cudf::type_id::BOOL8}, num_rows, copy_bitmask(chunks0), chunks0.null_count())); + columns.push_back(cudf::make_fixed_width_column( + output_type, num_rows, copy_bitmask(chunks0), chunks0.null_count())); auto overflows_view = columns[0]->mutable_view(); auto assembled_view = columns[1]->mutable_view(); - thrust::transform(rmm::exec_policy(stream), thrust::make_counting_iterator(0), + thrust::transform(rmm::exec_policy(stream), + thrust::make_counting_iterator(0), thrust::make_counting_iterator(num_rows), assembled_view.begin<__int128_t>(), - chunk_assembler(overflows_view.begin(), chunks0.begin(), - chunks1.begin(), chunks2.begin(), + chunk_assembler(overflows_view.begin(), + chunks0.begin(), + chunks1.begin(), + chunks2.begin(), chunks3.begin())); return std::make_unique(std::move(columns)); } -} // namespace cudf::jni +} // namespace cudf::jni diff --git a/java/src/main/native/src/aggregation128_utils.hpp b/java/src/main/native/src/aggregation128_utils.hpp index a1437606cdf..94860cea53b 100644 --- a/java/src/main/native/src/aggregation128_utils.hpp +++ b/java/src/main/native/src/aggregation128_utils.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, NVIDIA CORPORATION. + * Copyright (c) 2022-2024, NVIDIA CORPORATION. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,13 +14,14 @@ * limitations under the License. */ -#include - #include #include #include + #include +#include + namespace cudf::jni { /** @@ -39,9 +40,11 @@ namespace cudf::jni { * @param stream CUDA stream to use * @return A column containing the extracted 32-bit integer values */ -std::unique_ptr -extract_chunk32(cudf::column_view const &col, cudf::data_type dtype, int chunk_idx, - rmm::cuda_stream_view stream = cudf::get_default_stream()); +std::unique_ptr extract_chunk32( + cudf::column_view const& col, + cudf::data_type dtype, + int chunk_idx, + rmm::cuda_stream_view stream = cudf::get_default_stream()); /** * @brief Reassemble a 128-bit column from four 64-bit integer columns with overflow detection. @@ -63,8 +66,9 @@ extract_chunk32(cudf::column_view const &col, cudf::data_type dtype, int chunk_i * requested type. The boolean value will be true if an overflow was detected * for that row's value. */ -std::unique_ptr -assemble128_from_sum(cudf::table_view const &chunks_table, cudf::data_type output_type, - rmm::cuda_stream_view stream = cudf::get_default_stream()); +std::unique_ptr assemble128_from_sum( + cudf::table_view const& chunks_table, + cudf::data_type output_type, + rmm::cuda_stream_view stream = cudf::get_default_stream()); -} // namespace cudf::jni +} // namespace cudf::jni diff --git a/java/src/main/native/src/check_nvcomp_output_sizes.cu b/java/src/main/native/src/check_nvcomp_output_sizes.cu index 9d29e66ec59..8e0df7dd89a 100644 --- a/java/src/main/native/src/check_nvcomp_output_sizes.cu +++ b/java/src/main/native/src/check_nvcomp_output_sizes.cu @@ -13,20 +13,21 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +#include "check_nvcomp_output_sizes.hpp" + #include + #include #include #include -#include "check_nvcomp_output_sizes.hpp" - namespace { struct java_domain { - static constexpr char const *name{"Java"}; + static constexpr char const* name{"Java"}; }; -} // anonymous namespace +} // anonymous namespace namespace cudf { namespace java { @@ -35,13 +36,17 @@ namespace java { * Check that the vector of expected uncompressed sizes matches the vector of actual compressed * sizes. Both vectors are assumed to be in device memory and contain num_chunks elements. */ -bool check_nvcomp_output_sizes(std::size_t const *dev_uncompressed_sizes, - std::size_t const *dev_actual_uncompressed_sizes, - std::size_t num_chunks, rmm::cuda_stream_view stream) { +bool check_nvcomp_output_sizes(std::size_t const* dev_uncompressed_sizes, + std::size_t const* dev_actual_uncompressed_sizes, + std::size_t num_chunks, + rmm::cuda_stream_view stream) +{ NVTX3_FUNC_RANGE_IN(java_domain); - return thrust::equal(rmm::exec_policy(stream), dev_uncompressed_sizes, - dev_uncompressed_sizes + num_chunks, dev_actual_uncompressed_sizes); + return thrust::equal(rmm::exec_policy(stream), + dev_uncompressed_sizes, + dev_uncompressed_sizes + num_chunks, + dev_actual_uncompressed_sizes); } -} // namespace java -} // namespace cudf +} // namespace java +} // namespace cudf diff --git a/java/src/main/native/src/check_nvcomp_output_sizes.hpp b/java/src/main/native/src/check_nvcomp_output_sizes.hpp index 00b36471a85..594be6c7c96 100644 --- a/java/src/main/native/src/check_nvcomp_output_sizes.hpp +++ b/java/src/main/native/src/check_nvcomp_output_sizes.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, NVIDIA CORPORATION. + * Copyright (c) 2021-2024, NVIDIA CORPORATION. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -26,8 +26,9 @@ namespace java { * Check that the vector of expected uncompressed sizes matches the vector of actual compressed * sizes. Both vectors are assumed to be in device memory and contain num_chunks elements. */ -bool check_nvcomp_output_sizes(std::size_t const *dev_uncompressed_sizes, - std::size_t const *dev_actual_uncompressed_sizes, - std::size_t num_chunks, rmm::cuda_stream_view stream); -} // namespace java -} // namespace cudf +bool check_nvcomp_output_sizes(std::size_t const* dev_uncompressed_sizes, + std::size_t const* dev_actual_uncompressed_sizes, + std::size_t num_chunks, + rmm::cuda_stream_view stream); +} // namespace java +} // namespace cudf diff --git a/java/src/main/native/src/csv_chunked_writer.hpp b/java/src/main/native/src/csv_chunked_writer.hpp index 1f1e73a1a4b..ee05aa95328 100644 --- a/java/src/main/native/src/csv_chunked_writer.hpp +++ b/java/src/main/native/src/csv_chunked_writer.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023, NVIDIA CORPORATION. + * Copyright (c) 2023-2024, NVIDIA CORPORATION. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,11 +15,11 @@ */ #pragma once -#include +#include "jni_writer_data_sink.hpp" #include -#include "jni_writer_data_sink.hpp" +#include namespace cudf::jni::io { @@ -27,17 +27,17 @@ namespace cudf::jni::io { * @brief Class to write multiple Tables into the jni_writer_data_sink. */ class csv_chunked_writer { - cudf::io::csv_writer_options _options; std::unique_ptr _sink; - bool _first_write_completed = false; ///< Decides if header should be written. + bool _first_write_completed = false; ///< Decides if header should be written. -public: + public: explicit csv_chunked_writer(cudf::io::csv_writer_options options, - std::unique_ptr &sink) - : _options{options}, _sink{std::move(sink)} { - auto const &sink_info = _options.get_sink(); + std::unique_ptr& sink) + : _options{options}, _sink{std::move(sink)} + { + auto const& sink_info = _options.get_sink(); // Assert invariants. CUDF_EXPECTS(sink_info.type() != cudf::io::io_type::FILEPATH, "Currently, chunked CSV writes to files is not supported."); @@ -52,9 +52,10 @@ class csv_chunked_writer { CUDF_EXPECTS(sink_info.user_sinks()[0] == _sink.get(), "Sink mismatch."); } - void write(cudf::table_view const &table) { + void write(cudf::table_view const& table) + { if (_first_write_completed) { - _options.enable_include_header(false); // Don't write header after the first write. + _options.enable_include_header(false); // Don't write header after the first write. } _options.set_table(table); @@ -64,10 +65,11 @@ class csv_chunked_writer { _first_write_completed = true; } - void close() { + void close() + { // Flush pending writes to sink. _sink->flush(); } }; -} // namespace cudf::jni::io +} // namespace cudf::jni::io diff --git a/java/src/main/native/src/cudf_jni_apis.hpp b/java/src/main/native/src/cudf_jni_apis.hpp index bd82bbd2899..022493f04ab 100644 --- a/java/src/main/native/src/cudf_jni_apis.hpp +++ b/java/src/main/native/src/cudf_jni_apis.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019-2023, NVIDIA CORPORATION. + * Copyright (c) 2019-2024, NVIDIA CORPORATION. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,11 +15,11 @@ */ #pragma once +#include "jni_utils.hpp" + #include #include -#include "jni_utils.hpp" - namespace cudf { namespace jni { @@ -34,29 +34,31 @@ namespace jni { * @param table_result the table to convert for return * @param extra_columns columns not in the table that will be appended to the result. */ -jlongArray -convert_table_for_return(JNIEnv *env, std::unique_ptr &table_result, - std::vector> &&extra_columns = {}); +jlongArray convert_table_for_return( + JNIEnv* env, + std::unique_ptr& table_result, + std::vector>&& extra_columns = {}); /** * @copydoc convert_table_for_return(JNIEnv*, std::unique_ptr&, * std::vector>&&) */ -jlongArray -convert_table_for_return(JNIEnv *env, std::unique_ptr &&table_result, - std::vector> &&extra_columns = {}); +jlongArray convert_table_for_return( + JNIEnv* env, + std::unique_ptr&& table_result, + std::vector>&& extra_columns = {}); // // ContiguousTable APIs // -bool cache_contiguous_table_jni(JNIEnv *env); +bool cache_contiguous_table_jni(JNIEnv* env); -void release_contiguous_table_jni(JNIEnv *env); +void release_contiguous_table_jni(JNIEnv* env); -jobject contiguous_table_from(JNIEnv *env, cudf::packed_columns &split, long row_count); +jobject contiguous_table_from(JNIEnv* env, cudf::packed_columns& split, long row_count); -native_jobjectArray contiguous_table_array(JNIEnv *env, jsize length); +native_jobjectArray contiguous_table_array(JNIEnv* env, jsize length); /** * @brief Cache the JNI jclass and JNI jfield of Java `ContigSplitGroupByResult` @@ -64,14 +66,14 @@ native_jobjectArray contiguous_table_array(JNIEnv *env, jsize length); * @param env the JNI Env pointer * @return if success */ -bool cache_contig_split_group_by_result_jni(JNIEnv *env); +bool cache_contig_split_group_by_result_jni(JNIEnv* env); /** * @brief Release the JNI jclass and JNI jfield of Java `ContigSplitGroupByResult` * * @param env the JNI Env pointer */ -void release_contig_split_group_by_result_jni(JNIEnv *env); +void release_contig_split_group_by_result_jni(JNIEnv* env); /** * @brief Construct a Java `ContigSplitGroupByResult` from contiguous tables. @@ -80,7 +82,7 @@ void release_contig_split_group_by_result_jni(JNIEnv *env); * @param groups the contiguous tables * @return a Java `ContigSplitGroupByResult` */ -jobject contig_split_group_by_result_from(JNIEnv *env, jobjectArray &groups); +jobject contig_split_group_by_result_from(JNIEnv* env, jobjectArray& groups); /** * @brief Construct a Java `ContigSplitGroupByResult` from contiguous tables. @@ -90,8 +92,9 @@ jobject contig_split_group_by_result_from(JNIEnv *env, jobjectArray &groups); * @param groups the contiguous tables * @return a Java `ContigSplitGroupByResult` */ -jobject contig_split_group_by_result_from(JNIEnv *env, jobjectArray &groups, - jlongArray &uniq_key_columns); +jobject contig_split_group_by_result_from(JNIEnv* env, + jobjectArray& groups, + jlongArray& uniq_key_columns); // // HostMemoryBuffer APIs @@ -100,22 +103,24 @@ jobject contig_split_group_by_result_from(JNIEnv *env, jobjectArray &groups, /** * Allocate a HostMemoryBuffer */ -jobject allocate_host_buffer(JNIEnv *env, jlong amount, jboolean prefer_pinned, +jobject allocate_host_buffer(JNIEnv* env, + jlong amount, + jboolean prefer_pinned, jobject host_memory_allocator); /** * Get the address of a HostMemoryBuffer */ -jlong get_host_buffer_address(JNIEnv *env, jobject buffer); +jlong get_host_buffer_address(JNIEnv* env, jobject buffer); /** * Get the length of a HostMemoryBuffer */ -jlong get_host_buffer_length(JNIEnv *env, jobject buffer); +jlong get_host_buffer_length(JNIEnv* env, jobject buffer); // Get the JNI environment, attaching the current thread to the JVM if necessary. If the thread // needs to be attached, the thread will automatically detach when the thread terminates. -JNIEnv *get_jni_env(JavaVM *jvm); +JNIEnv* get_jni_env(JavaVM* jvm); /** Set the device to use for cudf */ void set_cudf_device(int device); @@ -125,22 +130,22 @@ void set_cudf_device(int device); * set the device, throw an exception, or do nothing depending on how the application has * configured it via Cuda.setAutoSetDeviceMode. */ -void auto_set_device(JNIEnv *env); +void auto_set_device(JNIEnv* env); /** * Fills all the bytes in the buffer 'buf' with 'value'. * The operation has not necessarily completed when this returns, but it could overlap with * operations occurring on other streams. */ -void device_memset_async(JNIEnv *env, rmm::device_buffer &buf, char value); +void device_memset_async(JNIEnv* env, rmm::device_buffer& buf, char value); // // DataSource APIs // -bool cache_data_source_jni(JNIEnv *env); +bool cache_data_source_jni(JNIEnv* env); -void release_data_source_jni(JNIEnv *env); +void release_data_source_jni(JNIEnv* env); -} // namespace jni -} // namespace cudf +} // namespace jni +} // namespace cudf diff --git a/java/src/main/native/src/dtype_utils.hpp b/java/src/main/native/src/dtype_utils.hpp index 4de8a94182c..90408782dd0 100644 --- a/java/src/main/native/src/dtype_utils.hpp +++ b/java/src/main/native/src/dtype_utils.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020-2022, NVIDIA CORPORATION. + * Copyright (c) 2020-2024, NVIDIA CORPORATION. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,15 +15,16 @@ */ #pragma once -#include - #include +#include + namespace cudf { namespace jni { // convert a timestamp type to the corresponding duration type -inline cudf::data_type timestamp_to_duration(cudf::data_type dt) { +inline cudf::data_type timestamp_to_duration(cudf::data_type dt) +{ cudf::type_id duration_type_id; switch (dt.id()) { case cudf::type_id::TIMESTAMP_DAYS: duration_type_id = cudf::type_id::DURATION_DAYS; break; @@ -44,13 +45,15 @@ inline cudf::data_type timestamp_to_duration(cudf::data_type dt) { return cudf::data_type(duration_type_id); } -inline bool is_decimal_type(cudf::type_id n_type) { +inline bool is_decimal_type(cudf::type_id n_type) +{ return n_type == cudf::type_id::DECIMAL32 || n_type == cudf::type_id::DECIMAL64 || n_type == cudf::type_id::DECIMAL128; } // create data_type including scale for decimal type -inline cudf::data_type make_data_type(jint out_dtype, jint scale) { +inline cudf::data_type make_data_type(jint out_dtype, jint scale) +{ cudf::type_id n_type = static_cast(out_dtype); cudf::data_type n_data_type; if (is_decimal_type(n_type)) { @@ -61,5 +64,5 @@ inline cudf::data_type make_data_type(jint out_dtype, jint scale) { return n_data_type; } -} // namespace jni -} // namespace cudf +} // namespace jni +} // namespace cudf diff --git a/java/src/main/native/src/jni_compiled_expr.hpp b/java/src/main/native/src/jni_compiled_expr.hpp index 74010f71011..dad2c33b731 100644 --- a/java/src/main/native/src/jni_compiled_expr.hpp +++ b/java/src/main/native/src/jni_compiled_expr.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, NVIDIA CORPORATION. + * Copyright (c) 2021-2024, NVIDIA CORPORATION. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,6 +16,11 @@ #pragma once +#include +#include + +#include +#include #include namespace cudf { @@ -38,29 +43,31 @@ class compiled_expr { /** GPU scalar instances that correspond to literal nodes */ std::vector> scalars; -public: - cudf::ast::literal &add_literal(std::unique_ptr literal_ptr, - std::unique_ptr scalar_ptr) { + public: + cudf::ast::literal& add_literal(std::unique_ptr literal_ptr, + std::unique_ptr scalar_ptr) + { expressions.push_back(std::move(literal_ptr)); scalars.push_back(std::move(scalar_ptr)); - return static_cast(*expressions.back()); + return static_cast(*expressions.back()); } - cudf::ast::column_reference & - add_column_ref(std::unique_ptr ref_ptr) { + cudf::ast::column_reference& add_column_ref(std::unique_ptr ref_ptr) + { expressions.push_back(std::move(ref_ptr)); - return static_cast(*expressions.back()); + return static_cast(*expressions.back()); } - cudf::ast::operation &add_operation(std::unique_ptr expr_ptr) { + cudf::ast::operation& add_operation(std::unique_ptr expr_ptr) + { expressions.push_back(std::move(expr_ptr)); - return static_cast(*expressions.back()); + return static_cast(*expressions.back()); } /** Return the expression node at the top of the tree */ - cudf::ast::expression &get_top_expression() const { return *expressions.back(); } + cudf::ast::expression& get_top_expression() const { return *expressions.back(); } }; -} // namespace ast -} // namespace jni -} // namespace cudf +} // namespace ast +} // namespace jni +} // namespace cudf diff --git a/java/src/main/native/src/jni_writer_data_sink.hpp b/java/src/main/native/src/jni_writer_data_sink.hpp index efac6112c25..52756266beb 100644 --- a/java/src/main/native/src/jni_writer_data_sink.hpp +++ b/java/src/main/native/src/jni_writer_data_sink.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023, NVIDIA CORPORATION. + * Copyright (c) 2023-2024, NVIDIA CORPORATION. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,56 +15,53 @@ */ #pragma once -#include - #include "cudf_jni_apis.hpp" #include "jni_utils.hpp" +#include + namespace cudf::jni { -constexpr long MINIMUM_WRITE_BUFFER_SIZE = 10 * 1024 * 1024; // 10 MB +constexpr long MINIMUM_WRITE_BUFFER_SIZE = 10 * 1024 * 1024; // 10 MB class jni_writer_data_sink final : public cudf::io::data_sink { -public: - explicit jni_writer_data_sink(JNIEnv *env, jobject callback, jobject host_memory_allocator) { - if (env->GetJavaVM(&jvm) < 0) { - throw std::runtime_error("GetJavaVM failed"); - } + public: + explicit jni_writer_data_sink(JNIEnv* env, jobject callback, jobject host_memory_allocator) + { + if (env->GetJavaVM(&jvm) < 0) { throw std::runtime_error("GetJavaVM failed"); } jclass cls = env->GetObjectClass(callback); - if (cls == nullptr) { - throw cudf::jni::jni_exception("class not found"); - } + if (cls == nullptr) { throw cudf::jni::jni_exception("class not found"); } handle_buffer_method = - env->GetMethodID(cls, "handleBuffer", "(Lai/rapids/cudf/HostMemoryBuffer;J)V"); - if (handle_buffer_method == nullptr) { - throw cudf::jni::jni_exception("handleBuffer method"); - } + env->GetMethodID(cls, "handleBuffer", "(Lai/rapids/cudf/HostMemoryBuffer;J)V"); + if (handle_buffer_method == nullptr) { throw cudf::jni::jni_exception("handleBuffer method"); } - this->callback = add_global_ref(env, callback); + this->callback = add_global_ref(env, callback); this->host_memory_allocator = add_global_ref(env, host_memory_allocator); } - virtual ~jni_writer_data_sink() { + virtual ~jni_writer_data_sink() + { // This should normally be called by a JVM thread. If the JVM environment is missing then this // is likely being triggered by the C++ runtime during shutdown. In that case the JVM may // already be destroyed and this thread should not try to attach to get an environment. - JNIEnv *env = nullptr; - if (jvm->GetEnv(reinterpret_cast(&env), cudf::jni::MINIMUM_JNI_VERSION) == JNI_OK) { - callback = del_global_ref(env, callback); - current_buffer = del_global_ref(env, current_buffer); + JNIEnv* env = nullptr; + if (jvm->GetEnv(reinterpret_cast(&env), cudf::jni::MINIMUM_JNI_VERSION) == JNI_OK) { + callback = del_global_ref(env, callback); + current_buffer = del_global_ref(env, current_buffer); host_memory_allocator = del_global_ref(env, host_memory_allocator); } - callback = nullptr; - current_buffer = nullptr; + callback = nullptr; + current_buffer = nullptr; host_memory_allocator = nullptr; } - void host_write(void const *data, size_t size) override { - JNIEnv *env = cudf::jni::get_jni_env(jvm); - long left_to_copy = static_cast(size); - const char *copy_from = static_cast(data); + void host_write(void const* data, size_t size) override + { + JNIEnv* env = cudf::jni::get_jni_env(jvm); + long left_to_copy = static_cast(size); + const char* copy_from = static_cast(data); while (left_to_copy > 0) { long buffer_amount_available = current_buffer_len - current_buffer_written; if (buffer_amount_available <= 0) { @@ -73,8 +70,8 @@ class jni_writer_data_sink final : public cudf::io::data_sink { buffer_amount_available = current_buffer_len - current_buffer_written; } long amount_to_copy = - left_to_copy < buffer_amount_available ? left_to_copy : buffer_amount_available; - char *copy_to = current_buffer_data + current_buffer_written; + left_to_copy < buffer_amount_available ? left_to_copy : buffer_amount_available; + char* copy_to = current_buffer_data + current_buffer_written; std::memcpy(copy_to, copy_from, amount_to_copy); copy_from = copy_from + amount_to_copy; @@ -86,10 +83,11 @@ class jni_writer_data_sink final : public cudf::io::data_sink { bool supports_device_write() const override { return true; } - void device_write(void const *gpu_data, size_t size, rmm::cuda_stream_view stream) override { - JNIEnv *env = cudf::jni::get_jni_env(jvm); - long left_to_copy = static_cast(size); - const char *copy_from = static_cast(gpu_data); + void device_write(void const* gpu_data, size_t size, rmm::cuda_stream_view stream) override + { + JNIEnv* env = cudf::jni::get_jni_env(jvm); + long left_to_copy = static_cast(size); + const char* copy_from = static_cast(gpu_data); while (left_to_copy > 0) { long buffer_amount_available = current_buffer_len - current_buffer_written; if (buffer_amount_available <= 0) { @@ -99,11 +97,11 @@ class jni_writer_data_sink final : public cudf::io::data_sink { buffer_amount_available = current_buffer_len - current_buffer_written; } long amount_to_copy = - left_to_copy < buffer_amount_available ? left_to_copy : buffer_amount_available; - char *copy_to = current_buffer_data + current_buffer_written; + left_to_copy < buffer_amount_available ? left_to_copy : buffer_amount_available; + char* copy_to = current_buffer_data + current_buffer_written; - CUDF_CUDA_TRY(cudaMemcpyAsync(copy_to, copy_from, amount_to_copy, cudaMemcpyDeviceToHost, - stream.value())); + CUDF_CUDA_TRY(cudaMemcpyAsync( + copy_to, copy_from, amount_to_copy, cudaMemcpyDeviceToHost, stream.value())); copy_from = copy_from + amount_to_copy; current_buffer_written += amount_to_copy; @@ -113,20 +111,23 @@ class jni_writer_data_sink final : public cudf::io::data_sink { stream.synchronize(); } - std::future device_write_async(void const *gpu_data, size_t size, - rmm::cuda_stream_view stream) override { + std::future device_write_async(void const* gpu_data, + size_t size, + rmm::cuda_stream_view stream) override + { // Call the sync version until figuring out how to write asynchronously. device_write(gpu_data, size, stream); return std::async(std::launch::deferred, [] {}); } - void flush() override { + void flush() override + { if (current_buffer_written > 0) { - JNIEnv *env = cudf::jni::get_jni_env(jvm); + JNIEnv* env = cudf::jni::get_jni_env(jvm); handle_buffer(env, current_buffer, current_buffer_written); - current_buffer = del_global_ref(env, current_buffer); - current_buffer_len = 0; - current_buffer_data = nullptr; + current_buffer = del_global_ref(env, current_buffer); + current_buffer_len = 0; + current_buffer_data = nullptr; current_buffer_written = 0; } } @@ -135,36 +136,34 @@ class jni_writer_data_sink final : public cudf::io::data_sink { void set_alloc_size(long size) { this->alloc_size = size; } -private: - void rotate_buffer(JNIEnv *env) { - if (current_buffer != nullptr) { - handle_buffer(env, current_buffer, current_buffer_written); - } - current_buffer = del_global_ref(env, current_buffer); - jobject tmp_buffer = allocate_host_buffer(env, alloc_size, true, host_memory_allocator); - current_buffer = add_global_ref(env, tmp_buffer); - current_buffer_len = get_host_buffer_length(env, current_buffer); - current_buffer_data = reinterpret_cast(get_host_buffer_address(env, current_buffer)); + private: + void rotate_buffer(JNIEnv* env) + { + if (current_buffer != nullptr) { handle_buffer(env, current_buffer, current_buffer_written); } + current_buffer = del_global_ref(env, current_buffer); + jobject tmp_buffer = allocate_host_buffer(env, alloc_size, true, host_memory_allocator); + current_buffer = add_global_ref(env, tmp_buffer); + current_buffer_len = get_host_buffer_length(env, current_buffer); + current_buffer_data = reinterpret_cast(get_host_buffer_address(env, current_buffer)); current_buffer_written = 0; } - void handle_buffer(JNIEnv *env, jobject buffer, jlong len) { + void handle_buffer(JNIEnv* env, jobject buffer, jlong len) + { env->CallVoidMethod(callback, handle_buffer_method, buffer, len); - if (env->ExceptionCheck()) { - throw std::runtime_error("handleBuffer threw an exception"); - } + if (env->ExceptionCheck()) { throw std::runtime_error("handleBuffer threw an exception"); } } - JavaVM *jvm; + JavaVM* jvm; jobject callback; jmethodID handle_buffer_method; - jobject current_buffer = nullptr; - char *current_buffer_data = nullptr; - long current_buffer_len = 0; + jobject current_buffer = nullptr; + char* current_buffer_data = nullptr; + long current_buffer_len = 0; long current_buffer_written = 0; - size_t total_written = 0; - long alloc_size = MINIMUM_WRITE_BUFFER_SIZE; + size_t total_written = 0; + long alloc_size = MINIMUM_WRITE_BUFFER_SIZE; jobject host_memory_allocator; }; -} // namespace cudf::jni +} // namespace cudf::jni diff --git a/java/src/main/native/src/maps_column_view.cu b/java/src/main/native/src/maps_column_view.cu index d5600e48a5c..d3ee52c074c 100644 --- a/java/src/main/native/src/maps_column_view.cu +++ b/java/src/main/native/src/maps_column_view.cu @@ -18,14 +18,17 @@ #include #include #include -#include + #include #include +#include + namespace cudf::jni { namespace { -column_view make_lists(column_view const &lists_child, lists_column_view const &lists_of_structs) { +column_view make_lists(column_view const& lists_child, lists_column_view const& lists_of_structs) +{ return column_view{data_type{type_id::LIST}, lists_of_structs.size(), nullptr, @@ -34,12 +37,13 @@ column_view make_lists(column_view const &lists_child, lists_column_view const & lists_of_structs.offset(), {lists_of_structs.offsets(), lists_child}}; } -} // namespace +} // namespace -maps_column_view::maps_column_view(lists_column_view const &lists_of_structs, +maps_column_view::maps_column_view(lists_column_view const& lists_of_structs, rmm::cuda_stream_view stream) - : keys_{make_lists(lists_of_structs.child().child(0), lists_of_structs)}, - values_{make_lists(lists_of_structs.child().child(1), lists_of_structs)} { + : keys_{make_lists(lists_of_structs.child().child(0), lists_of_structs)}, + values_{make_lists(lists_of_structs.child().child(1), lists_of_structs)} +{ auto const structs = lists_of_structs.child(); CUDF_EXPECTS(structs.type().id() == type_id::STRUCT, "maps_column_view input must have exactly 1 child (STRUCT) column."); @@ -48,66 +52,78 @@ maps_column_view::maps_column_view(lists_column_view const &lists_of_structs, } template -std::unique_ptr get_values_for_impl(maps_column_view const &maps_view, - KeyT const &lookup_keys, rmm::cuda_stream_view stream, - rmm::device_async_resource_ref mr) { - auto const keys_ = maps_view.keys(); +std::unique_ptr get_values_for_impl(maps_column_view const& maps_view, + KeyT const& lookup_keys, + rmm::cuda_stream_view stream, + rmm::device_async_resource_ref mr) +{ + auto const keys_ = maps_view.keys(); auto const values_ = maps_view.values(); CUDF_EXPECTS(lookup_keys.type().id() == keys_.child().type().id(), "Lookup keys must have the same type as the keys of the map column."); - auto key_indices = - lists::detail::index_of(keys_, lookup_keys, lists::duplicate_find_option::FIND_LAST, stream, - rmm::mr::get_current_device_resource()); - auto constexpr absent_offset = size_type{-1}; + auto key_indices = lists::detail::index_of(keys_, + lookup_keys, + lists::duplicate_find_option::FIND_LAST, + stream, + rmm::mr::get_current_device_resource()); + auto constexpr absent_offset = size_type{-1}; auto constexpr nullity_offset = std::numeric_limits::min(); - thrust::replace(rmm::exec_policy(stream), key_indices->mutable_view().template begin(), - key_indices->mutable_view().template end(), absent_offset, + thrust::replace(rmm::exec_policy(stream), + key_indices->mutable_view().template begin(), + key_indices->mutable_view().template end(), + absent_offset, nullity_offset); return lists::detail::extract_list_element(values_, key_indices->view(), stream, mr); } -std::unique_ptr maps_column_view::get_values_for(column_view const &lookup_keys, +std::unique_ptr maps_column_view::get_values_for(column_view const& lookup_keys, rmm::cuda_stream_view stream, - rmm::device_async_resource_ref mr) const { + rmm::device_async_resource_ref mr) const +{ CUDF_EXPECTS(lookup_keys.size() == size(), "Lookup keys must have the same size as the map column."); return get_values_for_impl(*this, lookup_keys, stream, mr); } -std::unique_ptr maps_column_view::get_values_for(scalar const &lookup_key, +std::unique_ptr maps_column_view::get_values_for(scalar const& lookup_key, rmm::cuda_stream_view stream, - rmm::device_async_resource_ref mr) const { + rmm::device_async_resource_ref mr) const +{ return get_values_for_impl(*this, lookup_key, stream, mr); } template -std::unique_ptr contains_impl(maps_column_view const &maps_view, KeyT const &lookup_keys, +std::unique_ptr contains_impl(maps_column_view const& maps_view, + KeyT const& lookup_keys, rmm::cuda_stream_view stream, - rmm::device_async_resource_ref mr) { + rmm::device_async_resource_ref mr) +{ auto const keys = maps_view.keys(); CUDF_EXPECTS(lookup_keys.type().id() == keys.child().type().id(), "Lookup keys must have the same type as the keys of the map column."); auto const contains = - lists::detail::contains(keys, lookup_keys, stream, rmm::mr::get_current_device_resource()); + lists::detail::contains(keys, lookup_keys, stream, rmm::mr::get_current_device_resource()); // Replace nulls with BOOL8{false}; auto const scalar_false = numeric_scalar{false, true, stream}; return detail::replace_nulls(contains->view(), scalar_false, stream, mr); } -std::unique_ptr maps_column_view::contains(column_view const &lookup_keys, +std::unique_ptr maps_column_view::contains(column_view const& lookup_keys, rmm::cuda_stream_view stream, - rmm::device_async_resource_ref mr) const { + rmm::device_async_resource_ref mr) const +{ CUDF_EXPECTS(lookup_keys.size() == size(), "Lookup keys must have the same size as the map column."); return contains_impl(*this, lookup_keys, stream, mr); } -std::unique_ptr maps_column_view::contains(scalar const &lookup_key, +std::unique_ptr maps_column_view::contains(scalar const& lookup_key, rmm::cuda_stream_view stream, - rmm::device_async_resource_ref mr) const { + rmm::device_async_resource_ref mr) const +{ return contains_impl(*this, lookup_key, stream, mr); } -} // namespace cudf::jni +} // namespace cudf::jni diff --git a/java/src/main/native/src/nvtx_common.hpp b/java/src/main/native/src/nvtx_common.hpp index 8b5b04f3370..69bcdfb8521 100644 --- a/java/src/main/native/src/nvtx_common.hpp +++ b/java/src/main/native/src/nvtx_common.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, NVIDIA CORPORATION. + * Copyright (c) 2021-2024, NVIDIA CORPORATION. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,8 +20,8 @@ namespace cudf { namespace jni { struct java_domain { - static constexpr char const *name{"Java"}; + static constexpr char const* name{"Java"}; }; -} // namespace jni -} // namespace cudf +} // namespace jni +} // namespace cudf