Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/macos-support' into macos-support
Browse files Browse the repository at this point in the history
  • Loading branch information
Fixstars-iizuka committed Dec 22, 2023
2 parents cfdfa51 + 28e60c2 commit 2ddf7ac
Show file tree
Hide file tree
Showing 13 changed files with 142 additions and 59 deletions.
6 changes: 3 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ option(WITH_CUDA "Enable CUDA with buliding examples." ON)
# CMake common settings
#
set(CMAKE_C_STANDARD 11)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON) # This is required to export symbols on windows platform
set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH})
Expand All @@ -32,7 +32,7 @@ set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH})
# Dependent libraries
#
find_package(Halide REQUIRED COMPONENTS shared)
if (WITH_CUDA)
if (${WITH_CUDA})
find_package(CUDA REQUIRED)
endif()

Expand Down Expand Up @@ -68,7 +68,7 @@ list(REMOVE_ITEM ION_CORE_SRC "${PROJECT_SOURCE_DIR}/src/generator.cc")
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 m stdc++)
else()
target_link_libraries(ion-core PUBLIC Halide::Halide Halide::Runtime)
endif()
Expand Down
16 changes: 12 additions & 4 deletions cmake/IonUtil.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ function(ion_compile NAME)

# Build compile
add_executable(${NAME} ${IEC_SRCS})
if(UNIX)
if(UNIX AND NOT APPLE)
target_compile_options(${NAME} PUBLIC -fno-rtti) # For Halide::Generator
target_link_options(${NAME} PUBLIC -Wl,--export-dynamic) # For JIT compiling
endif()
IF (APPLE)
target_compile_options(${NAME}
PUBLIC -fno-rtti # For Halide::Generator
PUBLIC -rdynamic) # For JIT compiling
Expand Down Expand Up @@ -104,9 +108,13 @@ function(ion_jit NAME)
set(multiValueArgs SRCS)
cmake_parse_arguments(IEJ "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
add_executable(${NAME} ${IEJ_SRCS})
if (UNIX)
# For JIT compiling
target_compile_options(${NAME} PUBLIC -rdynamic)
if (UNIX AND NOT APPLE)
target_link_options(${NAME} PUBLIC -Wl,--export-dynamic) # For JIT compiling
endif()
if (APPLE)
target_compile_options(${NAME}
PUBLIC -fno-rtti # For Halide::Generator
PUBLIC -rdynamic) # For JIT compiling
endif()
find_package(OpenCV 4 REQUIRED)
target_include_directories(${NAME} PUBLIC ${PROJECT_SOURCE_DIR}/include ${ION_BB_INCLUDE_DIRS} ${OpenCV_INCLUDE_DIRS})
Expand Down
23 changes: 16 additions & 7 deletions include/ion/builder.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

#include "def.h"
#include "buffer.h"
#include "building_block.h"
#include "node.h"
#include "port_map.h"

Expand All @@ -23,15 +22,17 @@ class DynamicModule;
*/
class Builder {
public:
/**
* CompileOption class holds option field for compilation.
*/
struct CompileOption {
std::string output_directory;
};
/**
* CompileOption class holds option field for compilation.
*/
struct CompileOption {
std::string output_directory;
};

Builder();

~Builder();

/**
* Adding new node to the graph.
* @arg k: The key of the node which should be matched with second argument of ION_REGISTER_BUILDING_BLOCK().
Expand Down Expand Up @@ -92,6 +93,13 @@ class Builder {
const std::vector<Node>& nodes() const { return nodes_; }
std::vector<Node>& nodes() { return nodes_; }


/**
* Register disposer hook which will be called from Builder destructor.
* This is available only for JIT mode.
*/
void register_disposer(const std::string& bb_id, const std::string& disposer_symbol);

private:

Halide::Pipeline build(ion::PortMap& ports);
Expand All @@ -108,6 +116,7 @@ class Builder {
std::unique_ptr<Halide::JITUserContext> jit_ctx_;
Halide::JITUserContext* jit_ctx_ptr_;
std::vector<const void*> args_;
std::vector<std::tuple<std::string, std::function<void(const char*)>>> disposers_;
};

} // namespace ion
Expand Down
28 changes: 23 additions & 5 deletions include/ion/building_block.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,10 @@
#include <vector>
#include <Halide.h>

// #include "generator.h"
#include "builder.h"

namespace ion {

template<typename T>
class BuildingBlock : public Halide::Generator<T> {
};

template<typename T>
using GeneratorParam = Halide::GeneratorParam<T>;

Expand All @@ -30,6 +26,28 @@ using Input = Halide::GeneratorInput<T>;
template<typename T>
using Output = Halide::GeneratorOutput<T>;

template<typename T>
class BuildingBlock : public Halide::Generator<T> {

GeneratorParam<uint64_t> builder_ptr{"builder_ptr", 0};
GeneratorParam<std::string> bb_id{"bb_id", ""};

protected:

template<typename... Ts>
void register_disposer(const std::string& n) {
reinterpret_cast<Builder*>(static_cast<uint64_t>(builder_ptr))->register_disposer(bb_id, n);
}

Halide::Buffer<uint8_t> get_id() {
std::string bb_id_s(bb_id);
Buffer<uint8_t> buf(bb_id_s.size() + 1);
buf.fill(0);
std::memcpy(buf.data(), bb_id_s.c_str(), bb_id_s.size());
return buf;
}
};

} // namespace ion

#define ION_REGISTER_BUILDING_BLOCK(...) HALIDE_REGISTER_GENERATOR(__VA_ARGS__)
Expand Down
13 changes: 9 additions & 4 deletions src/bb/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,16 @@ add_library(ion-bb SHARED bb.cc)
target_include_directories(ion-bb PUBLIC ${PROJECT_SOURCE_DIR}/include ${PROJECT_SOURCE_DIR}/src ${CMAKE_CURRENT_SOURCE_DIR} ${ION_BB_INCLUDE_DIRS})
target_link_libraries(ion-bb PUBLIC ion-core ${ION_BB_LIBRARIES})
if(UNIX)
target_compile_options(ion-bb
PUBLIC -fno-rtti # For Halide::Generator
PUBLIC -rdynamic) # For JIT compiling
target_compile_options(ion-bb PUBLIC -fno-rtti) # For Halide::Generator
if(APPLE)
target_compile_options(ion-bb
PUBLIC -fno-rtti # For Halide::Generator
PUBLIC -rdynamic) # For JIT compiling
else()
target_link_options(ion-bb PUBLIC -Wl,--export-dynamic) # For JIT compiling
endif()
elseif(MSVC)
target_compile_options(ion-bb
target_compile_options(ion-bb
PUBLIC /bigobj)
endif()

Expand Down
Loading

0 comments on commit 2ddf7ac

Please sign in to comment.