--- /dev/null
+#include <nnkit/Action.h>
+
+#include <nncc/core/ADT/tensor/IndexRange.h>
+#include <nncc/core/ADT/tensor/LexicalLayout.h>
+
+#include <H5Cpp.h>
+
+using nnkit::TensorContext;
+
+class HD5ExportAction final : public nnkit::Action
+{
+public:
+ HD5ExportAction(const std::string &path) : _file{path, H5F_ACC_TRUNC}
+ {
+ // DO NOTHING
+ }
+
+public:
+ void run(TensorContext &ctx) override
+ {
+ for (uint32_t n = 0; n < ctx.size(); ++n)
+ {
+ using nncc::core::ADT::tensor::Reader;
+
+ // TODO Support other data types
+ auto fn = [this] (const TensorContext &ctx, uint32_t n, const Reader<float> &t)
+ {
+ const auto shape = ctx.shape(n);
+
+ const auto rank = shape.rank();
+
+ hsize_t dims[rank];
+
+ for (uint32_t axis = 0; axis < rank; ++axis)
+ {
+ dims[axis] = shape.dim(axis);
+ }
+
+ H5::DataSpace dataspace(rank, dims);
+
+ auto dataset = _file.createDataSet(ctx.name(n), H5::PredType::IEEE_F32BE, dataspace);
+
+ float *data = new float[nncc::core::ADT::tensor::num_elements(shape)];
+
+ using nncc::core::ADT::tensor::range;
+ using nncc::core::ADT::tensor::Index;
+ using nncc::core::ADT::tensor::LexicalLayout;
+
+ LexicalLayout layout{};
+
+ range(shape).iterate() << [data, &t, &shape, &layout] (const Index &i)
+ {
+ data[layout.offset(shape, i)] = t.at(i);
+ };
+
+ dataset.write(data, H5::PredType::NATIVE_FLOAT);
+
+ delete[] data;
+ };
+
+ ctx.getConstFloatTensor(n, fn);
+ }
+ }
+
+private:
+ H5::H5File _file;
+};
+
+#include <nnkit/CmdlineArguments.h>
+#include <nncc/foundation/Memory.h>
+
+extern "C" std::unique_ptr<nnkit::Action> make_action(const nnkit::CmdlineArguments &args)
+{
+ return nncc::foundation::make_unique<HD5ExportAction>(args.at(0));
+}