@@ -240,37 +240,37 @@ __device__ inline void decode_fixed_value(scalar_value_input input,
240240 if (output.valid ) output.valid [index] = true ;
241241}
242242
243- enum class scalar_decode_kind : uint8_t { fixed, varint, zigzag };
243+ enum class scalar_decode_kind : uint8_t { FIXED , VARINT , ZIGZAG };
244244
245245struct scalar_kind {
246246 cudf::type_id type;
247247 scalar_decode_kind decode;
248248 bool operator ==(scalar_kind const &) const = default ;
249249};
250250
251- inline constexpr auto scalar_kinds = std::to_array<scalar_kind>({
252- {cudf::type_id::INT32 , scalar_decode_kind::varint },
253- {cudf::type_id::UINT32 , scalar_decode_kind::varint },
254- {cudf::type_id::INT64 , scalar_decode_kind::varint },
255- {cudf::type_id::UINT64 , scalar_decode_kind::varint },
256- {cudf::type_id::BOOL8 , scalar_decode_kind::varint },
257- {cudf::type_id::INT32 , scalar_decode_kind::zigzag },
258- {cudf::type_id::INT64 , scalar_decode_kind::zigzag },
259- {cudf::type_id::FLOAT32 , scalar_decode_kind::fixed },
260- {cudf::type_id::FLOAT64 , scalar_decode_kind::fixed },
261- {cudf::type_id::INT32 , scalar_decode_kind::fixed },
262- {cudf::type_id::UINT32 , scalar_decode_kind::fixed },
263- {cudf::type_id::INT64 , scalar_decode_kind::fixed },
264- {cudf::type_id::UINT64 , scalar_decode_kind::fixed },
251+ inline constexpr auto SCALAR_KINDS = std::to_array<scalar_kind>({
252+ {cudf::type_id::INT32 , scalar_decode_kind::VARINT },
253+ {cudf::type_id::UINT32 , scalar_decode_kind::VARINT },
254+ {cudf::type_id::INT64 , scalar_decode_kind::VARINT },
255+ {cudf::type_id::UINT64 , scalar_decode_kind::VARINT },
256+ {cudf::type_id::BOOL8 , scalar_decode_kind::VARINT },
257+ {cudf::type_id::INT32 , scalar_decode_kind::ZIGZAG },
258+ {cudf::type_id::INT64 , scalar_decode_kind::ZIGZAG },
259+ {cudf::type_id::FLOAT32 , scalar_decode_kind::FIXED },
260+ {cudf::type_id::FLOAT64 , scalar_decode_kind::FIXED },
261+ {cudf::type_id::INT32 , scalar_decode_kind::FIXED },
262+ {cudf::type_id::UINT32 , scalar_decode_kind::FIXED },
263+ {cudf::type_id::INT64 , scalar_decode_kind::FIXED },
264+ {cudf::type_id::UINT64 , scalar_decode_kind::FIXED },
265265});
266266
267267constexpr scalar_decode_kind get_scalar_decode_kind (cudf::type_id type, proto_encoding encoding)
268268{
269269 using enum cudf::type_id;
270270 using enum proto_encoding;
271- return type == FLOAT32 || type == FLOAT64 || encoding == FIXED ? scalar_decode_kind::fixed
272- : encoding == ZIGZAG ? scalar_decode_kind::zigzag
273- : scalar_decode_kind::varint ;
271+ return type == FLOAT32 || type == FLOAT64 || encoding == FIXED ? scalar_decode_kind::FIXED
272+ : encoding == ZIGZAG ? scalar_decode_kind::ZIGZAG
273+ : scalar_decode_kind::VARINT ;
274274}
275275
276276template <typename T>
@@ -279,52 +279,61 @@ inline scalar_decode_kind get_scalar_decode_kind(proto_encoding encoding)
279279 if constexpr (std::is_floating_point_v<T>) {
280280 CUDF_EXPECTS (encoding == proto_encoding::DEFAULT || encoding == proto_encoding::FIXED ,
281281 " Floating-point protobuf extraction requires default or fixed encoding" );
282- return scalar_decode_kind::fixed;
283282 } else if (encoding == proto_encoding::FIXED ) {
284- if constexpr (sizeof (T) == 4 || sizeof (T) == 8 ) {
285- return scalar_decode_kind::fixed;
286- } else {
287- CUDF_FAIL (" Fixed-width protobuf extraction requires a 32-bit or 64-bit output type" );
288- }
283+ CUDF_EXPECTS (sizeof (T) == 4 || sizeof (T) == 8 ,
284+ " Fixed-width protobuf extraction requires a 32-bit or 64-bit output type" );
289285 } else if constexpr (std::is_signed_v<T>) {
290286 CUDF_EXPECTS (encoding == proto_encoding::DEFAULT || encoding == proto_encoding::ZIGZAG ,
291287 " Signed varint protobuf extraction requires default or zigzag encoding" );
292- return encoding == proto_encoding::ZIGZAG ? scalar_decode_kind::zigzag
293- : scalar_decode_kind::varint;
294- } else {
288+ } else if constexpr (std::is_integral_v<T>) {
295289 CUDF_EXPECTS (encoding == proto_encoding::DEFAULT ,
296290 " Unsigned varint protobuf extraction requires default encoding" );
297- return scalar_decode_kind::varint;
291+ } else {
292+ CUDF_FAIL (" Varint protobuf extraction requires an integral output type" );
293+ }
294+ return get_scalar_decode_kind (
295+ std::is_floating_point_v<T> ? cudf::type_id::FLOAT32 : cudf::type_id::INT32 , encoding);
296+ }
297+
298+ template <typename T, scalar_decode_kind Decode, typename F>
299+ constexpr void dispatch_scalar_decoder (F&& f)
300+ {
301+ if constexpr (Decode == scalar_decode_kind::FIXED ) {
302+ static_assert (sizeof (T) == 4 || sizeof (T) == 8 );
303+ std::forward<F>(f).template operator ()<decode_fixed_value<T>>();
304+ } else if constexpr (Decode == scalar_decode_kind::VARINT ) {
305+ static_assert (std::is_integral_v<T>);
306+ std::forward<F>(f).template operator ()<decode_varint_value<T, false >>();
307+ } else if constexpr (Decode == scalar_decode_kind::ZIGZAG ) {
308+ static_assert (std::is_integral_v<T> && std::is_signed_v<T>);
309+ std::forward<F>(f).template operator ()<decode_varint_value<T, true >>();
310+ } else {
311+ static_assert (Decode == scalar_decode_kind::FIXED || Decode == scalar_decode_kind::VARINT ||
312+ Decode == scalar_decode_kind::ZIGZAG );
298313 }
299314}
300315
301316template <typename T, typename F>
302317inline void dispatch_scalar_decoder (scalar_decode_kind decode, F&& f)
303318{
304319 switch (decode) {
305- case scalar_decode_kind::fixed :
320+ case scalar_decode_kind::FIXED :
306321 if constexpr (sizeof (T) == 4 || sizeof (T) == 8 ) {
307- f.template operator ()<decode_fixed_value<T>>();
308- } else {
309- CUDF_FAIL (" Fixed-width protobuf extraction requires a 32-bit or 64-bit output type" );
322+ return dispatch_scalar_decoder<T, scalar_decode_kind::FIXED >(std::forward<F>(f));
310323 }
311324 break ;
312- case scalar_decode_kind::varint :
325+ case scalar_decode_kind::VARINT :
313326 if constexpr (std::is_integral_v<T>) {
314- f.template operator ()<decode_varint_value<T, false >>();
315- } else {
316- CUDF_FAIL (" Varint protobuf extraction requires an integral output type" );
327+ return dispatch_scalar_decoder<T, scalar_decode_kind::VARINT >(std::forward<F>(f));
317328 }
318329 break ;
319- case scalar_decode_kind::zigzag :
330+ case scalar_decode_kind::ZIGZAG :
320331 if constexpr (std::is_integral_v<T> && std::is_signed_v<T>) {
321- f.template operator ()<decode_varint_value<T, true >>();
322- } else {
323- CUDF_FAIL (" Zigzag protobuf extraction requires a signed integral output type" );
332+ return dispatch_scalar_decoder<T, scalar_decode_kind::ZIGZAG >(std::forward<F>(f));
324333 }
325334 break ;
326- default : CUDF_FAIL (" Unknown protobuf scalar decode kind" );
327335 }
336+ CUDF_UNREACHABLE (" Invalid protobuf scalar decode kind/type combination" );
328337}
329338
330339template <typename OutputType, auto DecodeFn, typename LocationProvider>
@@ -463,23 +472,6 @@ inline std::pair<rmm::device_buffer, cudf::size_type> make_null_mask_from_valid(
463472 return cudf::detail::valid_if (begin, end, pred, stream, mr);
464473}
465474
466- template <typename T, typename LaunchFn>
467- std::unique_ptr<cudf::column> extract_and_build_scalar_column (cudf::data_type dt,
468- int num_rows,
469- LaunchFn&& launch_extract,
470- rmm::cuda_stream_view stream,
471- rmm::device_async_resource_ref mr)
472- {
473- rmm::device_uvector<T> out (num_rows, stream, mr);
474- rmm::device_uvector<bool > valid (num_rows, stream, mr);
475- if (num_rows == 0 ) {
476- return std::make_unique<cudf::column>(dt, 0 , out.release (), rmm::device_buffer{}, 0 );
477- }
478- launch_extract (out.data (), valid.data ());
479- auto [mask, null_count] = make_null_mask_from_valid (valid, num_rows, stream, mr);
480- return std::make_unique<cudf::column>(dt, num_rows, out.release (), std::move (mask), null_count);
481- }
482-
483475template <typename T, typename LocationProvider>
484476inline void extract_scalar_into_buffers (uint8_t const * message_data,
485477 LocationProvider const & loc_provider,
@@ -521,21 +513,20 @@ std::unique_ptr<cudf::column> extract_and_build_scalar_field_column(
521513 rmm::cuda_stream_view stream,
522514 rmm::device_async_resource_ref mr)
523515{
524- return extract_and_build_scalar_column<T>(
525- field.output_type ,
516+ if (num_rows == 0 ) { return cudf::make_empty_column (field.output_type ); }
517+ rmm::device_uvector<T> out (num_rows, stream, mr);
518+ rmm::device_uvector<bool > valid (num_rows, stream, mr);
519+ extract_scalar_into_buffers<T, LocationProvider>(
520+ message_data,
521+ loc_provider,
526522 num_rows,
527- [&](T* out_ptr, bool * valid_ptr) {
528- extract_scalar_into_buffers<T, LocationProvider>(
529- message_data,
530- loc_provider,
531- num_rows,
532- field.schema .encoding ,
533- make_scalar_decode_options<T>(field),
534- {out_ptr, valid_ptr, decode_ctx.error ->data ()},
535- stream);
536- },
537- stream,
538- mr);
523+ field.schema .encoding ,
524+ make_scalar_decode_options<T>(field),
525+ {out.data (), valid.data (), decode_ctx.error ->data ()},
526+ stream);
527+ auto [mask, null_count] = make_null_mask_from_valid (valid, num_rows, stream, mr);
528+ return std::make_unique<cudf::column>(
529+ field.output_type , num_rows, out.release (), std::move (mask), null_count);
539530}
540531
541532template <typename LocationProvider, typename ValidityFn>
@@ -665,9 +656,7 @@ inline std::unique_ptr<cudf::column> extract_typed_column(protobuf_field_decode_
665656 return extract_and_build_scalar_field_column<uint8_t >(
666657 field, message_data, loc_provider, num_items, decode_ctx, stream, mr);
667658 case cudf::type_id::INT32 : {
668- if (num_items == 0 ) {
669- return std::make_unique<cudf::column>(dt, 0 , rmm::device_buffer{}, rmm::device_buffer{}, 0 );
670- }
659+ if (num_items == 0 ) { return cudf::make_empty_column (dt); }
671660 rmm::device_uvector<int32_t > out (num_items, stream, mr);
672661 rmm::device_uvector<bool > valid (num_items, stream, mr);
673662 extract_scalar_into_buffers<int32_t , LocationProvider>(
0 commit comments