Skip to content

Commit

Permalink
[luci] Introduce Compress weights pass
Browse files Browse the repository at this point in the history
This commit introduces CopressWeightsPass for Conv2D

ONE-DCO-1.0-Signed-off-by: Vyacheslav Bazhenov <[email protected]>
  • Loading branch information
Vyacheslav Bazhenov committed Sep 12, 2024
1 parent 54b9838 commit a4f7dbf
Show file tree
Hide file tree
Showing 31 changed files with 1,720 additions and 24 deletions.
3 changes: 3 additions & 0 deletions compiler/circle2circle/src/Circle2Circle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,8 @@ int entry(int argc, char **argv)
"This will convert single input Transpose to Reshape");
add_switch(arser, "--expand_broadcast_const", "This will expand broadcastable constant inputs");
add_switch(arser, "--unroll_unidirseqlstm", "Unroll UnidirectionalSequenceLSTM operator.");
add_switch(arser, "--compress_weights_huffman",
"Loseless weights compression with Huffman encoding.");
add_switch(arser, "--convert_nchw_to_nhwc",
"Experimental: This will convert NCHW operators to NHWC under the assumption that "
"input model is NCHW.");
Expand Down Expand Up @@ -343,6 +345,7 @@ int entry(int argc, char **argv)
option_str_to_enum["decompose_softmax"] = Algorithms::DecomposeSoftmaxPass;
option_str_to_enum["expand_broadcast_const"] = Algorithms::ExpandBroadcastConst;
option_str_to_enum["unroll_unidirseqlstm"] = Algorithms::UnrollUnidirSeqLSTM;
option_str_to_enum["compress_weights_huffman"] = Algorithms::CompressWeightsHuffman;
// clang-format on

if (arser.get<bool>("--verbose"))
Expand Down
15 changes: 15 additions & 0 deletions compiler/luci-interpreter/include/luci_interpreter/core/Tensor.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#define LUCI_INTERPRETER_CORE_TENSOR_H

#include "luci_interpreter/core/DataType.h"
#include <luci/IR/AttrWeightCompression.h>

#include <cassert>
#include <cstddef>
Expand Down Expand Up @@ -146,6 +147,8 @@ class Tensor

void resize(const Shape &new_shape);

void resize(const Shape &new_shape, size_t raw_size);

void set_data_buffer(uint8_t *buffer)
{
if (buffer == nullptr)
Expand Down Expand Up @@ -173,11 +176,21 @@ class Tensor

void set_offset(int32_t offset) { _offset = offset; }

luci::CompressionType get_compression() const { return _compression; }

void set_compression(luci::CompressionType compression) { _compression = compression; }

size_t get_raw_size(void) const { return _raw_size; }
void set_raw_size(size_t size) { _raw_size = size; }

private:
DataType _element_type;
Shape _shape;
AffineQuantization _quantization;
uint8_t *_data = nullptr;
// Used for compressed/sparsed tensors when size != WxHxLxD
size_t _raw_size{0};

std::string _name;
bool _data_allocated = false;
// Write of tensor is reported to registered Observers only if this tensor is observable
Expand All @@ -190,6 +203,8 @@ class Tensor
// Used by static memory manager.
// Stores the offset from the beginning of the allocated memory buffer.
int32_t _offset = -1;

luci::CompressionType _compression{luci::CompressionType::NONE};
};

} // namespace luci_interpreter
Expand Down
Loading

0 comments on commit a4f7dbf

Please sign in to comment.