11#include " gpu_columns.hpp"
22#include " gpu_buffer_manager.hpp"
33#include " log/logging.hpp"
4+ #include " duckdb/common/types/decimal.hpp"
45
56namespace duckdb {
67
8+ size_t GPUDecimalTypeInfo::GetDecimalTypeSize () const {
9+ if (width_ <= Decimal::MAX_WIDTH_INT16 ) {
10+ return sizeof (int16_t );
11+ } else if (width_ <= Decimal::MAX_WIDTH_INT32 ) {
12+ return sizeof (int32_t );
13+ } else if (width_ <= Decimal::MAX_WIDTH_INT64 ) {
14+ return sizeof (int64_t );
15+ } else if (width_ <= Decimal::MAX_WIDTH_INT128 ) {
16+ return sizeof (__int128_t );
17+ } else {
18+ throw InternalException (" Decimal has a width of %d which is bigger than the maximum supported width of %d" ,
19+ width_, DecimalType::MaxWidth ());
20+ }
21+ }
22+
723DataWrapper::DataWrapper (GPUColumnType _type, uint8_t * _data, size_t _size) : data(_data), size(_size) {
824 type = _type;
925 num_bytes = size * getColumnTypeSize ();
@@ -14,7 +30,7 @@ DataWrapper::DataWrapper(GPUColumnType _type, uint8_t* _data, uint64_t* _offset,
1430 data (_data), size(_size), type(_type), offset(_offset), num_bytes(_num_bytes), is_string_data(_is_string_data) {};
1531
1632size_t
17- DataWrapper::getColumnTypeSize () {
33+ DataWrapper::getColumnTypeSize () const {
1834 switch (type.id ()) {
1935 case GPUColumnTypeId::INT32 :
2036 case GPUColumnTypeId::DATE :
@@ -31,6 +47,13 @@ DataWrapper::getColumnTypeSize() {
3147 return sizeof (uint8_t );
3248 case GPUColumnTypeId::VARCHAR :
3349 return 128 ;
50+ case GPUColumnTypeId::DECIMAL : {
51+ GPUDecimalTypeInfo* decimal_type_info = type.GetDecimalTypeInfo ();
52+ if (decimal_type_info == nullptr ) {
53+ throw InternalException (" `decimal_type_info` not set for DECIMAL type in `getColumnTypeSize`" );
54+ }
55+ return decimal_type_info->GetDecimalTypeSize ();
56+ }
3457 default :
3558 throw duckdb::InternalException (" Unsupported sirius column type in `getColumnTypeSize()`: %d" ,
3659 static_cast <int >(type.id ()));
@@ -114,6 +137,23 @@ GPUColumn::convertToCudfColumn() {
114137 std::move (children)
115138 );
116139 return str_col;
140+ } else if (data_wrapper.type .id () == GPUColumnTypeId::DECIMAL ) {
141+ cudf::data_type cudf_type;
142+ switch (data_wrapper.getColumnTypeSize ()) {
143+ case sizeof (int32_t ): {
144+ // cudf decimal type uses negative scale, same for below
145+ cudf_type = cudf::data_type (cudf::type_id::DECIMAL32 , -data_wrapper.type .GetDecimalTypeInfo ()->scale_ );
146+ break ;
147+ }
148+ case sizeof (int64_t ): {
149+ cudf_type = cudf::data_type (cudf::type_id::DECIMAL64 , -data_wrapper.type .GetDecimalTypeInfo ()->scale_ );
150+ break ;
151+ }
152+ default :
153+ throw duckdb::InternalException (" Unsupported sirius DECIMAL column type size in `convertToCudfColumn()`: %zu" ,
154+ data_wrapper.getColumnTypeSize ());
155+ }
156+ return cudf::column_view (cudf_type, size, reinterpret_cast <void *>(data_wrapper.data ), nullptr , 0 );
117157 }
118158 throw duckdb::InternalException (" Unsupported sirius column type in `convertToCudfColumn()`: %d" , data_wrapper.type .id ());
119159}
@@ -179,6 +219,27 @@ GPUColumn::setFromCudfColumn(cudf::column& cudf_column, bool _is_unique, int32_t
179219 data_wrapper.type = GPUColumnType (GPUColumnTypeId::BOOLEAN );
180220 data_wrapper.num_bytes = col_size * data_wrapper.getColumnTypeSize ();
181221 data_wrapper.offset = nullptr ;
222+ } else if (col_type == cudf::data_type (cudf::type_id::TIMESTAMP_DAYS )) {
223+ data_wrapper.is_string_data = false ;
224+ data_wrapper.type = GPUColumnType (GPUColumnTypeId::DATE );
225+ data_wrapper.num_bytes = col_size * data_wrapper.getColumnTypeSize ();
226+ data_wrapper.offset = nullptr ;
227+ } else if (col_type.id () == cudf::type_id::DECIMAL32 ) {
228+ data_wrapper.is_string_data = false ;
229+ data_wrapper.type = GPUColumnType (GPUColumnTypeId::DECIMAL );
230+ // cudf decimal type uses negative scale, same for below
231+ data_wrapper.type .SetDecimalTypeInfo (Decimal::MAX_WIDTH_INT32 , -col_type.scale ());
232+ data_wrapper.num_bytes = col_size * data_wrapper.getColumnTypeSize ();
233+ data_wrapper.offset = nullptr ;
234+ } else if (col_type.id () == cudf::type_id::DECIMAL64 ) {
235+ data_wrapper.is_string_data = false ;
236+ data_wrapper.type = GPUColumnType (GPUColumnTypeId::DECIMAL );
237+ data_wrapper.type .SetDecimalTypeInfo (Decimal::MAX_WIDTH_INT64 , -col_type.scale ());
238+ data_wrapper.num_bytes = col_size * data_wrapper.getColumnTypeSize ();
239+ data_wrapper.offset = nullptr ;
240+ } else {
241+ throw NotImplementedException (" Unsupported cudf data type in `setFromCudfColumn`: %d" ,
242+ static_cast <int >(col_type.id ()));
182243 }
183244
184245 if (_row_ids != nullptr ) {
@@ -224,6 +285,24 @@ GPUColumn::setFromCudfScalar(cudf::scalar& cudf_scalar, GPUBufferManager* gpuBuf
224285 callCudaMemcpyDeviceToDevice<uint8_t >(data_wrapper.data , reinterpret_cast <uint8_t *>(typed_scalar.data ()), sizeof (uint8_t ), 0 );
225286 data_wrapper.type = GPUColumnType (GPUColumnTypeId::BOOLEAN );
226287 data_wrapper.num_bytes = sizeof (uint8_t );
288+ } else if (scalar_type.id () == cudf::type_id::DECIMAL32 ){
289+ auto & typed_scalar = static_cast <cudf::fixed_point_scalar<numeric::decimal32>&>(cudf_scalar);
290+ data_wrapper.data = gpuBufferManager->customCudaMalloc <uint8_t >(sizeof (int32_t ), 0 , 0 );
291+ callCudaMemcpyDeviceToDevice<uint8_t >(data_wrapper.data , reinterpret_cast <uint8_t *>(typed_scalar.data ()), sizeof (int32_t ), 0 );
292+ data_wrapper.type = GPUColumnType (GPUColumnTypeId::DECIMAL );
293+ // cudf decimal type uses negative scale, same for below
294+ data_wrapper.type .SetDecimalTypeInfo (Decimal::MAX_WIDTH_INT32 , -typed_scalar.type ().scale ());
295+ data_wrapper.num_bytes = sizeof (int32_t );
296+ } else if (scalar_type.id () == cudf::type_id::DECIMAL64 ){
297+ auto & typed_scalar = static_cast <cudf::fixed_point_scalar<numeric::decimal64>&>(cudf_scalar);
298+ data_wrapper.data = gpuBufferManager->customCudaMalloc <uint8_t >(sizeof (int64_t ), 0 , 0 );
299+ callCudaMemcpyDeviceToDevice<uint8_t >(data_wrapper.data , reinterpret_cast <uint8_t *>(typed_scalar.data ()), sizeof (int64_t ), 0 );
300+ data_wrapper.type = GPUColumnType (GPUColumnTypeId::DECIMAL );
301+ data_wrapper.type .SetDecimalTypeInfo (Decimal::MAX_WIDTH_INT64 , -typed_scalar.type ().scale ());
302+ data_wrapper.num_bytes = sizeof (int64_t );
303+ } else {
304+ throw NotImplementedException (" Unsupported cudf data type in `setFromCudfScalar`: %d" ,
305+ static_cast <int >(scalar_type.id ()));
227306 }
228307
229308 data_wrapper.size = 1 ;
0 commit comments