Skip to content

Commit 34c0b9a

Browse files
committed
Merge branch 'main' into type_decimal
2 parents f2eb2cb + 4860082 commit 34c0b9a

4 files changed

Lines changed: 41 additions & 2 deletions

File tree

src/cuda/utils.cu

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ __global__ void convert_int64_to_int128(uint8_t *input, uint8_t *output, size_t
3535
// for (int i = 0; i < 8; ++i) {
3636
// output[idx * 16 + i] = input[idx * 8 + i];
3737
// output[idx * 16 + i + 8] = 0;
38-
output_ptr[0] = input_ptr[0];
39-
output_ptr[1] = 0; // Set the upper 64 bits to zero
38+
// output_ptr[0] = input_ptr[0];
39+
// output_ptr[1] = 0; // Set the upper 64 bits to zero
4040
// }
4141
}
4242
}
@@ -56,6 +56,16 @@ __global__ void convert_int32_to_int128(uint8_t *input, uint8_t *output, size_t
5656
}
5757
}
5858

59+
__global__ void convert_int32_to_int64(uint8_t *input, uint8_t *output, size_t count) {
60+
size_t idx = blockIdx.x * blockDim.x + threadIdx.x;
61+
if (idx < count) {
62+
// Store the converted value as 16 bytes in output
63+
int32_t* input_ptr = reinterpret_cast<int32_t*>(input + idx * 4);
64+
int64_t* output_ptr = reinterpret_cast<int64_t*>(output + idx * 8);
65+
output_ptr[0] = input_ptr[0];
66+
}
67+
}
68+
5969
void warmup_gpu() {
6070
// Perform the warmup
6171
cudaFree(0);
@@ -85,4 +95,15 @@ void convertInt32ToInt128(uint8_t *input, uint8_t *output, size_t count) {
8595
cudaDeviceSynchronize();
8696
}
8797

98+
void convertInt32ToInt64(uint8_t *input, uint8_t *output, size_t count) {
99+
if (count == 0) return;
100+
101+
// Launch the kernel to convert the data
102+
size_t threads_per_block = 256;
103+
size_t blocks = (count + threads_per_block - 1) / threads_per_block;
104+
105+
convert_int32_to_int64<<<blocks, threads_per_block>>>(input, output, count);
106+
cudaDeviceSynchronize();
107+
}
108+
88109
} // namespace duckdb

src/include/utils.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@ namespace duckdb {
77
void warmup_gpu();
88
void convertInt64ToInt128(uint8_t *input, uint8_t *output, size_t count);
99
void convertInt32ToInt128(uint8_t *input, uint8_t *output, size_t count);
10+
void convertInt32ToInt64(uint8_t *input, uint8_t *output, size_t count);
1011

1112
} // namespace duckdb

src/operator/gpu_physical_grouped_aggregate.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include "gpu_buffer_manager.hpp"
55
#include "gpu_materialize.hpp"
66
#include "log/logging.hpp"
7+
#include "utils.hpp"
78

89
namespace duckdb {
910

@@ -304,6 +305,14 @@ HandleGroupByAggregateCuDF(vector<shared_ptr<GPUColumn>> &group_by_keys, vector<
304305
agg_mode[agg_idx] = AggregationType::SUM;
305306
} else if (expr.function.name.compare("sum_no_overflow") == 0 && aggregate_keys[agg_idx]->data_wrapper.data != nullptr) {
306307
agg_mode[agg_idx] = AggregationType::SUM;
308+
if (aggregate_keys[agg_idx]->data_wrapper.type.id() == GPUColumnTypeId::INT32) {
309+
SIRIUS_LOG_DEBUG("Converting INT32 to INT64 for sum_no_overflow");
310+
uint64_t* temp = gpuBufferManager->customCudaMalloc<uint64_t>(aggregate_keys[agg_idx]->column_length, 0, 0);
311+
convertInt32ToInt64(aggregate_keys[agg_idx]->data_wrapper.data, reinterpret_cast<uint8_t*>(temp), aggregate_keys[agg_idx]->column_length);
312+
aggregate_keys[agg_idx]->data_wrapper.data = reinterpret_cast<uint8_t*>(temp);
313+
aggregate_keys[agg_idx]->data_wrapper.type = GPUColumnType(GPUColumnTypeId::INT64);
314+
aggregate_keys[agg_idx]->data_wrapper.num_bytes = aggregate_keys[agg_idx]->data_wrapper.num_bytes * 2;
315+
}
307316
} else if (expr.function.name.compare("avg") == 0 && aggregate_keys[agg_idx]->data_wrapper.data != nullptr) {
308317
agg_mode[agg_idx] = AggregationType::AVERAGE;
309318
} else if (expr.function.name.compare("max") == 0 && aggregate_keys[agg_idx]->data_wrapper.data != nullptr) {

src/operator/gpu_physical_ungrouped_aggregate.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,14 @@ HandleAggregateExpressionCuDF(vector<shared_ptr<GPUColumn>> &aggregate_keys, GPU
119119
agg_mode[agg_idx] = AggregationType::SUM;
120120
} else if (expr.function.name.compare("sum_no_overflow") == 0 && aggregate_keys[agg_idx]->data_wrapper.data != nullptr) {
121121
agg_mode[agg_idx] = AggregationType::SUM;
122+
if (aggregate_keys[agg_idx]->data_wrapper.type.id() == GPUColumnTypeId::INT32) {
123+
SIRIUS_LOG_DEBUG("Converting INT32 to INT64 for sum_no_overflow");
124+
uint64_t* temp = gpuBufferManager->customCudaMalloc<uint64_t>(aggregate_keys[agg_idx]->column_length, 0, 0);
125+
convertInt32ToInt64(aggregate_keys[agg_idx]->data_wrapper.data, reinterpret_cast<uint8_t*>(temp), aggregate_keys[agg_idx]->column_length);
126+
aggregate_keys[agg_idx]->data_wrapper.data = reinterpret_cast<uint8_t*>(temp);
127+
aggregate_keys[agg_idx]->data_wrapper.type = GPUColumnType(GPUColumnTypeId::INT64);
128+
aggregate_keys[agg_idx]->data_wrapper.num_bytes = aggregate_keys[agg_idx]->data_wrapper.num_bytes * 2;
129+
}
122130
} else if (expr.function.name.compare("avg") == 0 && aggregate_keys[agg_idx]->data_wrapper.data != nullptr) {
123131
agg_mode[agg_idx] = AggregationType::AVERAGE;
124132
} else if (expr.function.name.compare("max") == 0 && aggregate_keys[agg_idx]->data_wrapper.data != nullptr) {

0 commit comments

Comments
 (0)