wrote equivalent python code

This commit is contained in:
Robin
2024-12-26 17:34:41 +01:00
parent 3c8e68ac1d
commit 274622157a
2 changed files with 37 additions and 9 deletions

View File

@@ -1,4 +1,4 @@
// #include "hurricanedata/fielddata.h"
#include "hurricanedata/fielddata.h"
#include "hurricanedata/gpubufferhandler.h"
#include "hurricanedata/datareader.h"
#include "hurricanedata/gpubuffer.h"
@@ -10,9 +10,10 @@
#include <memory>
#include <iomanip>
__global__ void getSingleValue(float *ans, const FieldMetadata &fmd, FieldData fd) {
float xi = getVal(fmd, fd, 1, 20, 100, 100);
*ans = xi;
__global__ void middleOfTwoValues(float *ans, const FieldMetadata &fmd, FieldData fd) {
float xi = getVal(fmd, fd, 0, 20, 100, 100);
float yi = getVal(fmd, fd, 1, 20, 100, 100);
*ans = (xi+yi)/2;
}
int main() {
@@ -20,7 +21,6 @@ int main() {
std::string variable = "T";
// std::unique_ptr<DataReader> dataReader = std::make_unique<DataReader>(path, variable);
DataReader dataReader{path, variable};
std::cout << "created datareader\n";
@@ -38,16 +38,14 @@ int main() {
for (int i = 0; i < 10; i++) {
FieldData fd = bufferHandler.nextFieldData();
getSingleValue<<<1, 1>>>(ptr_test_read, *bufferHandler.fmd, fd);
middleOfTwoValues<<<1, 1>>>(ptr_test_read, *bufferHandler.fmd, fd);
cudaDeviceSynchronize();
std::cout << "ptr_test_read = " << std::fixed << std::setprecision(6) << *ptr_test_read << "\n";
}
// TODO: Write an example loop using buffering and measure it.
// TODO: Free data properly in FieldData (maybe make an iterator)
// TODO: measure data transfer time in this example code.
cudaFree(ptr_test_read);
return 0;
}