Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/port access #164

Merged
merged 11 commits into from
Nov 30, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 27 additions & 27 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ cmake_minimum_required(VERSION 3.6)
# Options
#
if (UNIX)
set(DEFAULT_TARGET_BB "base;dnn;image-io;image-processing;opencv;sgm")
set(DEFAULT_TARGET_BB "base;dnn;image-io;image-processing;opencv;sgm")
else()
set(DEFAULT_TARGET_BB "base;image-io;image-processing;opencv;sgm")
set(DEFAULT_TARGET_BB "base;image-io;image-processing;opencv;sgm")
endif()
set(ION_TARGET_BB ${DEFAULT_TARGET_BB} CACHE STRING "A List of building blocks to build (This overrides ION_BUILD_ALL_BB)")
option(ION_BUILD_DOC "Build documents." OFF)
Expand Down Expand Up @@ -41,12 +41,12 @@ endif()
# Version
#
execute_process(COMMAND git describe --tags
OUTPUT_VARIABLE GIT_DESCRIBE_RESULT
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
OUTPUT_VARIABLE GIT_DESCRIBE_RESULT
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
message(STATUS "Version: ${GIT_DESCRIBE_RESULT}")
string(STRIP "${GIT_DESCRIBE_RESULT}" ION_KIT_VERSION_S)
add_definitions("-DION_KIT_VERSION=\"${ION_KIT_VERSION_S}\"")
string(REPLACE "v" "" ION_KIT_VERSION ${ION_KIT_VERSION_S})
string(REPLACE "v" "" ION_KIT_VERSION "${ION_KIT_VERSION_S}")
file(GENERATE OUTPUT ${CMAKE_BINARY_DIR}/VERSION CONTENT "${ION_KIT_VERSION_S}")

#
Expand All @@ -68,9 +68,9 @@ file(GLOB ION_CORE_SRC LIST_DIRECTORIES false ${PROJECT_SOURCE_DIR}/src/*)
add_library(ion-core SHARED ${ION_CORE_SRC})
target_include_directories(ion-core PUBLIC ${PROJECT_SOURCE_DIR}/include ${PROJECT_SOURCE_DIR}/src)
if (UNIX)
target_link_libraries(ion-core PUBLIC Halide::Halide Halide::Runtime dl pthread z)
target_link_libraries(ion-core PUBLIC Halide::Halide Halide::Runtime dl pthread z)
else()
target_link_libraries(ion-core PUBLIC Halide::Halide Halide::Runtime)
target_link_libraries(ion-core PUBLIC Halide::Halide Halide::Runtime)
endif()

#
Expand Down Expand Up @@ -105,19 +105,19 @@ if (ION_BUILD_DOC)
list(APPEND PUBLIC_HEADERS ${FILES})
set(DOXYGEN_INDEX_FILE ${CMAKE_BINARY_DIR}/xml/index.xml)
add_custom_command(OUTPUT ${DOXYGEN_INDEX_FILE}
COMMAND ${DOXYGEN_EXECUTABLE} ${CMAKE_SOURCE_DIR}/doc/Doxyfile
DEPENDS ${PUBLIC_HEADERS}
MAIN_DEPENDENCY ${CMAKE_SOURCE_DIR}/doc/Doxyfile
COMMENT "Generating docs")
COMMAND ${DOXYGEN_EXECUTABLE} ${CMAKE_SOURCE_DIR}/doc/Doxyfile
DEPENDS ${PUBLIC_HEADERS}
MAIN_DEPENDENCY ${CMAKE_SOURCE_DIR}/doc/Doxyfile
COMMENT "Generating docs")
add_custom_target(Doxygen ALL DEPENDS ${DOXYGEN_INDEX_FILE})

set(SPHINX_INDEX_FILE ${CMAKE_BINARY_DIR}/doc/index.html)
add_custom_command(OUTPUT ${SPHINX_INDEX_FILE}
COMMAND ${SPHINX_EXECUTABLE} -b html
-Dbreathe_projects.ion-core=${CMAKE_BINARY_DIR}/xml
${CMAKE_SOURCE_DIR}/doc ${CMAKE_BINARY_DIR}/doc
DEPENDS ${DOXYGEN_INDEX_FILE}
MAIN_DEPENDENCY ${CMAKE_SOURCE_DIR}/doc/index.rst)
COMMAND ${SPHINX_EXECUTABLE} -b html
-Dbreathe_projects.ion-core=${CMAKE_BINARY_DIR}/xml
${CMAKE_SOURCE_DIR}/doc ${CMAKE_BINARY_DIR}/doc
DEPENDS ${DOXYGEN_INDEX_FILE}
MAIN_DEPENDENCY ${CMAKE_SOURCE_DIR}/doc/index.rst)
add_custom_target(Sphinx ALL DEPENDS ${SPHINX_INDEX_FILE})

install(DIRECTORY ${CMAKE_BINARY_DIR}/doc DESTINATION .)
Expand All @@ -141,14 +141,14 @@ endif()

install(DIRECTORY include DESTINATION .)
install(FILES
${CMAKE_BINARY_DIR}/VERSION
DESTINATION .)
${CMAKE_BINARY_DIR}/VERSION
DESTINATION .)
install(FILES
${CMAKE_SOURCE_DIR}/LICENSE
DESTINATION license)
${CMAKE_SOURCE_DIR}/LICENSE
DESTINATION license)
install(FILES
${CMAKE_SOURCE_DIR}/thirdparty_notice.txt
DESTINATION license)
${CMAKE_SOURCE_DIR}/thirdparty_notice.txt
DESTINATION license)

# Halide
if (ION_BUNDLE_HALIDE)
Expand All @@ -158,10 +158,10 @@ if (ION_BUNDLE_HALIDE)
install(FILES ${HALIDE_HEADERS} DESTINATION include)

file(GLOB HALIDE_BINS
${HALIDE_ROOT}/bin/featurization_to_sample*
${HALIDE_ROOT}/bin/get_host_target*
${HALIDE_ROOT}/bin/retrain_cost_model*
${HALIDE_ROOT}/bin/weightsdir_to_weightsfile*)
${HALIDE_ROOT}/bin/featurization_to_sample*
${HALIDE_ROOT}/bin/get_host_target*
${HALIDE_ROOT}/bin/retrain_cost_model*
${HALIDE_ROOT}/bin/weightsdir_to_weightsfile*)
install(FILES ${HALIDE_BINS} DESTINATION bin)

install(DIRECTORY ${HALIDE_ROOT}/lib/cmake/Halide DESTINATION lib/cmake/)
Expand Down Expand Up @@ -192,4 +192,4 @@ else ()
set(CPACK_GENERATOR "ZIP")
endif ()
set(CPACK_PACKAGE_VERSION ${ION_KIT_VERSION})
include(CPack)
include(CPack)
15 changes: 2 additions & 13 deletions example/gender_count.cc
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What are the changes for?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please review this again?

Original file line number Diff line number Diff line change
Expand Up @@ -25,26 +25,15 @@ int main(int argc, char *argv[]) {
n = b.add("base_reorder_buffer_3d_float")(n["output"]).set_param(Param{"dim0", "2"}, Param{"dim1", "0"}, Param{"dim2", "1"}); // CHW -> HWC

auto img = n["output"];
n = b.add("dnn_tlt_peoplenet")(img);
n = b.add("base_reorder_buffer_3d_float")(n["output"]).set_param(Param{"dim0", "1"}, Param{"dim1", "2"}, Param{"dim2", "0"}); // HWC -> CHW
n = b.add("base_denormalize_3d_uint8")(n["output"]);
n = b.add("image_io_gui_display")(n["output"]).set_param(wparam, hparam);
Port out_p1 = n["output"];

n = b.add("dnn_tlt_peoplenet_md")(img).set_param(wparam, hparam);
n = b.add("dnn_classify_gender")(img, n["output"]).set_param(wparam, hparam);
n = b.add("dnn_json_dict_average_regulator")(n["output"]).set_param(Param{"period_in_sec", "10"});
n = b.add("dnn_ifttt_webhook_uploader")(n["output"]).set_param(Param{"ifttt_webhook_url", "http://maker.ifttt.com/trigger/gender_count/with/key/buf--6AoUjTGu868Pva_Q9"});
Port out_p2 = n["output"];

PortMap pm;
pm.set(wport, width);
pm.set(hport, height);
Halide::Buffer<int32_t> out1 = Halide::Buffer<int32_t>::make_scalar();
pm.set(out_p1, out1);
Halide::Buffer<int32_t> out2 = Halide::Buffer<int32_t>::make_scalar();
pm.set(out_p2, out2);
for (int i=0; i<1000; ++i) {

for (int i=0; i<10; ++i) {
b.run(pm);
}
} catch (const std::exception &e) {
Expand Down
29 changes: 21 additions & 8 deletions include/ion/port.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,15 +147,15 @@ class Port {
friend class Node;

Port()
: key_(), type_(), dimensions_(0), node_id_(), param_info_() {}
: key_(), type_(), dimensions_(0), index_(-1), node_id_(), param_info_() {}

/**
* Construct new port for scalar value.
* @arg k: The key of the port which should be matched with BuildingBlock Input/Output name.
* @arg t: The type of the value.
*/
Port(const std::string& k, Halide::Type t)
: key_(k), type_(t), dimensions_(0), node_id_(), param_info_(new ParamContainer(k, t)) {}
: key_(k), type_(t), dimensions_(0), index_(-1), node_id_(), param_info_(new ParamContainer(k, t)) {}

/**
* Construct new port for vector value.
Expand All @@ -164,7 +164,7 @@ class Port {
* @arg d: The dimension of the port. The range is 1 to 4.
*/
Port(const std::string& k, Halide::Type t, int32_t d)
: key_(k), type_(t), dimensions_(d), node_id_(), param_info_(new ParamContainer(k, t, d)) {}
: key_(k), type_(t), dimensions_(d), index_(-1), node_id_(), param_info_(new ParamContainer(k, t, d)) {}

std::string key() const { return key_; }
std::string& key() { return key_; }
Expand All @@ -175,6 +175,9 @@ class Port {
int32_t dimensions() const { return dimensions_; }
int32_t& dimensions() { return dimensions_; }

int32_t index() const { return index_; }
int32_t& index() { return index_; }

std::string node_id() const { return node_id_; }
std::string& node_id() { return node_id_; }

Expand Down Expand Up @@ -203,15 +206,25 @@ class Port {
return !node_id_.empty();
}

private:
/**
* This port is bound with some node.
*/
Port(const std::string& k, const std::string& ni) : key_(k), type_(), dimensions_(0), node_id_(ni), param_info_(nullptr){}

/**
* Overloaded operator to set the port index and return a reference to the current port. eg. port[0]
*/
Port operator[](int i) {
this->index_ = i;
return *this;
}

private:
/**
* This port is bound with some node.
*/
Port(const std::string& k, const std::string& ni) : key_(k), type_(), index_(-1), dimensions_(0), node_id_(ni), param_info_(nullptr){}

std::string key_;
Halide::Type type_;
int32_t dimensions_;
int32_t index_;
std::string node_id_;
std::shared_ptr<ParamContainer> param_info_;
};
Expand Down
Loading
Loading