99#include " gpu_buffer_manager.hpp"
1010#include " gpu_materialize.hpp"
1111#include " log/logging.hpp"
12+ #include " utils.hpp"
1213
1314namespace duckdb {
1415
@@ -174,6 +175,8 @@ LogicalType ColumnTypeToLogicalType(ColumnType type) {
174175 return LogicalType::BOOLEAN ;
175176 case ColumnType::VARCHAR :
176177 return LogicalType::VARCHAR ;
178+ case ColumnType::INT128 :
179+ return LogicalType::HUGEINT ;
177180 default :
178181 throw NotImplementedException (" Unsupported column type" );
179182 }
@@ -192,6 +195,8 @@ Vector rawDataToVector(uint8_t* host_data, size_t vector_offset, ColumnType type
192195 sizeof_type = sizeof (double ); break ;
193196 case ColumnType::BOOLEAN :
194197 sizeof_type = sizeof (uint8_t ); break ;
198+ case ColumnType::INT128 :
199+ sizeof_type = 2 * sizeof (uint64_t ); break ;
195200 default :
196201 throw NotImplementedException (" Unsupported column type" );
197202 }
@@ -231,8 +236,8 @@ SinkResultType GPUPhysicalMaterializedCollector::Sink(GPUIntermediateRelation &i
231236 char * all_columns_chars = reinterpret_cast <char *>(combined_buffer + all_columns_strings_buffer_size);
232237
233238 size_t size_bytes = 0 ;
234- Allocator& allocator = Allocator::DefaultAllocator ();
235239 uint8_t ** host_data = gpuBufferManager->customCudaHostAlloc <uint8_t *>(input_relation.columns .size ());
240+
236241 GPUIntermediateRelation materialized_relation (input_relation.columns .size ());
237242 string_t ** duckdb_strings = gpuBufferManager->customCudaHostAlloc <string_t *>(input_relation.columns .size ());
238243 string_t * curr_column_string_buffer = all_columns_string;
@@ -249,9 +254,26 @@ SinkResultType GPUPhysicalMaterializedCollector::Sink(GPUIntermediateRelation &i
249254 ColumnType col_type = input_relation.columns [col]->data_wrapper .type ;
250255 bool is_string = false ;
251256 if (col_type != ColumnType::VARCHAR ) {
252- // host_data[col] = allocator.AllocateData(size_bytes);
253- host_data[col] = gpuBufferManager->customCudaHostAlloc <uint8_t >(size_bytes);
254- callCudaMemcpyDeviceToHost<uint8_t >(host_data[col], materialized_relation.columns [col]->data_wrapper .data , size_bytes, 0 );
257+ if (types[col].InternalType () == PhysicalType::INT128 ) {
258+ if (materialized_relation.columns [col]->data_wrapper .type == ColumnType::INT64 ) {
259+ SIRIUS_LOG_DEBUG (" Converting INT64 to INT128 for column {}" , col);
260+ uint8_t * temp_int128 = gpuBufferManager->customCudaMalloc <uint8_t >(size_bytes * 2 , 0 , 0 );
261+ convertInt64ToInt128 (materialized_relation.columns [col]->data_wrapper .data , temp_int128, materialized_relation.columns [col]->column_length );
262+ host_data[col] = gpuBufferManager->customCudaHostAlloc <uint8_t >(size_bytes * 2 );
263+ callCudaMemcpyDeviceToHost<uint8_t >(host_data[col], temp_int128, size_bytes * 2 , 0 );
264+ } else if (materialized_relation.columns [col]->data_wrapper .type == ColumnType::INT32 ) {
265+ SIRIUS_LOG_DEBUG (" Converting INT32 to INT128 for column {}" , col);
266+ uint8_t * temp_int128 = gpuBufferManager->customCudaMalloc <uint8_t >(size_bytes * 4 , 0 , 0 );
267+ convertInt32ToInt128 (materialized_relation.columns [col]->data_wrapper .data , temp_int128, materialized_relation.columns [col]->column_length );
268+ host_data[col] = gpuBufferManager->customCudaHostAlloc <uint8_t >(size_bytes * 4 );
269+ callCudaMemcpyDeviceToHost<uint8_t >(host_data[col], temp_int128, size_bytes * 4 , 0 );
270+ } else {
271+ throw NotImplementedException (" Unsupported column type for INT128 conversion" );
272+ }
273+ } else {
274+ host_data[col] = gpuBufferManager->customCudaHostAlloc <uint8_t >(size_bytes);
275+ callCudaMemcpyDeviceToHost<uint8_t >(host_data[col], materialized_relation.columns [col]->data_wrapper .data , size_bytes, 0 );
276+ }
255277 } else {
256278 // Use the helper method to materialize the string on the GPU
257279 shared_ptr<GPUColumn> str_column = materialized_relation.columns [col];
@@ -284,8 +306,13 @@ SinkResultType GPUPhysicalMaterializedCollector::Sink(GPUIntermediateRelation &i
284306 chunk.InitializeEmpty (types);
285307 for (int col = 0 ; col < materialized_relation.columns .size (); col++) {
286308 if (materialized_relation.columns [col]->data_wrapper .type != ColumnType::VARCHAR ) {
287- Vector vector = rawDataToVector (host_data[col], vec, materialized_relation.columns [col]->data_wrapper .type );
288- chunk.data [col].Reference (vector);
309+ if (types[col].InternalType () == PhysicalType::INT128 ) {
310+ Vector vector = rawDataToVector (host_data[col], vec, ColumnType::INT128 );
311+ chunk.data [col].Reference (vector);
312+ } else {
313+ Vector vector = rawDataToVector (host_data[col], vec, materialized_relation.columns [col]->data_wrapper .type );
314+ chunk.data [col].Reference (vector);
315+ }
289316 } else {
290317 // Add the strings to the vector
291318 Vector str_vector (LogicalType::VARCHAR , reinterpret_cast <data_ptr_t >(duckdb_strings[col] + read_index));
0 commit comments