Агрегация

This commit is contained in:
2025-12-13 12:31:21 +00:00
parent 6a22dc3ef7
commit ab18d9770f
9 changed files with 112 additions and 148 deletions

View File

@@ -23,13 +23,12 @@ struct GpuRecord {
struct GpuDayStats {
long long day;
double low;
double high;
double open;
double close;
double avg;
double first_ts;
double last_ts;
double open_min;
double open_max;
double close_min;
double close_max;
long long count;
};
extern "C" int gpu_is_available() {
@@ -63,32 +62,30 @@ __global__ void aggregate_kernel(
GpuDayStats stats;
stats.day = day_indices[d];
stats.low = DBL_MAX;
stats.high = -DBL_MAX;
stats.first_ts = DBL_MAX;
stats.last_ts = -DBL_MAX;
stats.open = 0;
stats.close = 0;
stats.open_min = DBL_MAX;
stats.open_max = -DBL_MAX;
stats.close_min = DBL_MAX;
stats.close_max = -DBL_MAX;
stats.count = count;
double avg_sum = 0.0;
for (int i = 0; i < count; i++) {
const GpuRecord& r = records[offset + i];
// min/max
if (r.low < stats.low) stats.low = r.low;
if (r.high > stats.high) stats.high = r.high;
// Accumulate avg = (low + high) / 2
avg_sum += (r.low + r.high) / 2.0;
// first/last по timestamp
if (r.timestamp < stats.first_ts) {
stats.first_ts = r.timestamp;
stats.open = r.open;
}
if (r.timestamp > stats.last_ts) {
stats.last_ts = r.timestamp;
stats.close = r.close;
}
// min/max Open
if (r.open < stats.open_min) stats.open_min = r.open;
if (r.open > stats.open_max) stats.open_max = r.open;
// min/max Close
if (r.close < stats.close_min) stats.close_min = r.close;
if (r.close > stats.close_max) stats.close_max = r.close;
}
stats.avg = (stats.low + stats.high) / 2.0;
stats.avg = avg_sum / static_cast<double>(count);
out_stats[d] = stats;
}