Skip to content

Commit 60dfdd0

Browse files
committed
Fix hdf5 offset compute
1 parent 0984ccc commit 60dfdd0

File tree

4 files changed

+29
-41
lines changed

4 files changed

+29
-41
lines changed

src/AMSlib/ml/surrogate.cpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "AMS.h"
1212
#include "surrogate.hpp"
1313
#include "wf/debug.h"
14+
#include "wf/utils.hpp"
1415

1516
using namespace ams;
1617
static std::string getDTypeAsString(torch::Dtype dtype)
@@ -247,7 +248,9 @@ std::tuple<torch::Tensor, torch::Tensor> SurrogateModel::evaluate(
247248
}
248249

249250
auto ITensor = torch::cat(ConvertedInputs, CAxis);
250-
std::cout << "Input concatenated tensor is " << ITensor.sizes() << "\n";
251+
DBG(Surrogate,
252+
"Input concatenated tensor is %s",
253+
shapeToString(ITensor).c_str());
251254

252255
auto [OTensor, Predicate] = _evaluate(ITensor, policy, threshold);
253256
if (InputDevice != torch_device) {

src/AMSlib/wf/hdf5db.cpp

+10-9
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,9 @@ void hdf5DB::writeDataToDataset(ams::MutableArrayRef<hsize_t> currentShape,
196196

197197
// Prepare the dataset for new data
198198
ams::SmallVector<hsize_t> newShape(tensor_dims.begin(), tensor_dims.end());
199+
199200
newShape[0] += currentShape[0]; // Update the first dimension
201+
200202
status = H5Dset_extent(dset, newShape.data());
201203
if (status < 0) {
202204
throw std::runtime_error("Failed to extend dataset's dimensions.");
@@ -239,7 +241,7 @@ void hdf5DB::writeDataToDataset(ams::MutableArrayRef<hsize_t> currentShape,
239241
}
240242

241243
// Update currentShape
242-
currentShape[0] += newShape[0];
244+
currentShape[0] = newShape[0];
243245

244246
// Close HDF5 objects
245247
H5Sclose(memSpace);
@@ -250,8 +252,8 @@ void hdf5DB::writeDataToDataset(ams::MutableArrayRef<hsize_t> currentShape,
250252
void hdf5DB::_store(const at::Tensor& inputs, const at::Tensor& outputs)
251253
{
252254
DBG(DB,
253-
"DB of type %s stores input/output tensors of shapes(%s, "
254-
"%s)",
255+
"DB of type %s stores input/output tensors of shapes %s, "
256+
"%s",
255257
type().c_str(),
256258
tensorSizeToString(inputs.sizes()).c_str(),
257259
tensorSizeToString(outputs.sizes()).c_str());
@@ -262,6 +264,11 @@ void hdf5DB::_store(const at::Tensor& inputs, const at::Tensor& outputs)
262264

263265
writeDataToDataset(currentInputShape, HDIset, inputs);
264266
writeDataToDataset(currentOutputShape, HDOset, outputs);
267+
DBG(DB,
268+
"DB (file:%s) next elements to be stored at Input:%s Output: %s",
269+
fn.c_str(),
270+
SmallVectorToString(currentOutputShape).c_str(),
271+
SmallVectorToString(currentInputShape).c_str());
265272
}
266273

267274

@@ -321,13 +328,7 @@ void hdf5DB::store(ArrayRef<torch::Tensor> Inputs,
321328
c10::SmallVector<torch::Tensor> ConvertedInputs(Inputs.begin(), Inputs.end());
322329
c10::SmallVector<torch::Tensor> ConvertedOutputs(Outputs.begin(),
323330
Outputs.end());
324-
for (auto& T : ConvertedInputs) {
325-
std::cout << "CI Shape is " << T.sizes() << "\n";
326-
}
327331

328-
for (auto& T : ConvertedOutputs) {
329-
std::cout << "CO Shape is " << T.sizes() << "\n";
330-
}
331332
auto inputs =
332333
torch::cat(ConvertedInputs, Inputs[0].sizes().size() - 1).to(tOptions);
333334
auto outputs =

src/AMSlib/wf/interface.cpp

-11
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,9 @@ static ams::SmallVector<ams::AMSTensor> torchToAMSTensors(
8181
auto shapes = ArrayRef(tensor.sizes().begin(), tensor.strides().size());
8282
auto strides = ArrayRef(tensor.strides().begin(), tensor.strides().size());
8383
if (dType == AMSDType::AMS_SINGLE) {
84-
std::cout << "Setting pointer " << tensor.data_ptr<float>() << "\n";
8584
ams_tensors.push_back(
8685
AMSTensor::view(tensor.data_ptr<float>(), shapes, strides, rType));
8786
} else if (dType == AMSDType::AMS_DOUBLE) {
88-
std::cout << "Setting pointer " << tensor.data_ptr<double>() << "\n";
8987
ams_tensors.push_back(
9088
AMSTensor::view(tensor.data_ptr<double>(), shapes, strides, rType));
9189
}
@@ -138,14 +136,5 @@ void callAMS(ams::AMSWorkflow *executor,
138136
ams::SmallVector<torch::Tensor> tinouts = amsToTorchTensors(inouts);
139137
ams::SmallVector<torch::Tensor> touts = amsToTorchTensors(outs);
140138

141-
for (auto &TI : tins)
142-
std::cout << "ITensor Shape is " << TI.sizes() << "\n";
143-
for (auto &TIO : tinouts)
144-
std::cout << "IOTensor Shape is " << TIO.sizes() << "\n";
145-
146-
for (auto &TO : touts)
147-
std::cout << "OTensor Shape is " << TO.sizes() << "\n";
148-
149-
150139
executor->evaluate(Physics, tins, tinouts, touts);
151140
}

src/AMSlib/wf/workflow.hpp

+15-20
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "macro.h"
2222
#include "ml/surrogate.hpp"
2323
#include "resource_manager.hpp"
24+
#include "utils.hpp"
2425
#include "wf/basedb.hpp"
2526
#include "wf/debug.h"
2627

@@ -189,9 +190,6 @@ class AMSWorkflow
189190
}
190191
for (int i = 0; i < computedDomain.size(); i++) {
191192
auto indexed_shape = computedDomain[i].sizes();
192-
std::cout << "Scattering outputs " << entireDomain[i].sizes() << " CD "
193-
<< computedDomain[i].sizes() << " Predicate "
194-
<< Predicate.sizes() << "\n";
195193
entireDomain[i].index_put_({Predicate},
196194
computedDomain[i].view(indexed_shape));
197195
}
@@ -208,9 +206,6 @@ class AMSWorkflow
208206
int ConcatAxisSize = dst.sizes()[dst.dim() - 1];
209207
torch::Tensor Slice =
210208
Src.narrow(outerDim, offset, ConcatAxisSize).to(dst.options());
211-
std::cout << "Slice Shape is:" << Slice.sizes() << "\n";
212-
std::cout << "Dst shape is " << dst.sizes() << "\n";
213-
std::cout << "Predicate is " << Predicate.sizes() << "\n";
214209
dst.index_put_({Predicate}, Slice.index({Predicate}));
215210
offset += ConcatAxisSize;
216211
}
@@ -278,12 +273,23 @@ class AMSWorkflow
278273
InOuts.size(),
279274
Outs.size());
280275

276+
std::string msg{"ApplicationInput: [ "};
281277
for (auto &TI : Ins)
282-
std::cout << "ITensor Shape is " << TI.sizes() << "\n";
278+
msg += shapeToString(TI) + " ";
279+
msg += "]";
280+
DBG(Workflow, "%s", msg.c_str());
281+
282+
msg = "ApplicationInOut: [ ";
283283
for (auto &TIO : InOuts)
284-
std::cout << "IOTensor Shape is " << TIO.sizes() << "\n";
284+
msg += shapeToString(TIO) + " ";
285+
msg += "]";
286+
DBG(Workflow, "%s", msg.c_str());
287+
288+
msg = "ApplicationOutput: [ ";
285289
for (auto &TO : Outs)
286-
std::cout << "OTensor Shape is " << TO.sizes() << "\n";
290+
msg += shapeToString(TO) + " ";
291+
msg += "]";
292+
DBG(Workflow, "%s", msg.c_str());
287293

288294

289295
SmallVector<torch::Tensor> InputTensors(Ins.begin(), Ins.end());
@@ -373,22 +379,11 @@ class AMSWorkflow
373379
PhysicInOutsBefore.push_back(S.clone());
374380

375381

376-
for (auto &TI : PhysicIns)
377-
std::cout << "Before Phy ITensor Shape is " << TI.sizes() << "\n";
378-
for (auto &TO : PhysicOuts)
379-
std::cout << "Before Phy OTensor Shape is " << TO.sizes() << "\n";
380-
381-
382382
// We call the application here
383383
CALIPER(CALI_MARK_BEGIN("PHYSICS MODULE");)
384384
callApplication(CallBack, PhysicIns, PhysicInOuts, PhysicOuts);
385385
CALIPER(CALI_MARK_END("PHYSICS MODULE");)
386386

387-
for (auto &TI : PhysicIns)
388-
std::cout << "After Phy ITensor Shape is " << TI.sizes() << "\n";
389-
for (auto &TO : PhysicOuts)
390-
std::cout << "After Phy OTensor Shape is " << TO.sizes() << "\n";
391-
392387

393388
CALIPER(CALI_MARK_BEGIN("UNPACK");)
394389
// Copy out the computation results to the original tensors/buffers

0 commit comments

Comments
 (0)