mirror of
https://github.com/MartinOpat/cuda-based-raytrace.git
synced 2025-06-07 02:13:10 +02:00
still need to modify datareader to use netcdf on only one thread
This commit is contained in:
59
src/main.cu
59
src/main.cu
@@ -1,19 +1,35 @@
|
||||
#include "hurricanedata/fielddata.h"
|
||||
// #include "hurricanedata/fielddata.h"
|
||||
// #include "hurricanedata/gpubufferhandler.h"
|
||||
#include "hurricanedata/datareader.h"
|
||||
#include "hurricanedata/gpubuffer.h"
|
||||
|
||||
#include <cuda_runtime.h>
|
||||
#include <device_launch_parameters.h>
|
||||
#include <iostream>
|
||||
#include <cmath>
|
||||
#include <memory>
|
||||
#include <iomanip>
|
||||
|
||||
|
||||
// Not parallel computation
|
||||
__global__ void computeMean(float *ans, const FieldMetadata &fmd, FieldData fd) {
|
||||
// __global__ void computeMean(float *ans, const FieldMetadata &fmd, FieldData fd) {
|
||||
// float sum = 0;
|
||||
// size_t num_not_masked_values = 0;
|
||||
// for (int i = 0; i < fmd.widthSize; i++) {
|
||||
// double xi = getVal(fmd, fd, 2, 20, 100, i);
|
||||
// if (xi < 1E14) { /* If x is not missing value */
|
||||
// num_not_masked_values++;
|
||||
// sum += xi;
|
||||
// }
|
||||
// }
|
||||
// *ans = sum/num_not_masked_values;
|
||||
// }
|
||||
|
||||
__global__ void computeMean(float *ans, DataHandle dh) {
|
||||
float sum = 0;
|
||||
size_t num_not_masked_values = 0;
|
||||
for (int i = 0; i < fmd.widthSize; i++) {
|
||||
double xi = getVal(fmd, fd, 2, 20, 100, i);
|
||||
for (int i = 0; i < dh.size; i++) {
|
||||
double xi = dh.d_data[i];
|
||||
if (xi < 1E14) { /* If x is not missing value */
|
||||
num_not_masked_values++;
|
||||
sum += xi;
|
||||
@@ -23,22 +39,37 @@ __global__ void computeMean(float *ans, const FieldMetadata &fmd, FieldData fd)
|
||||
}
|
||||
|
||||
int main() {
|
||||
std::string path = "data/MERRA2_400.inst6_3d_ana_Np.20120101.nc4";
|
||||
std::string path = "data";
|
||||
|
||||
std::string variable = "T";
|
||||
GPUBuffer buffer{path, variable};
|
||||
|
||||
auto fd = buffer.nextFieldData();
|
||||
// std::unique_ptr<DataReader> dataReader = std::make_unique<DataReader>(path, variable);
|
||||
DataReader dataReader{path, variable};
|
||||
|
||||
float *ptr_mean;
|
||||
cudaMallocManaged(&ptr_mean, sizeof(float));
|
||||
std::cout << "created datareader\n";
|
||||
|
||||
computeMean<<<1, 1>>>(ptr_mean, *buffer.fmd, fd);
|
||||
GPUBuffer buffer (dataReader);
|
||||
|
||||
cudaDeviceSynchronize();
|
||||
std::cout << "created buffer\n";
|
||||
|
||||
std::cout << "Mean = " << std::fixed << std::setprecision(6) << *ptr_mean << "\n";
|
||||
auto dataHandle = buffer.getDataHandle(0);
|
||||
|
||||
cudaFree(fd.valArrays[0]);
|
||||
cudaFree(ptr_mean);
|
||||
// std::cout << "got a data handle\n";
|
||||
|
||||
// GPUBufferHandler buffer{path, variable};
|
||||
|
||||
// auto fd = buffer.nextFieldData();
|
||||
|
||||
// float *ptr_mean;
|
||||
// cudaMallocManaged(&ptr_mean, sizeof(float));
|
||||
|
||||
// computeMean<<<1, 1>>>(ptr_mean, dataHandle);
|
||||
|
||||
// cudaDeviceSynchronize();
|
||||
|
||||
// std::cout << "Mean = " << std::fixed << std::setprecision(6) << *ptr_mean << "\n";
|
||||
|
||||
// // cudaFree(fd.valArrays[0]);
|
||||
// cudaFree(ptr_mean);
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user