ONE - On-device Neural Engine
Loading...
Searching...
No Matches
HD5ImportAction Class Referencefinal
Collaboration diagram for HD5ImportAction:

Public Member Functions

 HD5ImportAction (const std::string &path)
 
void run (TensorContext &ctx) override
 
- Public Member Functions inherited from nnkit::Action
virtual ~Action ()=default
 

Detailed Description

Definition at line 30 of file Import.cpp.

Constructor & Destructor Documentation

◆ HD5ImportAction()

HD5ImportAction::HD5ImportAction ( const std::string &  path)
inline

Definition at line 33 of file Import.cpp.

33 : _file{path, H5F_ACC_RDONLY}
34 {
35 _value_grp = _file.openGroup(value_grpname());
36 }
std::string value_grpname(void)
Return the name of "value group".
Definition Common.cpp:34

References value_grpname().

Member Function Documentation

◆ run()

void HD5ImportAction::run ( TensorContext ctx)
inlineoverridevirtual

Implements nnkit::Action.

Definition at line 39 of file Import.cpp.

40 {
41 for (uint32_t n = 0; n < ctx.size(); ++n)
42 {
44
45 auto fn = [this](const TensorContext &ctx, uint32_t n, Accessor<float> &t) {
46 const auto name = ctx.name(n);
47
48 auto dataset = _value_grp.openDataSet(value_filename(n));
49
50 // TODO Support non-float tensors
51 assert(dataset.getDataType() == H5::PredType::IEEE_F32BE);
52
53 // TODO Check whether shape is consistent
54 const auto shape = ctx.shape(n);
55
56 std::vector<float> buffer;
57
59 buffer.resize(num_elements(shape));
60
61 dataset.read(buffer.data(), H5::PredType::NATIVE_FLOAT);
62
66
67 LexicalLayout layout{};
68
69 for (IndexEnumerator e{shape}; e.valid(); e.advance())
70 {
71 auto i = e.current();
72 t.at(i) = buffer[layout.offset(shape, i)];
73 }
74
75 // TODO Check name
76 };
77
78 try
79 {
80 ctx.getMutableFloatTensor(n, fn);
81 }
82 catch (const H5::FileIException &)
83 {
84 // Skip if data is not present in HDF5 file
85 }
86 }
87 }
Shape & resize(uint32_t size)
Definition Shape.cpp:36
uint32_t num_elements(const Shape &shape)
The number of elements of a feature map of a given shape.
Definition Shape.h:59
uint64_t num_elements(const Shape &)
Definition Shape.cpp:51
std::string value_filename(uint32_t n)
Return the name of n-th tensor dataset.
Definition Common.cpp:35
virtual void getMutableFloatTensor(uint32_t n, const TypedAccessor< float > &cb)
virtual nncc::core::ADT::tensor::Shape shape(uint32_t n) const =0
virtual std::string name(uint32_t n) const =0
virtual uint32_t size(void) const =0

References nnkit::TensorContext::getMutableFloatTensor(), nnkit::TensorContext::name(), nncc::core::ADT::tensor::num_elements(), nncc::core::ADT::tensor::Shape::resize(), nnkit::TensorContext::shape(), nnkit::TensorContext::size(), and value_filename().

Referenced by package.infer.session::inference().


The documentation for this class was generated from the following file: