@@ -21,9 +21,10 @@ struct MaterializeNumeric
2121 static std::unique_ptr<cudf::column> Do (const T* input_data,
2222 const uint64_t * row_ids,
2323 uint64_t row_id_count,
24- rmm::device_async_resource_ref mr)
24+ rmm::device_async_resource_ref mr,
25+ rmm::cuda_stream_view stream = rmm::cuda_stream_default)
2526 {
26- auto stream = cudf::get_default_stream ();
27+ // Define the thrust execution policy
2728 rmm::mr::thrust_allocator<uint8_t > thrust_allocator (stream, mr);
2829 auto exec = thrust::cuda::par (thrust_allocator).on (stream);
2930
@@ -55,9 +56,9 @@ struct MaterializeString
5556 {}
5657
5758 // Operator
58- __device__ __forceinline__ cudf::size_type operator ()(uint64_t row_id) const
59+ __device__ __forceinline__ int64_t operator ()(uint64_t row_id) const
5960 {
60- return static_cast <cudf::size_type >(input_offsets[row_id + 1 ] - input_offsets[row_id]);
61+ return static_cast <int64_t >(input_offsets[row_id + 1 ] - input_offsets[row_id]);
6162 }
6263 };
6364
@@ -68,14 +69,14 @@ struct MaterializeString
6869 const uint64_t * row_ids;
6970 const uint64_t * input_offsets;
7071 const uint8_t * input_data;
71- cudf::size_type * output_offsets;
72+ int64_t * output_offsets;
7273 uint8_t * output_data;
7374
7475 // Constructor
7576 CopyData (const uint64_t * row_ids,
7677 const uint64_t * input_offsets,
7778 const uint8_t * input_data,
78- cudf::size_type * output_offsets,
79+ int64_t * output_offsets,
7980 uint8_t * output_data)
8081 : row_ids(row_ids)
8182 , input_offsets(input_offsets)
@@ -101,21 +102,21 @@ struct MaterializeString
101102 const uint64_t * input_offsets,
102103 const uint64_t * row_ids,
103104 uint64_t row_id_count,
104- rmm::device_async_resource_ref mr)
105+ rmm::device_async_resource_ref mr,
106+ rmm::cuda_stream_view stream = rmm::cuda_stream_default)
105107 {
106108 static_assert (std::is_same_v<int32_t , cudf::size_type>); // Sanity check
107109
108- auto stream = cudf::get_default_stream ();
110+ // Define the thrust execution policy
109111 rmm::mr::thrust_allocator<uint8_t > thrust_allocator (stream, mr);
110112 auto exec = thrust::cuda::par (thrust_allocator).on (stream);
111113 uint64_t offset_count = row_id_count + 1 ;
112114
113115 // Allocate temporary string length and output offsets buffer
114- rmm::device_uvector<cudf::size_type > temp_string_lengths (offset_count, stream, mr);
115- rmm::device_uvector<cudf::size_type > output_offsets (offset_count, stream, mr);
116+ rmm::device_uvector<int64_t > temp_string_lengths (offset_count, stream, mr);
117+ rmm::device_uvector<int64_t > output_offsets (offset_count, stream, mr);
116118 // Set the last string length to 0, so that the exclusive scan places the total sum at the end
117- CUDF_CUDA_TRY (
118- cudaMemset (temp_string_lengths.data () + row_id_count, 0 , sizeof (cudf::size_type)));
119+ CUDF_CUDA_TRY (cudaMemset (temp_string_lengths.data () + row_id_count, 0 , sizeof (int64_t )));
119120
120121 // Gather the string lengths
121122 thrust::transform (exec,
@@ -129,16 +130,9 @@ struct MaterializeString
129130 temp_string_lengths.begin (),
130131 temp_string_lengths.end (),
131132 output_offsets.begin (),
132- static_cast <cudf::size_type >(0 ));
133+ static_cast <int64_t >(0 ));
133134 const auto output_bytes = output_offsets.back_element (stream);
134135
135- // Check for overflow
136- if (output_bytes < 0 )
137- {
138- throw InternalException (" Dispatch[Materialize]: String data greater than INT32_MAX "
139- " detedted!" );
140- }
141-
142136 // Allocate output data buffer
143137 rmm::device_uvector<uint8_t > output_data (output_bytes, stream, mr);
144138
@@ -150,7 +144,7 @@ struct MaterializeString
150144 CopyData (row_ids, input_offsets, input_data, output_offsets.data (), output_data.data ()));
151145
152146 // Return a cudf::column
153- auto offsets_col = std::make_unique<cudf::column>(cudf::data_type{cudf::type_id::INT32 },
147+ auto offsets_col = std::make_unique<cudf::column>(cudf::data_type{cudf::type_id::INT64 },
154148 static_cast <cudf::size_type>(offset_count),
155149 output_offsets.release (),
156150 rmm::device_buffer{0 , stream, mr},
@@ -165,7 +159,8 @@ struct MaterializeString
165159
166160// Materialize a GPUColumn directly into a cudf::column
167161std::unique_ptr<cudf::column> GpuDispatcher::DispatchMaterialize (const GPUColumn* input,
168- rmm::device_async_resource_ref mr)
162+ rmm::device_async_resource_ref mr,
163+ rmm::cuda_stream_view stream)
169164{
170165 D_ASSERT (input->row_ids != nullptr );
171166 D_ASSERT (input->row_ids ->size () > 0 );
@@ -179,38 +174,46 @@ std::unique_ptr<cudf::column> GpuDispatcher::DispatchMaterialize(const GPUColumn
179174 return MaterializeNumeric<int32_t >::Do (reinterpret_cast <const int32_t *>(input_data),
180175 input->row_ids ,
181176 input->row_id_count ,
182- mr);
177+ mr,
178+ stream);
183179 case GPUColumnTypeId::INT64 :
184180 return MaterializeNumeric<uint64_t >::Do (reinterpret_cast <const uint64_t *>(input_data),
185181 input->row_ids ,
186182 input->row_id_count ,
187- mr);
183+ mr,
184+ stream);
188185 case GPUColumnTypeId::FLOAT32 :
189186 return MaterializeNumeric<float_t >::Do (reinterpret_cast <const float_t *>(input_data),
190187 input->row_ids ,
191188 input->row_id_count ,
192- mr);
189+ mr,
190+ stream);
193191 case GPUColumnTypeId::FLOAT64 :
194192 return MaterializeNumeric<double_t >::Do (reinterpret_cast <const double_t *>(input_data),
195193 input->row_ids ,
196194 input->row_id_count ,
197- mr);
195+ mr,
196+ stream);
198197 case GPUColumnTypeId::BOOLEAN :
199198 return MaterializeNumeric<bool >::Do (reinterpret_cast <const bool *>(input_data),
200199 input->row_ids ,
201200 input->row_id_count ,
202- mr);
201+ mr,
202+ stream);
203203 case GPUColumnTypeId::DATE :
204- return MaterializeNumeric<cudf::timestamp_D>::Do (reinterpret_cast <const cudf::timestamp_D*>(input_data),
205- input->row_ids ,
206- input->row_id_count ,
207- mr);
204+ return MaterializeNumeric<cudf::timestamp_D>::Do (
205+ reinterpret_cast <const cudf::timestamp_D*>(input_data),
206+ input->row_ids ,
207+ input->row_id_count ,
208+ mr,
209+ stream);
208210 case GPUColumnTypeId::VARCHAR :
209211 return MaterializeString::Do (input_data,
210212 input_offsets,
211213 input->row_ids ,
212214 input->row_id_count ,
213- mr);
215+ mr,
216+ stream);
214217 default :
215218 throw InternalException (" Unsupported sirius column type in `Dispatch[Materialize]`: %d" ,
216219 static_cast <int >(input->data_wrapper .type .id ()));
0 commit comments