Skip to content

Commit aa80d45

Browse files
authored
Expose stream-ordering in scalar and avro APIs (#17766)
Contributes to #13744 Replaces conversion operators in derived classes of `cudf::scalar` with stream-ordered `get_value(stream)` member function. Adds stream parameter to `cudf::io::read_avro` Authors: - Shruti Shivakumar (https://github.com/shrshi) - Vyas Ramasubramani (https://github.com/vyasr) Approvers: - Bradley Dice (https://github.com/bdice) - Vukasin Milovanovic (https://github.com/vuule) - David Wendt (https://github.com/davidwendt) - https://github.com/nvdbaranec URL: #17766
1 parent 433799b commit aa80d45

File tree

7 files changed

+70
-37
lines changed

7 files changed

+70
-37
lines changed

cpp/include/cudf/io/avro.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2020-2024, NVIDIA CORPORATION.
2+
* Copyright (c) 2020-2025, NVIDIA CORPORATION.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -208,13 +208,15 @@ class avro_reader_options_builder {
208208
* @endcode
209209
*
210210
* @param options Settings for controlling reading behavior
211+
* @param stream CUDA stream used for device memory operations and kernel launches
211212
* @param mr Device memory resource used to allocate device memory of the table in the returned
212213
* table_with_metadata
213214
*
214215
* @return The set of columns along with metadata
215216
*/
216217
table_with_metadata read_avro(
217218
avro_reader_options const& options,
219+
rmm::cuda_stream_view stream = cudf::get_default_stream(),
218220
rmm::device_async_resource_ref mr = cudf::get_current_device_resource_ref());
219221

220222
/** @} */ // end of group

cpp/include/cudf/scalar/scalar.hpp

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2019-2024, NVIDIA CORPORATION.
2+
* Copyright (c) 2019-2025, NVIDIA CORPORATION.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -176,11 +176,6 @@ class fixed_width_scalar : public scalar {
176176
*/
177177
void set_value(T value, rmm::cuda_stream_view stream = cudf::get_default_stream());
178178

179-
/**
180-
* @brief Explicit conversion operator to get the value of the scalar on the host.
181-
*/
182-
explicit operator value_type() const;
183-
184179
/**
185180
* @brief Get the value of the scalar.
186181
*
@@ -402,11 +397,6 @@ class fixed_point_scalar : public scalar {
402397
[[nodiscard]] T fixed_point_value(
403398
rmm::cuda_stream_view stream = cudf::get_default_stream()) const;
404399

405-
/**
406-
* @brief Explicit conversion operator to get the value of the scalar on the host.
407-
*/
408-
explicit operator value_type() const;
409-
410400
/**
411401
* @brief Returns a raw pointer to the value in device memory.
412402
* @return A raw pointer to the value in device memory
@@ -515,11 +505,6 @@ class string_scalar : public scalar {
515505
rmm::cuda_stream_view stream = cudf::get_default_stream(),
516506
rmm::device_async_resource_ref mr = cudf::get_current_device_resource_ref());
517507

518-
/**
519-
* @brief Explicit conversion operator to get the value of the scalar in a host std::string.
520-
*/
521-
explicit operator std::string() const;
522-
523508
/**
524509
* @brief Get the value of the scalar in a host std::string.
525510
*

cpp/src/io/functions.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,9 @@ std::vector<std::unique_ptr<data_sink>> make_datasinks(sink_info const& info)
189189

190190
} // namespace
191191

192-
table_with_metadata read_avro(avro_reader_options const& options, rmm::device_async_resource_ref mr)
192+
table_with_metadata read_avro(avro_reader_options const& options,
193+
rmm::cuda_stream_view stream,
194+
rmm::device_async_resource_ref mr)
193195
{
194196
namespace avro = cudf::io::detail::avro;
195197

@@ -199,7 +201,7 @@ table_with_metadata read_avro(avro_reader_options const& options, rmm::device_as
199201

200202
CUDF_EXPECTS(datasources.size() == 1, "Only a single source is currently supported.");
201203

202-
return avro::read_avro(std::move(datasources[0]), options, cudf::get_default_stream(), mr);
204+
return avro::read_avro(std::move(datasources[0]), options, stream, mr);
203205
}
204206

205207
table_with_metadata read_json(json_reader_options options,

cpp/src/scalar/scalar.cpp

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2019-2024, NVIDIA CORPORATION.
2+
* Copyright (c) 2019-2025, NVIDIA CORPORATION.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -110,8 +110,6 @@ size_type string_scalar::size() const { return _data.size(); }
110110

111111
char const* string_scalar::data() const { return static_cast<char const*>(_data.data()); }
112112

113-
string_scalar::operator std::string() const { return this->to_string(cudf::get_default_stream()); }
114-
115113
std::string string_scalar::to_string(rmm::cuda_stream_view stream) const
116114
{
117115
std::string result(size(), '\0');
@@ -183,12 +181,6 @@ T fixed_point_scalar<T>::fixed_point_value(rmm::cuda_stream_view stream) const
183181
numeric::scaled_integer<rep_type>{_data.value(stream), numeric::scale_type{type().scale()}}};
184182
}
185183

186-
template <typename T>
187-
fixed_point_scalar<T>::operator value_type() const
188-
{
189-
return this->fixed_point_value(cudf::get_default_stream());
190-
}
191-
192184
template <typename T>
193185
typename fixed_point_scalar<T>::rep_type* fixed_point_scalar<T>::data()
194186
{
@@ -266,12 +258,6 @@ T const* fixed_width_scalar<T>::data() const
266258
return _data.data();
267259
}
268260

269-
template <typename T>
270-
fixed_width_scalar<T>::operator value_type() const
271-
{
272-
return this->value(cudf::get_default_stream());
273-
}
274-
275261
/**
276262
* @brief These define the valid fixed-width scalar types.
277263
*

cpp/tests/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -725,6 +725,7 @@ ConfigureTest(STREAM_REPLACE_TEST streams/replace_test.cpp STREAM_MODE testing)
725725
ConfigureTest(STREAM_RESHAPE_TEST streams/reshape_test.cpp STREAM_MODE testing)
726726
ConfigureTest(STREAM_ROLLING_TEST streams/rolling_test.cpp STREAM_MODE testing)
727727
ConfigureTest(STREAM_ROUND_TEST streams/round_test.cpp STREAM_MODE testing)
728+
ConfigureTest(STREAM_SCALAR_TEST streams/scalar_test.cpp STREAM_MODE testing)
728729
ConfigureTest(STREAM_SEARCH_TEST streams/search_test.cpp STREAM_MODE testing)
729730
ConfigureTest(STREAM_SORTING_TEST streams/sorting_test.cpp STREAM_MODE testing)
730731
ConfigureTest(STREAM_STREAM_COMPACTION_TEST streams/stream_compaction_test.cpp STREAM_MODE testing)

cpp/tests/binaryop/assert-binops.h

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2019-2023, NVIDIA CORPORATION.
2+
* Copyright (c) 2019-2025, NVIDIA CORPORATION.
33
*
44
* Copyright 2018-2019 BlazingDB, Inc.
55
* Copyright 2018 Christian Noboa Mardini <[email protected]>
@@ -69,6 +69,20 @@ struct NearEqualComparator {
6969
}
7070
};
7171

72+
template <typename TypeLhs, typename ScalarType>
73+
TypeLhs scalar_host_value(cudf::scalar const& lhs)
74+
{
75+
auto sclr = static_cast<ScalarType const&>(lhs);
76+
auto stream = cudf::get_default_stream();
77+
if constexpr (std::is_same_v<ScalarType, cudf::string_scalar>) {
78+
return sclr.to_string(stream);
79+
} else if constexpr (std::is_same_v<ScalarType, cudf::fixed_point_scalar<TypeLhs>>) {
80+
return sclr.fixed_point_value(stream);
81+
} else {
82+
return sclr.value(stream);
83+
}
84+
}
85+
7286
template <typename TypeOut,
7387
typename TypeLhs,
7488
typename TypeRhs,
@@ -81,7 +95,7 @@ void ASSERT_BINOP(cudf::column_view const& out,
8195
TypeOp&& op,
8296
ValueComparator const& value_comparator = ValueComparator())
8397
{
84-
auto lhs_h = static_cast<ScalarType const&>(lhs).operator TypeLhs();
98+
auto lhs_h = scalar_host_value<TypeLhs, ScalarType>(lhs);
8599
auto rhs_h = cudf::test::to_host<TypeRhs>(rhs);
86100
auto rhs_data = rhs_h.first;
87101
auto out_h = cudf::test::to_host<TypeOut>(out);
@@ -129,7 +143,7 @@ void ASSERT_BINOP(cudf::column_view const& out,
129143
TypeOp&& op,
130144
ValueComparator const& value_comparator = ValueComparator())
131145
{
132-
auto rhs_h = static_cast<ScalarType const&>(rhs).operator TypeRhs();
146+
auto rhs_h = scalar_host_value<TypeRhs, ScalarType>(rhs);
133147
auto lhs_h = cudf::test::to_host<TypeLhs>(lhs);
134148
auto lhs_data = lhs_h.first;
135149
auto out_h = cudf::test::to_host<TypeOut>(out);

cpp/tests/streams/scalar_test.cpp

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* Copyright (c) 2025, NVIDIA CORPORATION.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#include <cudf_test/base_fixture.hpp>
18+
#include <cudf_test/default_stream.hpp>
19+
#include <cudf_test/type_lists.hpp>
20+
21+
#include <cudf/scalar/scalar.hpp>
22+
23+
template <typename T>
24+
struct TypedScalarTest : public cudf::test::BaseFixture {};
25+
26+
TYPED_TEST_SUITE(TypedScalarTest, cudf::test::FixedWidthTypes);
27+
28+
TYPED_TEST(TypedScalarTest, DefaultValidity)
29+
{
30+
using Type = cudf::device_storage_type_t<TypeParam>;
31+
Type value = static_cast<Type>(cudf::test::make_type_param_scalar<TypeParam>(7));
32+
cudf::scalar_type_t<TypeParam> s(value, true, cudf::test::get_default_stream());
33+
EXPECT_EQ(value, s.value(cudf::test::get_default_stream()));
34+
}
35+
36+
struct StringScalarTest : public cudf::test::BaseFixture {};
37+
38+
TEST_F(StringScalarTest, DefaultValidity)
39+
{
40+
std::string value = "test string";
41+
auto s = cudf::string_scalar(value, true, cudf::test::get_default_stream());
42+
EXPECT_EQ(value, s.to_string(cudf::test::get_default_stream()));
43+
}

0 commit comments

Comments
 (0)