possibly loaded 3d array to device?
This commit is contained in:
parent
1c2ab4af76
commit
2719b93fa6
|
|
@ -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.
|
|
@ -23,3 +23,32 @@ std::vector<float> readData(std::string path, std::string variableName) {
|
||||||
|
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue