diff --git a/cpp/include/cudf/detail/copy_if_else.cuh b/cpp/include/cudf/detail/copy_if_else.cuh index 3faba5ef51b..1acdcadaacf 100644 --- a/cpp/include/cudf/detail/copy_if_else.cuh +++ b/cpp/include/cudf/detail/copy_if_else.cuh @@ -190,7 +190,7 @@ std::unique_ptr copy_if_else( <<>>( lhs_begin, rhs, filter, *out_v, valid_count.data()); - out->set_null_count(size - valid_count.value()); + out->set_null_count(size - valid_count.value(stream)); } else { // call the kernel copy_if_else_kernel diff --git a/cpp/include/cudf/detail/copy_range.cuh b/cpp/include/cudf/detail/copy_range.cuh index b7479f828ec..ac59b429a2c 100644 --- a/cpp/include/cudf/detail/copy_range.cuh +++ b/cpp/include/cudf/detail/copy_range.cuh @@ -172,7 +172,7 @@ void copy_range(SourceValueIterator source_value_begin, target_end, null_count.data()); - target.set_null_count(null_count.value()); + target.set_null_count(null_count.value(stream)); } else { auto kernel = copy_range_kernel; diff --git a/cpp/include/cudf/scalar/scalar.hpp b/cpp/include/cudf/scalar/scalar.hpp index 6938ad5feaa..e4d7baf86d9 100644 --- a/cpp/include/cudf/scalar/scalar.hpp +++ b/cpp/include/cudf/scalar/scalar.hpp @@ -73,7 +73,7 @@ class scalar { * @param is_valid true: set the value to valid. false: set it to null * @param stream CUDA stream used for device memory operations. */ - void set_valid(bool is_valid, rmm::cuda_stream_view stream = rmm::cuda_stream_default); + void set_valid_async(bool is_valid, rmm::cuda_stream_view stream = rmm::cuda_stream_default); /** * @brief Indicates whether the scalar contains a valid value @@ -97,10 +97,10 @@ class scalar { bool const* validity_data() const; protected: - data_type _type{type_id::EMPTY}; ///< Logical type of value in the scalar - rmm::device_scalar _is_valid{}; ///< Device bool signifying validity + data_type _type{type_id::EMPTY}; ///< Logical type of value in the scalar + rmm::device_scalar _is_valid; ///< Device bool signifying validity - scalar() = default; + scalar() = delete; /** * @brief Construct a new scalar object @@ -175,9 +175,9 @@ class fixed_width_scalar : public scalar { T const* data() const; protected: - rmm::device_scalar _data{}; ///< device memory containing the value + rmm::device_scalar _data; ///< device memory containing the value - fixed_width_scalar(); + fixed_width_scalar() = delete; /** * @brief Construct a new fixed width scalar object @@ -218,7 +218,7 @@ class numeric_scalar : public detail::fixed_width_scalar { static_assert(is_numeric(), "Unexpected non-numeric type."); public: - numeric_scalar() = default; + numeric_scalar() = delete; ~numeric_scalar() = default; numeric_scalar(numeric_scalar&& other) = default; @@ -276,7 +276,7 @@ class fixed_point_scalar : public scalar { using rep_type = typename T::rep; using value_type = T; - fixed_point_scalar(); + fixed_point_scalar() = delete; ~fixed_point_scalar() = default; fixed_point_scalar(fixed_point_scalar&& other) = default; @@ -375,7 +375,7 @@ class fixed_point_scalar : public scalar { rep_type const* data() const; protected: - rmm::device_scalar _data{}; ///< device memory containing the value + rmm::device_scalar _data; ///< device memory containing the value }; /** @@ -385,10 +385,11 @@ class string_scalar : public scalar { public: using value_type = cudf::string_view; - string_scalar(); + string_scalar() = delete; ~string_scalar() = default; string_scalar(string_scalar&& other) = default; + // string_scalar(string_scalar const& other) = delete; string_scalar& operator=(string_scalar const& other) = delete; string_scalar& operator=(string_scalar&& other) = delete; @@ -488,7 +489,7 @@ class chrono_scalar : public detail::fixed_width_scalar { static_assert(is_chrono(), "Unexpected non-chrono type"); public: - chrono_scalar() = default; + chrono_scalar() = delete; ~chrono_scalar() = default; chrono_scalar(chrono_scalar&& other) = default; @@ -540,7 +541,7 @@ class timestamp_scalar : public chrono_scalar { using chrono_scalar::chrono_scalar; using rep_type = typename T::rep; - timestamp_scalar() = default; + timestamp_scalar() = delete; timestamp_scalar(timestamp_scalar&& other) = default; /** @@ -583,7 +584,7 @@ class duration_scalar : public chrono_scalar { using chrono_scalar::chrono_scalar; using rep_type = typename T::rep; - duration_scalar() = default; + duration_scalar() = delete; duration_scalar(duration_scalar&& other) = default; /** @@ -621,7 +622,7 @@ class duration_scalar : public chrono_scalar { */ class list_scalar : public scalar { public: - list_scalar(); + list_scalar() = delete; ~list_scalar() = default; list_scalar(list_scalar&& other) = default; @@ -681,7 +682,7 @@ class list_scalar : public scalar { */ class struct_scalar : public scalar { public: - struct_scalar(); + struct_scalar() = delete; ~struct_scalar() = default; struct_scalar(struct_scalar&& other) = default; struct_scalar(struct_scalar const& other) = default; diff --git a/cpp/src/copying/get_element.cu b/cpp/src/copying/get_element.cu index a4d863d204d..9fa5f6bf17b 100644 --- a/cpp/src/copying/get_element.cu +++ b/cpp/src/copying/get_element.cu @@ -66,8 +66,8 @@ struct get_element_functor { { auto device_col = column_device_view::create(input, stream); - rmm::device_scalar temp_data; - rmm::device_scalar temp_valid; + rmm::device_scalar temp_data(stream, mr); + rmm::device_scalar temp_valid(stream, mr); device_single_thread( [buffer = temp_data.data(), @@ -105,7 +105,7 @@ struct get_element_functor { if (!key_index_scalar.is_valid(stream)) { auto null_result = make_default_constructed_scalar(dict_view.keys().type(), stream, mr); - null_result->set_valid(false, stream); + null_result->set_valid_async(false, stream); return null_result; } @@ -154,8 +154,8 @@ struct get_element_functor { auto device_col = column_device_view::create(input, stream); - rmm::device_scalar temp_data; - rmm::device_scalar temp_valid; + rmm::device_scalar temp_data(stream, mr); + rmm::device_scalar temp_valid(stream, mr); device_single_thread( [buffer = temp_data.data(), diff --git a/cpp/src/io/json/reader_impl.cu b/cpp/src/io/json/reader_impl.cu index 89bb05f7875..c3fcb9f613f 100644 --- a/cpp/src/io/json/reader_impl.cu +++ b/cpp/src/io/json/reader_impl.cu @@ -147,7 +147,7 @@ std::unique_ptr create_json_keys_info_table(const parse_options_view &opt options, data, row_offsets, key_counter.data(), {}, stream); // Allocate columns to store hash value, length, and offset of each JSON object key in the input - auto const num_keys = key_counter.value(); + auto const num_keys = key_counter.value(stream); std::vector> info_columns; info_columns.emplace_back(make_numeric_column(data_type(type_id::UINT64), num_keys)); info_columns.emplace_back(make_numeric_column(data_type(type_id::UINT16), num_keys)); @@ -157,7 +157,7 @@ std::unique_ptr
create_json_keys_info_table(const parse_options_view &opt auto const info_table_mdv = mutable_table_device_view::create(info_table->mutable_view(), stream); // Reset the key counter - now used for indexing - key_counter.set_value_zero(stream); + key_counter.set_value_to_zero_async(stream); // Fill the allocated columns cudf::io::json::gpu::collect_keys_info( options, data, row_offsets, key_counter.data(), {*info_table_mdv}, stream); @@ -433,7 +433,7 @@ void reader::impl::set_column_names(device_span rec_starts, // use keys as column names if input rows are objects auto keys_desc = get_json_object_keys_hashes(rec_starts, stream); metadata_.column_names = keys_desc.first; - set_column_map(std::move(keys_desc.second)); + set_column_map(std::move(keys_desc.second), stream); } else { int cols_found = 0; bool quotation = false; diff --git a/cpp/src/io/json/reader_impl.hpp b/cpp/src/io/json/reader_impl.hpp index cb413630d07..fa3c34586d9 100644 --- a/cpp/src/io/json/reader_impl.hpp +++ b/cpp/src/io/json/reader_impl.hpp @@ -87,10 +87,11 @@ class reader::impl { * @brief Sets the column map data member and makes a device copy to be used as a kernel * parameter. */ - void set_column_map(col_map_ptr_type &&map) + void set_column_map(col_map_ptr_type &&map, rmm::cuda_stream_view stream) { key_to_col_idx_map_ = std::move(map); - d_key_col_map_ = std::make_unique>(*key_to_col_idx_map_); + d_key_col_map_ = + std::make_unique>(*key_to_col_idx_map_, stream); } /** * @brief Gets the pointer to the column hash map in the device memory. diff --git a/cpp/src/join/hash_join.cu b/cpp/src/join/hash_join.cu index 2624ea68629..3f59bc13dda 100644 --- a/cpp/src/join/hash_join.cu +++ b/cpp/src/join/hash_join.cu @@ -255,7 +255,7 @@ probe_join_hash_table(cudf::table_device_view build_table, constexpr int block_size{DEFAULT_JOIN_BLOCK_SIZE}; detail::grid_1d config(probe_table.num_rows(), block_size); - write_index.set_value_zero(stream); + write_index.set_value_to_zero_async(stream); row_hash hash_probe{probe_table}; row_equality equality{probe_table, build_table, compare_nulls == null_equality::EQUAL}; diff --git a/cpp/src/join/hash_join.cuh b/cpp/src/join/hash_join.cuh index e6df2b58b15..8fefda9f841 100644 --- a/cpp/src/join/hash_join.cuh +++ b/cpp/src/join/hash_join.cuh @@ -122,7 +122,7 @@ std::size_t estimate_join_output_size(table_device_view build_table, do { sample_probe_num_rows = std::min(sample_probe_num_rows, probe_table_num_rows); - size_estimate.set_value_zero(stream); + size_estimate.set_value_to_zero_async(stream); row_hash hash_probe{probe_table}; row_equality equality{probe_table, build_table, compare_nulls == null_equality::EQUAL}; diff --git a/cpp/src/reductions/compound.cuh b/cpp/src/reductions/compound.cuh index 09d812e5d94..34d8912bc41 100644 --- a/cpp/src/reductions/compound.cuh +++ b/cpp/src/reductions/compound.cuh @@ -78,7 +78,7 @@ std::unique_ptr compound_reduction(column_view const& col, } // set scalar is valid - result->set_valid(col.null_count() < col.size(), stream); + result->set_valid_async(col.null_count() < col.size(), stream); return result; }; diff --git a/cpp/src/reductions/reductions.cpp b/cpp/src/reductions/reductions.cpp index 083b0da8cf3..00539b6d7a5 100644 --- a/cpp/src/reductions/reductions.cpp +++ b/cpp/src/reductions/reductions.cpp @@ -113,7 +113,7 @@ std::unique_ptr reduce( rmm::mr::device_memory_resource *mr = rmm::mr::get_current_device_resource()) { std::unique_ptr result = make_default_constructed_scalar(output_dtype, stream, mr); - result->set_valid(false, stream); + result->set_valid_async(false, stream); // check if input column is empty if (col.size() <= col.null_count()) return result; diff --git a/cpp/src/reductions/simple.cuh b/cpp/src/reductions/simple.cuh index baaedda7d63..61002481ddc 100644 --- a/cpp/src/reductions/simple.cuh +++ b/cpp/src/reductions/simple.cuh @@ -67,7 +67,7 @@ std::unique_ptr simple_reduction(column_view const& col, }(); // set scalar is valid - result->set_valid((col.null_count() < col.size()), stream); + result->set_valid_async(col.null_count() < col.size(), stream); return result; } @@ -147,7 +147,7 @@ std::unique_ptr dictionary_reduction(column_view const& col, }(); // set scalar is valid - result->set_valid((col.null_count() < col.size()), stream); + result->set_valid_async(col.null_count() < col.size(), stream); return result; } diff --git a/cpp/src/scalar/scalar.cpp b/cpp/src/scalar/scalar.cpp index 9189634b5d8..653164161e8 100644 --- a/cpp/src/scalar/scalar.cpp +++ b/cpp/src/scalar/scalar.cpp @@ -46,9 +46,9 @@ scalar::scalar(scalar const& other, data_type scalar::type() const noexcept { return _type; } -void scalar::set_valid(bool is_valid, rmm::cuda_stream_view stream) +void scalar::set_valid_async(bool is_valid, rmm::cuda_stream_view stream) { - _is_valid.set_value(is_valid, stream); + _is_valid.set_value_async(is_valid, stream); } bool scalar::is_valid(rmm::cuda_stream_view stream) const { return _is_valid.value(stream); } @@ -57,8 +57,6 @@ bool* scalar::validity_data() { return _is_valid.data(); } bool const* scalar::validity_data() const { return _is_valid.data(); } -string_scalar::string_scalar() : scalar(data_type(type_id::STRING)) {} - string_scalar::string_scalar(std::string const& string, bool is_valid, rmm::cuda_stream_view stream, @@ -112,9 +110,6 @@ std::string string_scalar::to_string(rmm::cuda_stream_view stream) const return result; } -template -fixed_point_scalar::fixed_point_scalar() : scalar(data_type(type_to_id())){}; - template fixed_point_scalar::fixed_point_scalar(rep_type value, numeric::scale_type scale, @@ -122,7 +117,7 @@ fixed_point_scalar::fixed_point_scalar(rep_type value, rmm::cuda_stream_view stream, rmm::mr::device_memory_resource* mr) : scalar{data_type{type_to_id(), static_cast(scale)}, is_valid, stream, mr}, - _data{value} + _data{value, stream, mr} { } @@ -131,7 +126,7 @@ fixed_point_scalar::fixed_point_scalar(rep_type value, bool is_valid, rmm::cuda_stream_view stream, rmm::mr::device_memory_resource* mr) - : scalar{data_type{type_to_id(), 0}, is_valid, stream, mr}, _data{value} + : scalar{data_type{type_to_id(), 0}, is_valid, stream, mr}, _data{value, stream, mr} { } @@ -140,7 +135,8 @@ fixed_point_scalar::fixed_point_scalar(T value, bool is_valid, rmm::cuda_stream_view stream, rmm::mr::device_memory_resource* mr) - : scalar{data_type{type_to_id(), value.scale()}, is_valid, stream, mr}, _data{value.value()} + : scalar{data_type{type_to_id(), value.scale()}, is_valid, stream, mr}, + _data{value.value(), stream, mr} { } @@ -202,11 +198,6 @@ template class fixed_point_scalar; namespace detail { -template -fixed_width_scalar::fixed_width_scalar() : scalar(data_type(type_to_id())) -{ -} - template fixed_width_scalar::fixed_width_scalar(T value, bool is_valid, @@ -237,8 +228,8 @@ fixed_width_scalar::fixed_width_scalar(fixed_width_scalar const& other, template void fixed_width_scalar::set_value(T value, rmm::cuda_stream_view stream) { - _data.set_value(value, stream); - this->set_valid(true, stream); + _data.set_value_async(value, stream); + this->set_valid_async(true, stream); } template @@ -491,8 +482,6 @@ TS_CTOR(timestamp_ns, duration_us) TS_CTOR(timestamp_ns, duration_ns) TS_CTOR(timestamp_ns, int64_t) -list_scalar::list_scalar() : scalar(data_type(type_id::LIST)) {} - list_scalar::list_scalar(cudf::column_view const& data, bool is_valid, rmm::cuda_stream_view stream, @@ -518,8 +507,6 @@ list_scalar::list_scalar(list_scalar const& other, column_view list_scalar::view() const { return _data.view(); } -struct_scalar::struct_scalar() : scalar(data_type(type_id::STRUCT)) {} - struct_scalar::struct_scalar(table_view const& data, bool is_valid, rmm::cuda_stream_view stream, diff --git a/cpp/src/strings/attributes.cu b/cpp/src/strings/attributes.cu index bed86544ec7..997265ecfed 100644 --- a/cpp/src/strings/attributes.cu +++ b/cpp/src/strings/attributes.cu @@ -150,8 +150,8 @@ std::unique_ptr code_points( return length; }, thrust::plus()); - size_type const zero = 0; - offsets.set_element_async(0, zero, stream); + + offsets.set_element_to_zero_async(0, stream); // the total size is the number of characters in the entire column size_type num_characters = offsets.back_element(stream); diff --git a/cpp/src/strings/combine/join.cu b/cpp/src/strings/combine/join.cu index cdfaf856513..4a2144cd22b 100644 --- a/cpp/src/strings/combine/join.cu +++ b/cpp/src/strings/combine/join.cu @@ -74,11 +74,9 @@ std::unique_ptr join_strings(strings_column_view const& strings, return bytes; }, thrust::plus()); - size_type const zero = 0; - output_offsets.set_element_async(0, zero, stream); + + output_offsets.set_element_to_zero_async(0, stream); // total size is the last entry - // Note this call does a synchronize on the stream and thereby also protects the - // set_element_async parameter from going out of scope before it is used. size_type const bytes = output_offsets.back_element(stream); // build offsets column (only 1 string so 2 offset entries) diff --git a/cpp/src/strings/copying/concatenate.cu b/cpp/src/strings/copying/concatenate.cu index 48358cb4a38..0e6178d7f39 100644 --- a/cpp/src/strings/copying/concatenate.cu +++ b/cpp/src/strings/copying/concatenate.cu @@ -91,8 +91,7 @@ auto create_strings_device_views(host_span views, rmm::cuda_s // Compute the partition offsets and size of chars column // Note: Using 64-bit size_t so we can detect overflow of 32-bit size_type auto d_partition_offsets = rmm::device_uvector(views.size() + 1, stream); - size_t zero{0}; - d_partition_offsets.set_element_async(0, zero, stream); // zero first element + d_partition_offsets.set_element_to_zero_async(0, stream); // zero first element thrust::transform_inclusive_scan(rmm::exec_policy(stream), device_views_ptr, @@ -247,7 +246,7 @@ std::unique_ptr concatenate(host_span columns, } { // Copy offsets columns with single kernel launch - rmm::device_scalar d_valid_count(0); + rmm::device_scalar d_valid_count(0, stream); constexpr size_type block_size{256}; cudf::detail::grid_1d config(offsets_count, block_size); diff --git a/cpp/src/strings/json/json_path.cu b/cpp/src/strings/json/json_path.cu index 20d4aa2a307..8de9915a668 100644 --- a/cpp/src/strings/json/json_path.cu +++ b/cpp/src/strings/json/json_path.cu @@ -988,7 +988,7 @@ std::unique_ptr get_json_object(cudf::strings_column_view const& c return make_strings_column(col.size(), std::move(offsets), std::move(chars), - col.size() - d_valid_count.value(), + col.size() - d_valid_count.value(stream), std::move(validity), stream, mr); diff --git a/cpp/src/text/ngrams_tokenize.cu b/cpp/src/text/ngrams_tokenize.cu index bdcaac4d4ea..36136ef89fa 100644 --- a/cpp/src/text/ngrams_tokenize.cu +++ b/cpp/src/text/ngrams_tokenize.cu @@ -165,8 +165,7 @@ std::unique_ptr ngrams_tokenize( d_token_offsets + 1, strings_tokenizer{d_strings, d_delimiter}, thrust::plus()); - int32_t const zero = 0; - token_offsets.set_element_async(0, zero, stream); + token_offsets.set_element_to_zero_async(0, stream); auto const total_tokens = token_offsets.back_element(stream); // Ex. 5 tokens // get the token positions (in bytes) per string @@ -193,7 +192,7 @@ std::unique_ptr ngrams_tokenize( return (token_count >= ngrams) ? token_count - ngrams + 1 : 0; }, thrust::plus()); - ngram_offsets.set_element_async(0, zero, stream); + ngram_offsets.set_element_to_zero_async(0, stream); auto const total_ngrams = ngram_offsets.back_element(stream); // Compute the total size of the ngrams for each string (not for each ngram) @@ -213,7 +212,7 @@ std::unique_ptr ngrams_tokenize( d_chars_offsets + 1, ngram_builder_fn{d_strings, d_separator, ngrams, d_token_offsets, d_token_positions}, thrust::plus()); - chars_offsets.set_element_async(0, zero, stream); + chars_offsets.set_element_to_zero_async(0, stream); auto const output_chars_size = chars_offsets.back_element(stream); // Ex. 14 output bytes total rmm::device_uvector ngram_sizes(total_ngrams, stream); // size in bytes of each diff --git a/cpp/src/text/tokenize.cu b/cpp/src/text/tokenize.cu index d66b45618aa..0a8b3f5bb48 100644 --- a/cpp/src/text/tokenize.cu +++ b/cpp/src/text/tokenize.cu @@ -77,8 +77,7 @@ std::unique_ptr tokenize_fn(cudf::size_type strings_count, d_token_counts.template begin(), d_token_counts.template end(), token_offsets.begin() + 1); - int32_t const zero = 0; - token_offsets.set_element_async(0, zero, stream); + token_offsets.set_element_to_zero_async(0, stream); auto const total_tokens = token_offsets.back_element(stream); // build a list of pointers to each token rmm::device_uvector tokens(total_tokens, stream); diff --git a/cpp/tests/binaryop/binop-integration-test.cpp b/cpp/tests/binaryop/binop-integration-test.cpp index 019e72d3d3f..3f4cb073eb5 100644 --- a/cpp/tests/binaryop/binop-integration-test.cpp +++ b/cpp/tests/binaryop/binop-integration-test.cpp @@ -1101,7 +1101,7 @@ TEST_F(BinaryOperationIntegrationTest, NullAwareEqual_Vector_ScalarInvalid_B8_SI auto int_col = fixed_width_column_wrapper{{-INT32_MAX, -37, 0, 499, 44, INT32_MAX}, {false, true, false, true, true, false}}; auto int_scalar = cudf::scalar_type_t(999); - int_scalar.set_valid(false); + int_scalar.set_valid_async(false); auto op_col = cudf::binary_operation( int_col, int_scalar, cudf::binary_operator::NULL_EQUALS, data_type(type_to_id())); @@ -1217,7 +1217,7 @@ TEST_F(BinaryOperationIntegrationTest, NullAwareEqual_Scalar_Vector_B8_string_st {true, true, true, true, true, true, true}); // Matching a scalar that is invalid cudf::string_scalar str_scalar("foo"); - str_scalar.set_valid(false); + str_scalar.set_valid_async(false); auto op_col = cudf::binary_operation( str_scalar, str_col, cudf::binary_operator::NULL_EQUALS, data_type(type_to_id())); @@ -1262,7 +1262,7 @@ TEST_F(BinaryOperationIntegrationTest, NullAwareEqual_Scalar_Vector_B8_string_st {false, false, false, false, false, false, false}); // Matching a scalar that is invalid cudf::string_scalar str_scalar("foo"); - str_scalar.set_valid(false); + str_scalar.set_valid_async(false); auto op_col = cudf::binary_operation( str_scalar, str_col, cudf::binary_operator::NULL_EQUALS, data_type(type_to_id())); @@ -1303,7 +1303,7 @@ TEST_F(BinaryOperationIntegrationTest, NullAwareEqual_Vector_InvalidScalar_B8_st {true, false, true, true, true, false, true}); // Valid string invalidated cudf::string_scalar str_scalar("bb"); - str_scalar.set_valid(false); + str_scalar.set_valid_async(false); auto op_col = cudf::binary_operation( str_col, str_scalar, cudf::binary_operator::NULL_EQUALS, data_type(type_to_id())); @@ -1553,7 +1553,7 @@ TEST_F(BinaryOperationIntegrationTest, NullAwareMin_Vector_Scalar_SI64_SI32_FP32 fixed_width_column_wrapper{{999, -37, 0, INT32_MAX, -INT32_MAX, -4379, 55}, {false, true, false, true, false, true, false}}; auto float_scalar = cudf::scalar_type_t(-3.14f); - float_scalar.set_valid(false); + float_scalar.set_valid_async(false); auto op_col = cudf::binary_operation( int_col, float_scalar, cudf::binary_operator::NULL_MIN, data_type(type_to_id())); @@ -1575,7 +1575,7 @@ TEST_F(BinaryOperationIntegrationTest, NullAwareMax_Scalar_Vector_SI8_SI8_FP32) auto int_col = fixed_width_column_wrapper{ {9, -37, 0, 32, -47, -4, 55}, {false, false, false, false, false, false, false}}; auto float_scalar = cudf::scalar_type_t(-3.14f); - float_scalar.set_valid(false); + float_scalar.set_valid_async(false); auto op_col = cudf::binary_operation( float_scalar, int_col, cudf::binary_operator::NULL_MAX, data_type(type_to_id())); @@ -1728,7 +1728,7 @@ TEST_F(BinaryOperationIntegrationTest, NullAwareMax_Scalar_Vector_string_string_ {"eee", "invalid", "", "", "", "", "ééé", "foo", "bar", "abc", "foo"}, {false, true, true, false, true, true, true, false, false, true, true}); cudf::string_scalar str_scalar("foo"); - str_scalar.set_valid(false); + str_scalar.set_valid_async(false); // Returns the lhs_col auto op_col = cudf::binary_operation( diff --git a/cpp/tests/binaryop/binop-null-test.cpp b/cpp/tests/binaryop/binop-null-test.cpp index 184bafc8c57..c91bc12d95f 100644 --- a/cpp/tests/binaryop/binop-null-test.cpp +++ b/cpp/tests/binaryop/binop-null-test.cpp @@ -63,7 +63,7 @@ TEST_F(BinaryOperationNullTest, Scalar_Null_Vector_Valid) using ADD = cudf::library::operation::Add; auto lhs = make_random_wrapped_scalar(); - lhs.set_valid(false); + lhs.set_valid_async(false); auto rhs = make_random_wrapped_column(100, mask_state::ALL_VALID); auto out = @@ -98,7 +98,7 @@ TEST_F(BinaryOperationNullTest, Scalar_Null_Vector_NonNullable) using ADD = cudf::library::operation::Add; auto lhs = make_random_wrapped_scalar(); - lhs.set_valid(false); + lhs.set_valid_async(false); auto rhs = make_random_wrapped_column(100, mask_state::UNALLOCATED); auto out = diff --git a/cpp/tests/copying/scatter_tests.cpp b/cpp/tests/copying/scatter_tests.cpp index 500c017ca85..be4a689f213 100644 --- a/cpp/tests/copying/scatter_tests.cpp +++ b/cpp/tests/copying/scatter_tests.cpp @@ -738,7 +738,7 @@ struct BooleanMaskScalarScatter : public cudf::test::BaseFixture { } static_cast(scalar.get())->set_value(value); - static_cast(scalar.get())->set_valid(validity); + static_cast(scalar.get())->set_valid_async(validity); return scalar; } @@ -774,7 +774,7 @@ TYPED_TEST(BooleanMaskScalarScatter, WithNull) bool validity = false; auto scalar_1 = this->form_scalar(source, validity); auto scalar_2 = cudf::make_string_scalar("cudf"); - scalar_2->set_valid(true); + scalar_2->set_valid_async(true); std::vector> scalar_vect; scalar_vect.push_back(*scalar_1); scalar_vect.push_back(*scalar_2); @@ -804,7 +804,7 @@ class BooleanMaskScatterScalarString : public cudf::test::BaseFixture { TEST_F(BooleanMaskScatterScalarString, NoNUll) { auto scalar = cudf::make_string_scalar("cudf"); - scalar->set_valid(true); + scalar->set_valid_async(true); std::vector> scalar_vect; scalar_vect.push_back(*scalar); @@ -823,7 +823,7 @@ TEST_F(BooleanMaskScatterScalarString, NoNUll) TEST_F(BooleanMaskScatterScalarString, WithNUll) { auto scalar = cudf::make_string_scalar("cudf"); - scalar->set_valid(true); + scalar->set_valid_async(true); std::vector> scalar_vect; scalar_vect.push_back(*scalar); cudf::test::strings_column_wrapper target({"is", "is", "a", "udf", "api"}, {1, 0, 0, 1, 1}); diff --git a/cpp/tests/filling/fill_tests.cpp b/cpp/tests/filling/fill_tests.cpp index 6fedf7fea05..75c0cad20e7 100644 --- a/cpp/tests/filling/fill_tests.cpp +++ b/cpp/tests/filling/fill_tests.cpp @@ -68,7 +68,7 @@ class FillTypedTestFixture : public cudf::test::BaseFixture { } using ScalarType = cudf::scalar_type_t; static_cast(p_val.get())->set_value(value); - static_cast(p_val.get())->set_valid(value_is_valid); + static_cast(p_val.get())->set_valid_async(value_is_valid); auto expected_elements = cudf::detail::make_counting_transform_iterator(0, [begin, end, value](auto i) { @@ -189,7 +189,7 @@ class FillStringTestFixture : public cudf::test::BaseFixture { auto p_val = cudf::make_string_scalar(value); using ScalarType = cudf::scalar_type_t; - static_cast(p_val.get())->set_valid(value_is_valid); + static_cast(p_val.get())->set_valid_async(value_is_valid); auto p_chars = value.c_str(); auto num_chars = value.length(); @@ -285,7 +285,7 @@ TEST_F(FillErrorTestFixture, InvalidInplaceCall) using T_int = cudf::id_to_type; using ScalarType = cudf::scalar_type_t; static_cast(p_val_int.get())->set_value(5); - static_cast(p_val_int.get())->set_valid(false); + static_cast(p_val_int.get())->set_valid_async(false); auto destination = cudf::test::fixed_width_column_wrapper( thrust::make_counting_iterator(0), thrust::make_counting_iterator(0) + 100); diff --git a/cpp/tests/lists/contains_tests.cpp b/cpp/tests/lists/contains_tests.cpp index 73194271a32..fe0a3cb6084 100644 --- a/cpp/tests/lists/contains_tests.cpp +++ b/cpp/tests/lists/contains_tests.cpp @@ -46,7 +46,7 @@ template (), void>* = nullptr> auto create_scalar_search_key(T const& value) { auto search_key = make_numeric_scalar(data_type{type_to_id()}); - search_key->set_valid(true); + search_key->set_valid_async(true); static_cast*>(search_key.get())->set_value(value); return search_key; } @@ -61,7 +61,7 @@ template (), void>* = nullptr auto create_scalar_search_key(typename T::rep const& value) { auto search_key = make_timestamp_scalar(data_type{type_to_id()}); - search_key->set_valid(true); + search_key->set_valid_async(true); static_cast*>(search_key.get())->set_value(value); return search_key; } @@ -70,7 +70,7 @@ template (), void>* = nullptr> auto create_scalar_search_key(typename T::rep const& value) { auto search_key = make_duration_scalar(data_type{type_to_id()}); - search_key->set_valid(true); + search_key->set_valid_async(true); static_cast*>(search_key.get())->set_value(value); return search_key; } @@ -79,7 +79,7 @@ template (), void>* = nullptr> auto create_null_search_key() { auto search_key = make_numeric_scalar(data_type{type_to_id()}); - search_key->set_valid(false); + search_key->set_valid_async(false); return search_key; } @@ -87,7 +87,7 @@ template (), void>* = nullptr auto create_null_search_key() { auto search_key = make_timestamp_scalar(data_type{type_to_id()}); - search_key->set_valid(false); + search_key->set_valid_async(false); return search_key; } @@ -95,7 +95,7 @@ template (), void>* = nullptr> auto create_null_search_key() { auto search_key = make_duration_scalar(data_type{type_to_id()}); - search_key->set_valid(false); + search_key->set_valid_async(false); return search_key; } diff --git a/cpp/tests/replace/clamp_test.cpp b/cpp/tests/replace/clamp_test.cpp index 499745c7dc4..ecc36b3af20 100644 --- a/cpp/tests/replace/clamp_test.cpp +++ b/cpp/tests/replace/clamp_test.cpp @@ -33,9 +33,9 @@ struct ClampErrorTest : public cudf::test::BaseFixture { TEST_F(ClampErrorTest, MisMatchingScalarTypes) { auto lo = cudf::make_numeric_scalar(cudf::data_type(cudf::type_id::INT32)); - lo->set_valid(true); + lo->set_valid_async(true); auto hi = cudf::make_numeric_scalar(cudf::data_type(cudf::type_id::INT64)); - hi->set_valid(true); + hi->set_valid_async(true); cudf::test::fixed_width_column_wrapper input({1, 2, 3, 4, 5, 6}); @@ -45,9 +45,9 @@ TEST_F(ClampErrorTest, MisMatchingScalarTypes) TEST_F(ClampErrorTest, MisMatchingInputAndScalarTypes) { auto lo = cudf::make_numeric_scalar(cudf::data_type(cudf::type_id::INT32)); - lo->set_valid(true); + lo->set_valid_async(true); auto hi = cudf::make_numeric_scalar(cudf::data_type(cudf::type_id::INT32)); - hi->set_valid(true); + hi->set_valid_async(true); cudf::test::fixed_width_column_wrapper input({1, 2, 3, 4, 5, 6}); @@ -57,13 +57,13 @@ TEST_F(ClampErrorTest, MisMatchingInputAndScalarTypes) TEST_F(ClampErrorTest, MisMatchingReplaceScalarTypes) { auto lo = cudf::make_numeric_scalar(cudf::data_type(cudf::type_id::INT32)); - lo->set_valid(true); + lo->set_valid_async(true); auto hi = cudf::make_numeric_scalar(cudf::data_type(cudf::type_id::INT32)); - hi->set_valid(true); + hi->set_valid_async(true); auto lo_replace = cudf::make_numeric_scalar(cudf::data_type(cudf::type_id::INT64)); - lo_replace->set_valid(true); + lo_replace->set_valid_async(true); auto hi_replace = cudf::make_numeric_scalar(cudf::data_type(cudf::type_id::INT32)); - hi_replace->set_valid(true); + hi_replace->set_valid_async(true); cudf::test::fixed_width_column_wrapper input({1, 2, 3, 4, 5, 6}); @@ -73,13 +73,13 @@ TEST_F(ClampErrorTest, MisMatchingReplaceScalarTypes) TEST_F(ClampErrorTest, InValidCase1) { auto lo = cudf::make_numeric_scalar(cudf::data_type(cudf::type_id::INT32)); - lo->set_valid(true); + lo->set_valid_async(true); auto hi = cudf::make_numeric_scalar(cudf::data_type(cudf::type_id::INT32)); - hi->set_valid(true); + hi->set_valid_async(true); auto lo_replace = cudf::make_numeric_scalar(cudf::data_type(cudf::type_id::INT32)); - lo_replace->set_valid(false); + lo_replace->set_valid_async(false); auto hi_replace = cudf::make_numeric_scalar(cudf::data_type(cudf::type_id::INT32)); - hi_replace->set_valid(true); + hi_replace->set_valid_async(true); cudf::test::fixed_width_column_wrapper input({1, 2, 3, 4, 5, 6}); @@ -89,13 +89,13 @@ TEST_F(ClampErrorTest, InValidCase1) TEST_F(ClampErrorTest, InValidCase2) { auto lo = cudf::make_numeric_scalar(cudf::data_type(cudf::type_id::INT32)); - lo->set_valid(true); + lo->set_valid_async(true); auto hi = cudf::make_numeric_scalar(cudf::data_type(cudf::type_id::INT32)); - hi->set_valid(true); + hi->set_valid_async(true); auto lo_replace = cudf::make_numeric_scalar(cudf::data_type(cudf::type_id::INT32)); - lo_replace->set_valid(true); + lo_replace->set_valid_async(true); auto hi_replace = cudf::make_numeric_scalar(cudf::data_type(cudf::type_id::INT32)); - hi_replace->set_valid(false); + hi_replace->set_valid_async(false); cudf::test::fixed_width_column_wrapper input({1, 2, 3, 4, 5, 6}); @@ -108,9 +108,9 @@ struct ClampEmptyCaseTest : public cudf::test::BaseFixture { TEST_F(ClampEmptyCaseTest, BothScalarEmptyInvalid) { auto lo = cudf::make_numeric_scalar(cudf::data_type(cudf::type_id::INT32)); - lo->set_valid(false); + lo->set_valid_async(false); auto hi = cudf::make_numeric_scalar(cudf::data_type(cudf::type_id::INT32)); - hi->set_valid(false); + hi->set_valid_async(false); cudf::test::fixed_width_column_wrapper input({1, 2, 3, 4, 5, 6}); @@ -122,9 +122,9 @@ TEST_F(ClampEmptyCaseTest, BothScalarEmptyInvalid) TEST_F(ClampEmptyCaseTest, EmptyInput) { auto lo = cudf::make_numeric_scalar(cudf::data_type(cudf::type_id::INT32)); - lo->set_valid(true); + lo->set_valid_async(true); auto hi = cudf::make_numeric_scalar(cudf::data_type(cudf::type_id::INT32)); - hi->set_valid(true); + hi->set_valid_async(true); cudf::test::fixed_width_column_wrapper input({}); @@ -181,13 +181,13 @@ struct ClampTestNumeric : public cudf::test::BaseFixture { } static_cast(lo_scalar.get())->set_value(lo); - static_cast(lo_scalar.get())->set_valid(lo_validity); + static_cast(lo_scalar.get())->set_valid_async(lo_validity); static_cast(lo_replace_scalar.get())->set_value(lo_replace); - static_cast(lo_replace_scalar.get())->set_valid(lo_replace_validity); + static_cast(lo_replace_scalar.get())->set_valid_async(lo_replace_validity); static_cast(hi_scalar.get())->set_value(hi); - static_cast(hi_scalar.get())->set_valid(hi_validity); + static_cast(hi_scalar.get())->set_valid_async(hi_validity); static_cast(hi_replace_scalar.get())->set_value(hi_replace); - static_cast(hi_replace_scalar.get())->set_valid(hi_replace_validity); + static_cast(hi_replace_scalar.get())->set_valid_async(hi_replace_validity); if (input.size() == input_validity.size()) { cudf::test::fixed_width_column_wrapper input_column( @@ -307,9 +307,9 @@ TYPED_TEST(ClampFloatTest, WithNANandNoNull) cudf::make_numeric_scalar(cudf::data_type(cudf::data_type{cudf::type_to_id()})); static_cast(lo_scalar.get())->set_value(2.0); - static_cast(lo_scalar.get())->set_valid(true); + static_cast(lo_scalar.get())->set_valid_async(true); static_cast(hi_scalar.get())->set_value(6.0); - static_cast(hi_scalar.get())->set_valid(true); + static_cast(hi_scalar.get())->set_valid_async(true); auto got = cudf::clamp(input, *lo_scalar, *hi_scalar); cudf::test::fixed_width_column_wrapper expected( @@ -332,9 +332,9 @@ TYPED_TEST(ClampFloatTest, WithNANandNull) cudf::make_numeric_scalar(cudf::data_type(cudf::data_type{cudf::type_to_id()})); static_cast(lo_scalar.get())->set_value(2.0); - static_cast(lo_scalar.get())->set_valid(true); + static_cast(lo_scalar.get())->set_valid_async(true); static_cast(hi_scalar.get())->set_value(6.0); - static_cast(hi_scalar.get())->set_valid(true); + static_cast(hi_scalar.get())->set_valid_async(true); auto got = cudf::clamp(input, *lo_scalar, *hi_scalar); cudf::test::fixed_width_column_wrapper expected( @@ -362,13 +362,13 @@ TYPED_TEST(ClampFloatTest, SignOfAFloat) cudf::make_numeric_scalar(cudf::data_type(cudf::data_type{cudf::type_to_id()})); static_cast(lo_scalar.get())->set_value(0.0); - static_cast(lo_scalar.get())->set_valid(true); + static_cast(lo_scalar.get())->set_valid_async(true); static_cast(hi_scalar.get())->set_value(0.0); - static_cast(hi_scalar.get())->set_valid(true); + static_cast(hi_scalar.get())->set_valid_async(true); static_cast(lo_replace_scalar.get())->set_value(-1.0); - static_cast(lo_replace_scalar.get())->set_valid(true); + static_cast(lo_replace_scalar.get())->set_valid_async(true); static_cast(hi_replace_scalar.get())->set_value(1.0); - static_cast(hi_replace_scalar.get())->set_valid(true); + static_cast(hi_replace_scalar.get())->set_valid_async(true); auto got = cudf::clamp(input, *lo_scalar, *lo_replace_scalar, *hi_scalar, *hi_replace_scalar); cudf::test::fixed_width_column_wrapper expected( @@ -390,8 +390,8 @@ TEST_F(ClampStringTest, WithNullableColumn) auto lo = cudf::make_string_scalar("B"); auto hi = cudf::make_string_scalar("e"); - lo->set_valid(true); - hi->set_valid(true); + lo->set_valid_async(true); + hi->set_valid_async(true); std::vector expected_strings{"B", "b", "c", "D", "e", "F", "G", "H", "i", "e", "B"}; @@ -411,8 +411,8 @@ TEST_F(ClampStringTest, WithNonNullableColumn) auto lo = cudf::make_string_scalar("B"); auto hi = cudf::make_string_scalar("e"); - lo->set_valid(true); - hi->set_valid(true); + lo->set_valid_async(true); + hi->set_valid_async(true); std::vector expected_strings{"B", "b", "c", "D", "e", "F", "G", "H", "e", "e", "B"}; @@ -432,8 +432,8 @@ TEST_F(ClampStringTest, WithNullableColumnNullLow) auto lo = cudf::make_string_scalar("B"); auto hi = cudf::make_string_scalar("e"); - lo->set_valid(false); - hi->set_valid(true); + lo->set_valid_async(false); + hi->set_valid_async(true); std::vector expected_strings{"A", "b", "c", "D", "e", "F", "G", "H", "i", "e", "B"}; @@ -454,8 +454,8 @@ TEST_F(ClampStringTest, WithNullableColumnNullHigh) auto lo = cudf::make_string_scalar("B"); auto hi = cudf::make_string_scalar("e"); - lo->set_valid(true); - hi->set_valid(false); + lo->set_valid_async(true); + hi->set_valid_async(false); std::vector expected_strings{"B", "b", "c", "D", "e", "F", "G", "H", "i", "j", "B"}; @@ -476,8 +476,8 @@ TEST_F(ClampStringTest, WithNullableColumnBothLoAndHiNull) auto lo = cudf::make_string_scalar("B"); auto hi = cudf::make_string_scalar("e"); - lo->set_valid(false); - hi->set_valid(false); + lo->set_valid_async(false); + hi->set_valid_async(false); auto got = cudf::clamp(input, *lo, *hi); @@ -495,10 +495,10 @@ TEST_F(ClampStringTest, WithReplaceString) auto lo_replace = cudf::make_string_scalar("Z"); auto hi = cudf::make_string_scalar("e"); auto hi_replace = cudf::make_string_scalar("z"); - lo->set_valid(true); - lo_replace->set_valid(true); - hi->set_valid(true); - hi_replace->set_valid(true); + lo->set_valid_async(true); + lo_replace->set_valid_async(true); + hi->set_valid_async(true); + hi_replace->set_valid_async(true); std::vector expected_strings{"Z", "b", "c", "D", "e", "F", "G", "H", "z", "z", "B"}; diff --git a/cpp/tests/replace/replace_nulls_tests.cpp b/cpp/tests/replace/replace_nulls_tests.cpp index 3f0f546f55e..92342326dca 100644 --- a/cpp/tests/replace/replace_nulls_tests.cpp +++ b/cpp/tests/replace/replace_nulls_tests.cpp @@ -171,7 +171,7 @@ TEST_F(ReplaceNullsStringsTest, SimpleReplaceScalar) std::vector input_v{0, 0, 0, 0, 0, 0, 0, 0}; std::unique_ptr repl = cudf::make_string_scalar("rep", rmm::cuda_stream_default, mr()); - repl->set_valid(true, rmm::cuda_stream_default); + repl->set_valid_async(true, rmm::cuda_stream_default); std::vector expected{"rep", "rep", "rep", "rep", "rep", "rep", "rep", "rep"}; cudf::test::strings_column_wrapper input_w{input.begin(), input.end(), input_v.begin()}; diff --git a/cpp/tests/scalar/scalar_device_view_test.cu b/cpp/tests/scalar/scalar_device_view_test.cu index d0b6b0db44a..19d5372d93a 100644 --- a/cpp/tests/scalar/scalar_device_view_test.cu +++ b/cpp/tests/scalar/scalar_device_view_test.cu @@ -27,6 +27,7 @@ #include #include +#include "rmm/cuda_stream_view.hpp" template struct TypedScalarDeviceViewTest : public cudf::test::BaseFixture { @@ -49,13 +50,14 @@ __global__ void test_value(ScalarDeviceViewType s, ScalarDeviceViewType s1, bool TYPED_TEST(TypedScalarDeviceViewTest, Value) { - TypeParam value = cudf::test::make_type_param_scalar(7); + TypeParam value = cudf::test::make_type_param_scalar(7); + TypeParam value1 = cudf::test::make_type_param_scalar(11); cudf::scalar_type_t s(value); - cudf::scalar_type_t s1; + cudf::scalar_type_t s1{value1}; auto scalar_device_view = cudf::get_scalar_device_view(s); auto scalar_device_view1 = cudf::get_scalar_device_view(s1); - rmm::device_scalar result; + rmm::device_scalar result{rmm::cuda_stream_default}; test_set_value<<<1, 1>>>(scalar_device_view, scalar_device_view1); CHECK_CUDA(0); @@ -66,7 +68,7 @@ TYPED_TEST(TypedScalarDeviceViewTest, Value) test_value<<<1, 1>>>(scalar_device_view, scalar_device_view1, result.data()); CHECK_CUDA(0); - EXPECT_TRUE(result.value()); + EXPECT_TRUE(result.value(rmm::cuda_stream_default)); } template @@ -80,12 +82,12 @@ TYPED_TEST(TypedScalarDeviceViewTest, ConstructNull) TypeParam value = cudf::test::make_type_param_scalar(5); cudf::scalar_type_t s(value, false); auto scalar_device_view = cudf::get_scalar_device_view(s); - rmm::device_scalar result; + rmm::device_scalar result{rmm::cuda_stream_default}; test_null<<<1, 1>>>(scalar_device_view, result.data()); CHECK_CUDA(0); - EXPECT_FALSE(result.value()); + EXPECT_FALSE(result.value(rmm::cuda_stream_default)); } template @@ -96,9 +98,10 @@ __global__ void test_setnull(ScalarDeviceViewType s) TYPED_TEST(TypedScalarDeviceViewTest, SetNull) { - cudf::scalar_type_t s; + TypeParam value = cudf::test::make_type_param_scalar(5); + cudf::scalar_type_t s{value}; auto scalar_device_view = cudf::get_scalar_device_view(s); - s.set_valid(true); + s.set_valid_async(true); EXPECT_TRUE(s.is_valid()); test_setnull<<<1, 1>>>(scalar_device_view); @@ -124,11 +127,11 @@ TEST_F(StringScalarDeviceViewTest, Value) cudf::string_scalar s(value); auto scalar_device_view = cudf::get_scalar_device_view(s); - rmm::device_scalar result; + rmm::device_scalar result{rmm::cuda_stream_default}; auto value_v = cudf::detail::make_device_uvector_sync(value); test_string_value<<<1, 1>>>(scalar_device_view, value_v.data(), value.size(), result.data()); CHECK_CUDA(0); - EXPECT_TRUE(result.value()); + EXPECT_TRUE(result.value(rmm::cuda_stream_default)); } diff --git a/cpp/tests/scalar/scalar_test.cpp b/cpp/tests/scalar/scalar_test.cpp index 7a12c2fd27d..2047d815867 100644 --- a/cpp/tests/scalar/scalar_test.cpp +++ b/cpp/tests/scalar/scalar_test.cpp @@ -26,6 +26,7 @@ #include #include +#include template struct TypedScalarTest : public cudf::test::BaseFixture { @@ -58,8 +59,9 @@ TYPED_TEST(TypedScalarTest, ConstructNull) TYPED_TEST(TypedScalarTestWithoutFixedPoint, SetValue) { + TypeParam init = cudf::test::make_type_param_scalar(0); TypeParam value = cudf::test::make_type_param_scalar(9); - cudf::scalar_type_t s; + cudf::scalar_type_t s(init, true); s.set_value(value); EXPECT_TRUE(s.is_valid()); @@ -69,9 +71,8 @@ TYPED_TEST(TypedScalarTestWithoutFixedPoint, SetValue) TYPED_TEST(TypedScalarTestWithoutFixedPoint, SetNull) { TypeParam value = cudf::test::make_type_param_scalar(6); - cudf::scalar_type_t s; - s.set_value(value); - s.set_valid(false); + cudf::scalar_type_t s(value, true); + s.set_valid_async(false); EXPECT_FALSE(s.is_valid()); } @@ -111,13 +112,6 @@ TEST_F(StringScalarTest, DefaultValidity) EXPECT_EQ(value, s.to_string()); } -TEST_F(StringScalarTest, ConstructNull) -{ - auto s = cudf::string_scalar(); - - EXPECT_FALSE(s.is_valid()); -} - TEST_F(StringScalarTest, CopyConstructor) { std::string value = "test_string"; @@ -161,13 +155,6 @@ TEST_F(ListScalarTest, DefaultValidityNested) CUDF_TEST_EXPECT_COLUMNS_EQUAL(data, s.view()); } -TEST_F(ListScalarTest, ConstructNull) -{ - auto s = cudf::list_scalar(); - - EXPECT_FALSE(s.is_valid()); -} - TEST_F(ListScalarTest, MoveColumnConstructor) { auto data = cudf::test::fixed_width_column_wrapper{1, 2, 3}; diff --git a/java/src/main/native/src/ColumnVectorJni.cpp b/java/src/main/native/src/ColumnVectorJni.cpp index a517fe06c1f..57f5f613da7 100644 --- a/java/src/main/native/src/ColumnVectorJni.cpp +++ b/java/src/main/native/src/ColumnVectorJni.cpp @@ -17,18 +17,18 @@ #include #include #include +#include #include -#include #include -#include -#include -#include +#include #include #include #include +#include #include #include #include +#include #include "cudf_jni_apis.hpp" #include "dtype_utils.hpp" @@ -54,13 +54,9 @@ JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnVector_sequence(JNIEnv *env, j 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); @@ -83,17 +79,22 @@ JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnVector_fromArrow(JNIEnv *env, offsets_address = env->GetDirectBufferAddress(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), static_cast(validity_length)); - auto offsets_buffer = arrow::Buffer::Wrap(static_cast(offsets_address), static_cast(offsets_length)); + auto data_buffer = + 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), + 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); @@ -102,19 +103,23 @@ JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnVector_fromArrow(JNIEnv *env, 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()); std::vector> fields = {name_and_type}; std::shared_ptr schema = std::make_shared(fields); - auto arrow_table = arrow::Table::Make(schema, std::vector>{arrow_array}); + auto arrow_table = + arrow::Table::Make(schema, std::vector>{arrow_array}); std::unique_ptr table_result = cudf::from_arrow(*(arrow_table)); std::vector> retCols = table_result->release(); if (retCols.size() != 1) { @@ -125,65 +130,57 @@ JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnVector_fromArrow(JNIEnv *env, 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); std::vector column_views; - std::transform(n_cudf_columns.data(), - n_cudf_columns.data() + n_cudf_columns.size(), + std::transform(n_cudf_columns.data(), n_cudf_columns.data() + n_cudf_columns.size(), std::back_inserter(column_views), [](auto const &p_column) { return *p_column; }); - std::unique_ptr result = - cudf::strings::concatenate(cudf::table_view(column_views), separator_scalar, - narep_scalar, null_policy); + std::unique_ptr result = cudf::strings::concatenate( + cudf::table_view(column_views), separator_scalar, narep_scalar, null_policy); return reinterpret_cast(result.release()); } 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); std::vector column_views; - std::transform(n_cudf_columns.data(), - n_cudf_columns.data() + n_cudf_columns.size(), + std::transform(n_cudf_columns.data(), n_cudf_columns.data() + n_cudf_columns.size(), std::back_inserter(column_views), [](auto const &p_column) { return *p_column; }); cudf::column_view *column = reinterpret_cast(sep_handle); cudf::strings_column_view strings_column(*column); std::unique_ptr result = - cudf::strings::concatenate(cudf::table_view(column_views), strings_column, - separator_narep_scalar, col_narep_scalar, null_policy); + cudf::strings::concatenate(cudf::table_view(column_views), strings_column, + separator_narep_scalar, col_narep_scalar, null_policy); return reinterpret_cast(result.release()); } CATCH_STD(env, 0); @@ -195,28 +192,25 @@ JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnVector_concatListByRow(JNIEnv 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); std::vector column_views; - std::transform(n_cudf_columns.data(), - n_cudf_columns.data() + n_cudf_columns.size(), + std::transform(n_cudf_columns.data(), n_cudf_columns.data() + n_cudf_columns.size(), std::back_inserter(column_views), [](auto const &p_column) { return *p_column; }); std::unique_ptr result = - cudf::lists::concatenate_rows(cudf::table_view(column_views), null_policy); + cudf::lists::concatenate_rows(cudf::table_view(column_views), null_policy); return reinterpret_cast(result.release()); } 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) { + 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 { @@ -228,7 +222,7 @@ JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnVector_makeList(JNIEnv *env, j children_vector[i] = *children[i]; } auto zero = cudf::make_numeric_scalar(cudf::data_type(cudf::type_id::INT32)); - zero->set_valid(true); + zero->set_valid_async(true); static_cast(zero.get())->set_value(0); if (children.size() == 0) { @@ -236,17 +230,17 @@ JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnVector_makeList(JNIEnv *env, j 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); - ret = cudf::make_lists_column(row_count, std::move(offsets), std::move(empty_col), - 0, rmm::device_buffer()); + ret = cudf::make_lists_column(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(true); + count->set_valid_async(true); 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)); - ret = cudf::make_lists_column(row_count, std::move(offsets), std::move(data_col), - 0, rmm::device_buffer()); + ret = cudf::make_lists_column(row_count, std::move(offsets), std::move(data_col), 0, + rmm::device_buffer()); } return reinterpret_cast(ret.release()); @@ -288,7 +282,6 @@ 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) { JNI_NULL_CHECK(env, column_handles, "input columns are null", 0); @@ -313,12 +306,10 @@ JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnVector_concatenate(JNIEnv *env CATCH_STD(env, 0); } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnVector_hash(JNIEnv *env, - jobject j_object, +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnVector_hash(JNIEnv *env, jobject j_object, jlongArray column_handles, jint hash_function_id, - jintArray initial_values, - jint seed) { + jintArray initial_values, jint seed) { JNI_NULL_CHECK(env, column_handles, "array of column handles is null", 0); JNI_NULL_CHECK(env, initial_values, "array of initial values is null", 0); @@ -330,13 +321,13 @@ JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnVector_hash(JNIEnv *env, [](auto const &p_column) { return *p_column; }); cudf::table_view *input_table = new cudf::table_view(column_views); - cudf::jni::native_jintArray native_iv (env, initial_values); + cudf::jni::native_jintArray native_iv(env, initial_values); std::vector vector_iv; std::transform(native_iv.data(), native_iv.data() + native_iv.size(), - std::back_inserter(vector_iv), - [](auto const &iv) { return iv; }); + std::back_inserter(vector_iv), [](auto const &iv) { return iv; }); - std::unique_ptr result = cudf::hash(*input_table, static_cast(hash_function_id), vector_iv, seed); + std::unique_ptr result = + cudf::hash(*input_table, static_cast(hash_function_id), vector_iv, seed); return reinterpret_cast(result.release()); } CATCH_STD(env, 0); @@ -386,8 +377,7 @@ JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnVector_getNativeColumnView(JNI 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) { diff --git a/java/src/main/native/src/ScalarJni.cpp b/java/src/main/native/src/ScalarJni.cpp index 8939c77f234..e0fad0a60c4 100644 --- a/java/src/main/native/src/ScalarJni.cpp +++ b/java/src/main/native/src/ScalarJni.cpp @@ -161,7 +161,7 @@ JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Scalar_makeBool8Scalar(JNIEnv *env, cudf::jni::auto_set_device(env); std::unique_ptr s = cudf::make_numeric_scalar(cudf::data_type(cudf::type_id::BOOL8)); - s->set_valid(is_valid); + s->set_valid_async(is_valid); if (is_valid) { using ScalarType = cudf::scalar_type_t; int8_t val = value ? 1 : 0; @@ -178,7 +178,7 @@ JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Scalar_makeInt8Scalar(JNIEnv *env, j cudf::jni::auto_set_device(env); std::unique_ptr s = cudf::make_numeric_scalar(cudf::data_type(cudf::type_id::INT8)); - s->set_valid(is_valid); + s->set_valid_async(is_valid); if (is_valid) { using ScalarType = cudf::scalar_type_t; static_cast(s.get())->set_value(static_cast(value)); @@ -194,7 +194,7 @@ JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Scalar_makeUint8Scalar(JNIEnv *env, cudf::jni::auto_set_device(env); std::unique_ptr s = cudf::make_numeric_scalar(cudf::data_type(cudf::type_id::UINT8)); - s->set_valid(is_valid); + s->set_valid_async(is_valid); if (is_valid) { using ScalarType = cudf::scalar_type_t; static_cast(s.get())->set_value(static_cast(value)); @@ -211,7 +211,7 @@ JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Scalar_makeInt16Scalar(JNIEnv *env, cudf::jni::auto_set_device(env); std::unique_ptr s = cudf::make_numeric_scalar(cudf::data_type(cudf::type_id::INT16)); - s->set_valid(is_valid); + s->set_valid_async(is_valid); if (is_valid) { using ScalarType = cudf::scalar_type_t; static_cast(s.get())->set_value(static_cast(value)); @@ -228,7 +228,7 @@ JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Scalar_makeUint16Scalar(JNIEnv *env, cudf::jni::auto_set_device(env); std::unique_ptr s = cudf::make_numeric_scalar(cudf::data_type(cudf::type_id::UINT16)); - s->set_valid(is_valid); + s->set_valid_async(is_valid); if (is_valid) { using ScalarType = cudf::scalar_type_t; static_cast(s.get())->set_value(static_cast(value)); @@ -245,7 +245,7 @@ JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Scalar_makeDurationDaysScalar(JNIEnv cudf::jni::auto_set_device(env); std::unique_ptr s = cudf::make_duration_scalar(cudf::data_type(cudf::type_id::DURATION_DAYS)); - s->set_valid(is_valid); + s->set_valid_async(is_valid); if (is_valid) { using ScalarType = cudf::scalar_type_t; static_cast(s.get())->set_value(static_cast(value)); @@ -261,7 +261,7 @@ JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Scalar_makeInt32Scalar(JNIEnv *env, cudf::jni::auto_set_device(env); std::unique_ptr s = cudf::make_numeric_scalar(cudf::data_type(cudf::type_id::INT32)); - s->set_valid(is_valid); + s->set_valid_async(is_valid); if (is_valid) { using ScalarType = cudf::scalar_type_t; static_cast(s.get())->set_value(static_cast(value)); @@ -277,7 +277,7 @@ JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Scalar_makeUint32Scalar(JNIEnv *env, cudf::jni::auto_set_device(env); std::unique_ptr s = cudf::make_numeric_scalar(cudf::data_type(cudf::type_id::UINT32)); - s->set_valid(is_valid); + s->set_valid_async(is_valid); if (is_valid) { using ScalarType = cudf::scalar_type_t; static_cast(s.get())->set_value(static_cast(value)); @@ -293,7 +293,7 @@ JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Scalar_makeInt64Scalar(JNIEnv *env, cudf::jni::auto_set_device(env); std::unique_ptr s = cudf::make_numeric_scalar(cudf::data_type(cudf::type_id::INT64)); - s->set_valid(is_valid); + s->set_valid_async(is_valid); if (is_valid) { using ScalarType = cudf::scalar_type_t; static_cast(s.get())->set_value(static_cast(value)); @@ -310,7 +310,7 @@ JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Scalar_makeUint64Scalar(JNIEnv *env, cudf::jni::auto_set_device(env); std::unique_ptr s = cudf::make_numeric_scalar(cudf::data_type(cudf::type_id::UINT64)); - s->set_valid(is_valid); + s->set_valid_async(is_valid); if (is_valid) { using ScalarType = cudf::scalar_type_t; static_cast(s.get())->set_value(static_cast(value)); @@ -327,7 +327,7 @@ JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Scalar_makeFloat32Scalar(JNIEnv *env cudf::jni::auto_set_device(env); std::unique_ptr s = cudf::make_numeric_scalar(cudf::data_type(cudf::type_id::FLOAT32)); - s->set_valid(is_valid); + s->set_valid_async(is_valid); if (is_valid) { using ScalarType = cudf::scalar_type_t; static_cast(s.get())->set_value(static_cast(value)); @@ -344,7 +344,7 @@ JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Scalar_makeFloat64Scalar(JNIEnv *env cudf::jni::auto_set_device(env); std::unique_ptr s = cudf::make_numeric_scalar(cudf::data_type(cudf::type_id::FLOAT64)); - s->set_valid(is_valid); + s->set_valid_async(is_valid); if (is_valid) { using ScalarType = cudf::scalar_type_t; static_cast(s.get())->set_value(static_cast(value)); @@ -378,7 +378,7 @@ JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Scalar_makeTimestampDaysScalar(JNIEn cudf::jni::auto_set_device(env); std::unique_ptr s = cudf::make_timestamp_scalar(cudf::data_type(cudf::type_id::TIMESTAMP_DAYS)); - s->set_valid(is_valid); + s->set_valid_async(is_valid); if (is_valid) { using ScalarType = cudf::scalar_type_t; static_cast(s.get())->set_value(static_cast(value)); @@ -396,7 +396,7 @@ JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Scalar_makeDurationTimeScalar(JNIEnv cudf::jni::auto_set_device(env); auto dtype_id = static_cast(jdtype_id); std::unique_ptr s = cudf::make_duration_scalar(cudf::data_type(dtype_id)); - s->set_valid(is_valid); + s->set_valid_async(is_valid); if (is_valid) { using ScalarType = cudf::scalar_type_t; static_cast(s.get())->set_value(static_cast(value)); @@ -414,7 +414,7 @@ JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Scalar_makeTimestampTimeScalar(JNIEn cudf::jni::auto_set_device(env); auto dtype_id = static_cast(jdtype_id); std::unique_ptr s = cudf::make_timestamp_scalar(cudf::data_type(dtype_id)); - s->set_valid(is_valid); + s->set_valid_async(is_valid); if (is_valid) { using ScalarType = cudf::scalar_type_t; static_cast(s.get())->set_value(static_cast(value)); @@ -425,31 +425,30 @@ JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Scalar_makeTimestampTimeScalar(JNIEn } JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Scalar_makeDecimal32Scalar(JNIEnv *env, jclass, - jint value, - jint scale, + 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_); - s->set_valid(is_valid); + std::unique_ptr s = + 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, + 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_); - s->set_valid(is_valid); + std::unique_ptr s = + cudf::make_fixed_point_scalar(value_, scale_); + s->set_valid_async(is_valid); return reinterpret_cast(s.release()); } CATCH_STD(env, 0); @@ -467,8 +466,7 @@ JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Scalar_binaryOpSV(JNIEnv *env, jclas cudf::data_type n_data_type = cudf::jni::make_data_type(out_dtype, scale); cudf::binary_operator op = static_cast(int_op); - std::unique_ptr result = cudf::binary_operation( - *lhs, *rhs, op, n_data_type); + std::unique_ptr result = cudf::binary_operation(*lhs, *rhs, op, n_data_type); return reinterpret_cast(result.release()); } CATCH_STD(env, 0); @@ -486,8 +484,8 @@ JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Scalar_makeListScalar(JNIEnv *env, j // 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); - s->set_valid(is_valid); + cudf::scalar *s = new cudf::list_scalar(*col_view); + s->set_valid_async(is_valid); return reinterpret_cast(s); } CATCH_STD(env, 0); diff --git a/java/src/main/native/src/map_lookup.cu b/java/src/main/native/src/map_lookup.cu index b20daf84fc1..ad791747713 100644 --- a/java/src/main/native/src/map_lookup.cu +++ b/java/src/main/native/src/map_lookup.cu @@ -163,14 +163,14 @@ std::unique_ptr map_contains(column_view const &map_column, string_scala children.push_back(lcv.offsets()); children.push_back(scv.child(0)); - column_view list_of_keys(map_column.type(), map_column.size(), - nullptr, map_column.null_mask(), map_column.null_count(), 0, children); - auto contains_column = lists::contains(list_of_keys, lookup_key); + column_view list_of_keys(map_column.type(), map_column.size(), nullptr, map_column.null_mask(), + map_column.null_count(), 0, children); + auto contains_column = lists::contains(list_of_keys, lookup_key); // null will be skipped in all-aggregation when checking if all rows contain the key, // so replace all nulls with 0. std::unique_ptr replacement = - cudf::make_numeric_scalar(cudf::data_type(cudf::type_id::BOOL8)); - replacement->set_valid(true); + cudf::make_numeric_scalar(cudf::data_type(cudf::type_id::BOOL8)); + replacement->set_valid_async(true); using ScalarType = cudf::scalar_type_t; static_cast(replacement.get())->set_value(0); auto result = cudf::replace_nulls(contains_column->view(), *replacement); @@ -197,9 +197,9 @@ std::unique_ptr map_lookup(column_view const &map_column, string_scalar auto values_column = structs_column.child(1); auto table_for_gather = table_view{std::vector{values_column}}; - auto gathered_table = cudf::detail::gather( - table_for_gather, gather_map->view(), out_of_bounds_policy::NULLIFY, - detail::negative_index_policy::NOT_ALLOWED, stream, mr); + auto gathered_table = + cudf::detail::gather(table_for_gather, gather_map->view(), out_of_bounds_policy::NULLIFY, + detail::negative_index_policy::NOT_ALLOWED, stream, mr); return std::make_unique(std::move(gathered_table->get_column(0))); } diff --git a/java/src/main/native/src/row_conversion.cu b/java/src/main/native/src/row_conversion.cu index 402a592ef99..68f1ae93dec 100644 --- a/java/src/main/native/src/row_conversion.cu +++ b/java/src/main/native/src/row_conversion.cu @@ -494,11 +494,11 @@ std::vector> convert_to_rows(cudf::table_view cons using ScalarType = cudf::scalar_type_t; auto zero = cudf::make_numeric_scalar(cudf::data_type(cudf::type_id::INT32), stream.value()); - zero->set_valid(true, stream); + zero->set_valid_async(true, stream); static_cast(zero.get())->set_value(0, stream); auto step = cudf::make_numeric_scalar(cudf::data_type(cudf::type_id::INT32), stream.value()); - step->set_valid(true, stream); + step->set_valid_async(true, stream); static_cast(step.get()) ->set_value(static_cast(size_per_row), stream); diff --git a/java/src/test/java/ai/rapids/cudf/ScalarTest.java b/java/src/test/java/ai/rapids/cudf/ScalarTest.java index 00de3a696ad..e317392196e 100644 --- a/java/src/test/java/ai/rapids/cudf/ScalarTest.java +++ b/java/src/test/java/ai/rapids/cudf/ScalarTest.java @@ -18,23 +18,20 @@ package ai.rapids.cudf; +import static ai.rapids.cudf.TableTest.assertColumnsAreEqual; +import static org.junit.jupiter.api.Assertions.*; + import ai.rapids.cudf.HostColumnVector.BasicType; import ai.rapids.cudf.HostColumnVector.DataType; import ai.rapids.cudf.HostColumnVector.ListType; import ai.rapids.cudf.HostColumnVector.StructData; import ai.rapids.cudf.HostColumnVector.StructType; - -import org.junit.jupiter.api.Test; - import java.math.BigDecimal; import java.nio.charset.StandardCharsets; import java.util.Arrays; - -import static ai.rapids.cudf.TableTest.assertColumnsAreEqual; -import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.Test; public class ScalarTest extends CudfTestBase { - @Test public void testDoubleClose() { Scalar s = Scalar.fromNull(DType.INT32); @@ -86,8 +83,7 @@ public void testNull() { } // test list scalar with elementType(`type`) - try (Scalar s = Scalar.listFromNull(hDataType); - ColumnView listCv = s.getListAsColumnView()) { + try (Scalar s = Scalar.listFromNull(hDataType); ColumnView listCv = s.getListAsColumnView()) { assertFalse(s.isValid(), "null validity for " + type); assertEquals(DType.LIST, s.getType()); assertEquals(type, listCv.getType()); @@ -186,16 +182,21 @@ public void testDouble() { @Test public void testDecimal() { - BigDecimal[] bigDecimals = new BigDecimal[]{ + BigDecimal[] bigDecimals = new BigDecimal[] { BigDecimal.valueOf(1234, 0), BigDecimal.valueOf(12345678, 2), BigDecimal.valueOf(1234567890123L, 6), }; - for (BigDecimal dec: bigDecimals) { + for (BigDecimal dec : bigDecimals) { try (Scalar s = Scalar.fromDecimal(dec)) { - assertEquals(DType.fromJavaBigDecimal(dec), s.getType()); + DType dtype = DType.fromJavaBigDecimal(dec); + assertEquals(dtype, s.getType()); assertTrue(s.isValid()); - assertEquals(dec.unscaledValue().longValueExact(), s.getLong()); + if (dtype.getTypeId() == DType.DTypeEnum.DECIMAL64) { + assertEquals(dec.unscaledValue().longValueExact(), s.getLong()); + } else { + assertEquals(dec.unscaledValue().intValueExact(), s.getInt()); + } assertEquals(dec, s.getBigDecimal()); } try (Scalar s = Scalar.fromDecimal(-dec.scale(), dec.unscaledValue().intValueExact())) { @@ -260,7 +261,7 @@ public void testString() { assertEquals(DType.STRING, s.getType()); assertTrue(s.isValid()); assertEquals("TEST", s.getJavaString()); - assertArrayEquals(new byte[]{'T', 'E', 'S', 'T'}, s.getUTF8()); + assertArrayEquals(new byte[] {'T', 'E', 'S', 'T'}, s.getUTF8()); } } @@ -270,13 +271,13 @@ public void testUTF8String() { assertEquals(DType.STRING, s.getType()); assertTrue(s.isValid()); assertEquals("TEST", s.getJavaString()); - assertArrayEquals(new byte[]{'T', 'E', 'S', 'T'}, s.getUTF8()); + assertArrayEquals(new byte[] {'T', 'E', 'S', 'T'}, s.getUTF8()); } try (Scalar s = Scalar.fromUTF8String("".getBytes(StandardCharsets.UTF_8))) { assertEquals(DType.STRING, s.getType()); assertTrue(s.isValid()); assertEquals("", s.getJavaString()); - assertArrayEquals(new byte[]{}, s.getUTF8()); + assertArrayEquals(new byte[] {}, s.getUTF8()); } } @@ -293,11 +294,10 @@ public void testList() { } // list of list - HostColumnVector.DataType listDT = new HostColumnVector.ListType(true, - new HostColumnVector.BasicType(true, DType.INT32)); - try (ColumnVector listList = ColumnVector.fromLists(listDT, - Arrays.asList(1, 2, 3), - Arrays.asList(4, 5, 6)); + HostColumnVector.DataType listDT = + new HostColumnVector.ListType(true, new HostColumnVector.BasicType(true, DType.INT32)); + try (ColumnVector listList = + ColumnVector.fromLists(listDT, Arrays.asList(1, 2, 3), Arrays.asList(4, 5, 6)); Scalar s = Scalar.listFromColumnView(listList)) { assertEquals(DType.LIST, s.getType()); assertTrue(s.isValid()); @@ -377,22 +377,20 @@ public void testStruct() { } // test Struct Scalar with nested types - HostColumnVector.DataType listType = new HostColumnVector.ListType(true, - new HostColumnVector.BasicType(true, DType.INT32)); - HostColumnVector.DataType structType = new HostColumnVector.StructType(true, - new HostColumnVector.BasicType(true, DType.INT32), - new HostColumnVector.BasicType(true, DType.INT64)); - HostColumnVector.DataType nestedStructType = new HostColumnVector.StructType(true, - new HostColumnVector.BasicType(true, DType.STRING), - listType, structType); + HostColumnVector.DataType listType = + new HostColumnVector.ListType(true, new HostColumnVector.BasicType(true, DType.INT32)); + HostColumnVector.DataType structType = + new HostColumnVector.StructType(true, new HostColumnVector.BasicType(true, DType.INT32), + new HostColumnVector.BasicType(true, DType.INT64)); + HostColumnVector.DataType nestedStructType = new HostColumnVector.StructType( + true, new HostColumnVector.BasicType(true, DType.STRING), listType, structType); try (ColumnVector strCol = ColumnVector.fromStrings("AAAAAA"); ColumnVector listCol = ColumnVector.fromLists(listType, Arrays.asList(1, 2, 3, 4, 5)); - ColumnVector structCol = ColumnVector.fromStructs(structType, - new HostColumnVector.StructData(1, -1L)); + ColumnVector structCol = + ColumnVector.fromStructs(structType, new HostColumnVector.StructData(1, -1L)); ColumnVector nestedStructCol = ColumnVector.fromStructs(nestedStructType, - new HostColumnVector.StructData(null, - Arrays.asList(1, 2, null), - new HostColumnVector.StructData(null, 10L))); + new HostColumnVector.StructData( + null, Arrays.asList(1, 2, null), new HostColumnVector.StructData(null, 10L))); Scalar s = Scalar.structFromColumnViews(strCol, listCol, structCol, nestedStructCol)) { assertEquals(DType.STRUCT, s.getType()); assertTrue(s.isValid()); diff --git a/python/cudf/cudf/_lib/cpp/scalar/scalar.pxd b/python/cudf/cudf/_lib/cpp/scalar/scalar.pxd index de5cb05447c..feb747a5ccd 100644 --- a/python/cudf/cudf/_lib/cpp/scalar/scalar.pxd +++ b/python/cudf/cudf/_lib/cpp/scalar/scalar.pxd @@ -17,7 +17,7 @@ cdef extern from "cudf/scalar/scalar.hpp" namespace "cudf" nogil: scalar() except + scalar(scalar other) except + data_type type() except + - void set_valid(bool is_valid) except + + void set_valid_async(bool is_valid) except + bool is_valid() except + cdef cppclass numeric_scalar[T](scalar):