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 Aug 21, 2024
1 parent 2b9d81f commit ef1caef
Show file tree
Hide file tree
Showing 60 changed files with 4,684 additions and 52 deletions.
2 changes: 1 addition & 1 deletion Makefile.template
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ prepare_nncc_internal: $(WORKSPACE)
ifeq (,$(findstring android,$(TARGET_OS)))
EXTERNAL_FLATC=$(BUILDTOOL_PATH)/bin/flatc ./nncc configure -DBUILD_GTEST=OFF -DENABLE_TEST=OFF -DEXTERNALS_BUILD_THREADS=$(NPROCS) -DCMAKE_BUILD_TYPE=$(BUILD_TYPE) \
-DCMAKE_INSTALL_PREFIX=$(OVERLAY_FOLDER) \
-DBUILD_WHITELIST="luci;foder;pepper-csv2vec;loco;locop;logo;logo-core;mio-circle08;luci-compute;oops;hermes;hermes-std;angkor;pp;pepper-strcast;pepper-str" \
-DBUILD_WHITELIST="luci;foder;pepper-csv2vec;loco;locop;logo;logo-core;mio-circle09;luci-compute;oops;hermes;hermes-std;angkor;pp;pepper-strcast;pepper-str" \
$(OPTIONS_NNCC)
./nncc build -j$(NPROCS)
cmake --install $(NNCC_FOLDER) $(INSTALL_OPTIONS)
Expand Down
8 changes: 4 additions & 4 deletions compiler/circle-inspect/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
if(NOT TARGET mio_circle08)
if(NOT TARGET mio_circle09)
return()
endif(NOT TARGET mio_circle08)
endif(NOT TARGET mio_circle09)

set(DRIVER "driver/Driver.cpp")

Expand All @@ -10,6 +10,6 @@ add_executable(circle-inspect ${DRIVER} ${SOURCES})
target_include_directories(circle-inspect PRIVATE src)
target_link_libraries(circle-inspect arser)
target_link_libraries(circle-inspect foder)
target_link_libraries(circle-inspect mio_circle08)
target_link_libraries(circle-inspect mio_circle08_helper)
target_link_libraries(circle-inspect mio_circle09)
target_link_libraries(circle-inspect mio_circle09_helper)
target_link_libraries(circle-inspect safemain)
2 changes: 1 addition & 1 deletion compiler/circle-inspect/requires.cmake
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require("arser")
require("foder")
require("mio-circle08")
require("mio-circle09")
require("safemain")
8 changes: 4 additions & 4 deletions compiler/circle-operator/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
if(NOT TARGET mio_circle08)
if(NOT TARGET mio_circle09)
return()
endif(NOT TARGET mio_circle08)
endif(NOT TARGET mio_circle09)

set(DRIVER "driver/Driver.cpp")

Expand All @@ -10,8 +10,8 @@ add_executable(circle-operator ${DRIVER} ${SOURCES})
target_include_directories(circle-operator PRIVATE src)
target_link_libraries(circle-operator arser)
target_link_libraries(circle-operator foder)
target_link_libraries(circle-operator mio_circle08)
target_link_libraries(circle-operator mio_circle08_helper)
target_link_libraries(circle-operator mio_circle09)
target_link_libraries(circle-operator mio_circle09_helper)
target_link_libraries(circle-operator safemain)

install(TARGETS circle-operator DESTINATION bin)
2 changes: 1 addition & 1 deletion compiler/circle-operator/requires.cmake
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require("arser")
require("foder")
require("mio-circle08")
require("mio-circle09")
require("safemain")
8 changes: 4 additions & 4 deletions compiler/circle-tensordump/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
if(NOT TARGET mio_circle08)
if(NOT TARGET mio_circle09)
return()
endif(NOT TARGET mio_circle08)
endif(NOT TARGET mio_circle09)

nnas_find_package(HDF5 COMPONENTS STATIC QUIET)

Expand All @@ -19,8 +19,8 @@ target_include_directories(circle-tensordump PRIVATE ${HDF5_INCLUDE_DIRS})
target_link_libraries(circle-tensordump PRIVATE ${HDF5_CXX_LIBRARIES})
target_link_libraries(circle-tensordump PRIVATE arser)
target_link_libraries(circle-tensordump PRIVATE foder)
target_link_libraries(circle-tensordump PRIVATE mio_circle08)
target_link_libraries(circle-tensordump PRIVATE mio_circle08_helper)
target_link_libraries(circle-tensordump PRIVATE mio_circle09)
target_link_libraries(circle-tensordump PRIVATE mio_circle09_helper)
target_link_libraries(circle-tensordump PRIVATE safemain)

install(TARGETS circle-tensordump DESTINATION bin)
2 changes: 1 addition & 1 deletion compiler/circle-tensordump/requires.cmake
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require("arser")
require("foder")
require("mio-circle08")
require("mio-circle09")
require("safemain")
4 changes: 4 additions & 0 deletions compiler/circle2circle/src/Circle2Circle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,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 @@ -416,6 +418,8 @@ int entry(int argc, char **argv)
options->enable(Algorithms::ExpandBroadcastConst);
if (arser.get<bool>("--unroll_unidirseqlstm"))
options->enable(Algorithms::UnrollUnidirSeqLSTM);
if (arser.get<bool>("--compress_weights_huffman"))
options->enable(Algorithms::CompressWeightsHuffman);

// NOTE Experimental options; these will be removed someday
// Add experimental options here
Expand Down
1 change: 1 addition & 0 deletions compiler/luci-eval-driver/src/EvalDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ void writeDataToFile(const std::string &filename, const char *data, size_t data_

template <typename NodeT> size_t getTensorSize(const NodeT *node)
{
uint32_t tensor_size = loco::size(node->dtype());
uint32_t tensor_size = luci::size(node->dtype());
for (uint32_t i = 0; i < node->rank(); ++i)
tensor_size *= node->dim(i).value();
Expand Down
15 changes: 14 additions & 1 deletion 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 @@ -144,7 +145,7 @@ class Tensor

void writeData(const void *data_ptr, size_t data_size);

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

void set_data_buffer(uint8_t *buffer)
{
Expand Down Expand Up @@ -173,11 +174,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 +201,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 ef1caef

Please sign in to comment.