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 2, 2024
1 parent e0d6140 commit 71c600d
Show file tree
Hide file tree
Showing 67 changed files with 4,126 additions and 79 deletions.
4 changes: 2 additions & 2 deletions 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 All @@ -171,7 +171,7 @@ ifeq (,$(findstring android,$(TARGET_OS)))
@cp compiler/angkor/include/nncc/core/ADT/tensor/Index.h ${OVERLAY_FOLDER}/include/nncc/core/ADT/tensor
@cp compiler/oops/include/oops/InternalExn.h ${OVERLAY_FOLDER}/include/oops
@cp compiler/luci/lang/include/luci/IR/CircleNodes.lst ${OVERLAY_FOLDER}/include/luci/IR
@cp ${NNCC_WORKSPACE}/compiler/mio-circle08/gen/mio/circle/schema_generated.h ${OVERLAY_FOLDER}/include/mio/circle
@cp ${NNCC_WORKSPACE}/compiler/mio-circle09/gen/mio/circle/schema_generated.h ${OVERLAY_FOLDER}/include/mio/circle
@cp -r ${NNCC_WORKSPACE}/overlay/include/flatbuffers ${OVERLAY_FOLDER}/include
@echo "Done prepare-nncc"
endif
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")
8 changes: 4 additions & 4 deletions compiler/circle-verify/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
if(NOT TARGET mio_circle08)
message(STATUS "Skip circle-verify: mio_circle08 not found")
if(NOT TARGET mio_circle09)
message(STATUS "Skip circle-verify: mio_circle09 not found")
return()
endif(NOT TARGET mio_circle08)
endif(NOT TARGET mio_circle09)

file(GLOB_RECURSE SOURCES "src/*.cpp")

add_executable(circle-verify ${SOURCES})
target_include_directories(circle-verify PRIVATE src)
target_link_libraries(circle-verify arser)
target_link_libraries(circle-verify mio_circle08)
target_link_libraries(circle-verify mio_circle09)
target_link_libraries(circle-verify safemain)
target_link_libraries(circle-verify cwrap)
target_link_libraries(circle-verify foder)
2 changes: 1 addition & 1 deletion compiler/circle-verify/requires.cmake
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
require("arser")
require("mio-circle08")
require("mio-circle09")
require("safemain")
require("cwrap")
require("foder")
3 changes: 3 additions & 0 deletions compiler/circle2circle/src/Circle2Circle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,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 @@ -340,6 +342,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
6 changes: 3 additions & 3 deletions compiler/circlechef/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ if(NOT Protobuf_FOUND)
return()
endif(NOT Protobuf_FOUND)

if(NOT TARGET mio_circle08)
message(STATUS "circlechef: SKIP (missing mio-circle08)")
if(NOT TARGET mio_circle09)
message(STATUS "circlechef: SKIP (missing mio-circle09)")
return()
endif(NOT TARGET mio_circle08)
endif(NOT TARGET mio_circle09)

# Recipe Parser
add_subdirectory(proto)
Expand Down
4 changes: 2 additions & 2 deletions compiler/circlechef/circle/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ add_library(circlechef_circle STATIC ${SOURCES})
target_include_directories(circlechef_circle PUBLIC include)
target_include_directories(circlechef_circle PRIVATE src)
target_link_libraries(circlechef_circle circlechef_proto)
target_link_libraries(circlechef_circle mio_circle08)
target_link_libraries(circlechef_circle mio_circle08_helper)
target_link_libraries(circlechef_circle mio_circle09)
target_link_libraries(circlechef_circle mio_circle09_helper)
target_link_libraries(circlechef_circle cwrap)
target_link_libraries(circlechef_circle souschef)
2 changes: 1 addition & 1 deletion compiler/circlechef/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ target_include_directories(circlechef_core PUBLIC include)
target_include_directories(circlechef_core PRIVATE src)
target_link_libraries(circlechef_core PUBLIC circlechef_proto)
target_link_libraries(circlechef_core PUBLIC circlechef_log)
target_link_libraries(circlechef_core PUBLIC mio_circle08)
target_link_libraries(circlechef_core PUBLIC mio_circle09)
target_link_libraries(circlechef_core PUBLIC souschef)
target_link_libraries(circlechef_core PRIVATE nncc_coverage)

Expand Down
2 changes: 1 addition & 1 deletion compiler/circlechef/requires.cmake
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require("arser")
require("cwrap")
require("mio-circle08")
require("mio-circle09")
require("safemain")
require("hermes")
require("hermes-std")
Expand Down
10 changes: 5 additions & 5 deletions compiler/circledump/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
if(NOT TARGET mio_circle08)
message(STATUS "Skip circledump: mio_circle08 not found")
if(NOT TARGET mio_circle09)
message(STATUS "Skip circledump: mio_circle09 not found")
return()
endif(NOT TARGET mio_circle08)
endif(NOT TARGET mio_circle09)

set(DRIVER "driver/Driver.cpp")

Expand All @@ -11,8 +11,8 @@ add_executable(circledump ${DRIVER} ${SOURCES})
target_include_directories(circledump PRIVATE include)
target_link_libraries(circledump arser)
target_link_libraries(circledump foder)
target_link_libraries(circledump mio_circle08)
target_link_libraries(circledump mio_circle08_helper)
target_link_libraries(circledump mio_circle09)
target_link_libraries(circledump mio_circle09_helper)
target_link_libraries(circledump safemain)

install(TARGETS circledump DESTINATION bin)
2 changes: 1 addition & 1 deletion compiler/circledump/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,6 @@ O T(3) ofm

### Dependency

- mio-circle08
- mio-circle09
- safemain
- FlatBuffers
2 changes: 1 addition & 1 deletion compiler/circledump/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")
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 71c600d

Please sign in to comment.