mirror of
https://github.com/MartinOpat/cuda-based-raytrace.git
synced 2025-06-07 02:13:10 +02:00
possibly loaded 3d array to device?
This commit is contained in:
4
.gitignore
vendored
4
.gitignore
vendored
@@ -1,3 +1,3 @@
|
|||||||
build
|
build/
|
||||||
.vscode
|
.vscode
|
||||||
data
|
data/
|
||||||
BIN
build/main
BIN
build/main
Binary file not shown.
BIN
build/main.o
BIN
build/main.o
Binary file not shown.
@@ -22,4 +22,33 @@ std::vector<float> readData(std::string path, std::string variableName) {
|
|||||||
var.getVar(vec.data());
|
var.getVar(vec.data());
|
||||||
|
|
||||||
return vec;
|
return vec;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct cudaArray* loadDataToDevice(std::string path, std::string variableName) {
|
||||||
|
netCDF::NcFile data(path, netCDF::NcFile::read);
|
||||||
|
|
||||||
|
multimap<string, NcVar> vars = data.getVars();
|
||||||
|
|
||||||
|
NcVar var = vars.find(variableName)->second;
|
||||||
|
|
||||||
|
struct cudaChannelFormatDesc arrayType = {
|
||||||
|
.x = 32,
|
||||||
|
.y = 0,
|
||||||
|
.z = 0,
|
||||||
|
.w = 0,
|
||||||
|
.f = cudaChannelFormatKindFloat
|
||||||
|
}; // Float-32
|
||||||
|
|
||||||
|
struct cudaExtent extent = {
|
||||||
|
.width = var.getDim(3).getSize(), // longitude
|
||||||
|
.height = var.getDim(2).getSize(), // latitude
|
||||||
|
.depth = var.getDim(1).getSize(), // level
|
||||||
|
};
|
||||||
|
|
||||||
|
struct cudaArray *array;
|
||||||
|
|
||||||
|
cudaError_t error = cudaMalloc3DArray(&array, &arrayType, extent, 0);
|
||||||
|
cout << "cuda error: " << error << "\n";
|
||||||
|
|
||||||
|
return array;
|
||||||
}
|
}
|
||||||
@@ -5,5 +5,6 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
std::vector<float> readData(std::string path, std::string variableName);
|
std::vector<float> readData(std::string path, std::string variableName);
|
||||||
|
struct cudaArray* loadDataToDevice(std::string path, std::string variableName);
|
||||||
|
|
||||||
#endif //DATAREADER_H
|
#endif //DATAREADER_H
|
||||||
|
|||||||
11
src/main.cu
11
src/main.cu
@@ -8,15 +8,8 @@
|
|||||||
int main() {
|
int main() {
|
||||||
std::string path = "data/MERRA2_400.inst6_3d_ana_Np.20120101.nc4";
|
std::string path = "data/MERRA2_400.inst6_3d_ana_Np.20120101.nc4";
|
||||||
std::string variable = "U";
|
std::string variable = "U";
|
||||||
auto x = readData(path, variable);
|
auto arr = loadDataToDevice(path, variable);
|
||||||
|
cudaFreeArray(arr);
|
||||||
// Print some values from the file to see that it worked
|
|
||||||
int num = 0;
|
|
||||||
for(int i = 0; i < x.size(); i++) {
|
|
||||||
if (x[i] < 1E14) std::cout << x[i] << "\n";
|
|
||||||
if(num > 10000) break;
|
|
||||||
num++;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user