From 5ca71543e84410e3736ea8bf4118f7f47d3711ca Mon Sep 17 00:00:00 2001 From: Xinyu Li Date: Tue, 2 Apr 2024 09:52:13 -0700 Subject: [PATCH 1/3] update to halide17 --- .github/workflows/linux.yml | 2 +- .github/workflows/macos.yml | 2 +- .github/workflows/release.yml | 6 +++--- .github/workflows/windows.yml | 2 +- CMakeLists.txt | 3 +++ include/ion/port.h | 14 +++++++------- src/port.cc | 2 +- src/serializer.h | 2 +- 8 files changed, 18 insertions(+), 15 deletions(-) diff --git a/.github/workflows/linux.yml b/.github/workflows/linux.yml index 4b26087a..82005e57 100644 --- a/.github/workflows/linux.yml +++ b/.github/workflows/linux.yml @@ -33,7 +33,7 @@ jobs: # Halide mkdir ${HOME}/halide - curl -L https://github.com/halide/Halide/releases/download/v16.0.0/Halide-16.0.0-x86-64-linux-1e963ff817ef0968cc25d811a25a7350c8953ee6.tar.gz | tar zx -C ${HOME}/halide --strip-components 1 + curl -L https://github.com/halide/Halide/releases/download/v17.0.1/Halide-17.0.1-x86-64-linux-52541176253e74467dabc42eeee63d9a62c199f6.tar.gz | tar zx -C ${HOME}/halide --strip-components 1 find ${HOME}/halide -type d | xargs chmod 755 sudo cp -r ${HOME}/halide/* /usr/ diff --git a/.github/workflows/macos.yml b/.github/workflows/macos.yml index 73f14f79..545c408f 100644 --- a/.github/workflows/macos.yml +++ b/.github/workflows/macos.yml @@ -27,7 +27,7 @@ jobs: shell: bash run: | mkdir ${HOME}/Halide - curl -L https://github.com/halide/Halide/releases/download/v16.0.0/Halide-16.0.0-arm-64-osx-1e963ff817ef0968cc25d811a25a7350c8953ee6.tar.gz | tar zx -C ${HOME}/Halide --strip-components 1 + curl -L https://github.com/halide/Halide/releases/download/v17.0.1/Halide-17.0.1-arm-64-osx-52541176253e74467dabc42eeee63d9a62c199f6.tar.gz | tar zx -C ${HOME}/Halide --strip-components 1 find ${HOME}/Halide -type d | xargs chmod 755 - name: Configure diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 265c5bb7..45f125a7 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -27,7 +27,7 @@ jobs: run: | # Halide mkdir ${HOME}/Halide - curl -L https://github.com/halide/Halide/releases/download/v16.0.0/Halide-16.0.0-x86-64-linux-1e963ff817ef0968cc25d811a25a7350c8953ee6.tar.gz | tar zx -C ${HOME}/Halide --strip-components 1 + curl -L https://github.com/halide/Halide/releases/download/v17.0.1/Halide-17.0.1-x86-64-linux-52541176253e74467dabc42eeee63d9a62c199f6.tar.gz | tar zx -C ${HOME}/Halide --strip-components 1 find ${HOME}/Halide -type d | xargs chmod 755 # zlib, libjpeg, libpng @@ -64,7 +64,7 @@ jobs: run: | # Halide mkdir ${HOME}/Halide - curl -L https://github.com/halide/Halide/releases/download/v16.0.0/Halide-16.0.0-x86-64-windows-1e963ff817ef0968cc25d811a25a7350c8953ee6.zip -o Halide.zip + curl -L https://github.com/halide/Halide/releases/download/v17.0.1/Halide-17.0.1-x86-64-windows-52541176253e74467dabc42eeee63d9a62c199f6.zip -o Halide.zip unzip Halide.zip rm Halide.zip mv Halide*/* ${HOME}/Halide @@ -101,7 +101,7 @@ jobs: shell: bash run: | mkdir ${HOME}/Halide - curl -L https://github.com/halide/Halide/releases/download/v16.0.0/Halide-16.0.0-arm-64-osx-1e963ff817ef0968cc25d811a25a7350c8953ee6.tar.gz | tar zx -C ${HOME}/Halide --strip-components 1 + curl -L https://github.com/halide/Halide/releases/download/v17.0.1/Halide-17.0.1-arm-64-osx-52541176253e74467dabc42eeee63d9a62c199f6.tar.gz | tar zx -C ${HOME}/Halide --strip-components 1 find ${HOME}/Halide -type d | xargs chmod 755 - name: Configure diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml index 127366cb..0f05beae 100644 --- a/.github/workflows/windows.yml +++ b/.github/workflows/windows.yml @@ -31,7 +31,7 @@ jobs: run: | # Halide mkdir ${HOME}/Halide - curl -L https://github.com/halide/Halide/releases/download/v16.0.0/Halide-16.0.0-x86-64-windows-1e963ff817ef0968cc25d811a25a7350c8953ee6.zip -o Halide.zip + curl -L https://github.com/halide/Halide/releases/download/v17.0.1/Halide-17.0.1-x86-64-windows-52541176253e74467dabc42eeee63d9a62c199f6.zip -o Halide.zip unzip Halide.zip rm Halide.zip mv Halide*/* ${HOME}/Halide diff --git a/CMakeLists.txt b/CMakeLists.txt index 91ab1ee2..e63dd9f2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -152,6 +152,9 @@ if(UNIX) # On unix-like system, create include unversioned symlink # NOTE: RELEASE/DEBUG doesn't matter for the naming get_target_property(HALIDE_SONAME Halide::Halide IMPORTED_SONAME_RELEASE) + if(APPLE) + string(REPLACE "@rpath/" "" HALIDE_SONAME ${HALIDE_SONAME}) + endif() set(HALIDE_SYMFILE ${CMAKE_BINARY_DIR}/libHalide${CMAKE_SHARED_LIBRARY_SUFFIX}) file(CREATE_LINK ${HALIDE_SONAME} ${HALIDE_SYMFILE} SYMBOLIC) install(FILES ${HALIDE_SYMFILE} DESTINATION lib) diff --git a/include/ion/port.h b/include/ion/port.h index ed36880b..cba34865 100644 --- a/include/ion/port.h +++ b/include/ion/port.h @@ -61,7 +61,7 @@ class Port { Halide::Type type; int32_t dimensions; - std::unordered_map params; + std::unordered_map params; std::unordered_map instances; Impl(); @@ -181,9 +181,9 @@ class Port { void bind(T *v) { auto i = index_ == -1 ? 0 : index_; if (has_pred()) { - impl_->params[i] = Halide::Internal::Parameter{Halide::type_of(), false, 0, argument_name(pred_id(), pred_name(), i, graph_id())}; + impl_->params[i] = Halide::Parameter{Halide::type_of(), false, 0, argument_name(pred_id(), pred_name(), i, graph_id())}; } else { - impl_->params[i] = Halide::Internal::Parameter{type(), false, dimensions(), argument_name(pred_id(), pred_name(), i, graph_id())}; + impl_->params[i] = Halide::Parameter{type(), false, dimensions(), argument_name(pred_id(), pred_name(), i, graph_id())}; } impl_->instances[i] = v; @@ -193,9 +193,9 @@ class Port { void bind(const Halide::Buffer& buf) { auto i = index_ == -1 ? 0 : index_; if (has_pred()) { - impl_->params[i] = Halide::Internal::Parameter{buf.type(), true, buf.dimensions(), argument_name(pred_id(), pred_name(), i,graph_id())}; + impl_->params[i] = Halide::Parameter{buf.type(), true, buf.dimensions(), argument_name(pred_id(), pred_name(), i,graph_id())}; } else { - impl_->params[i] = Halide::Internal::Parameter{type(), true, dimensions(), argument_name(pred_id(), pred_name(), i,graph_id())}; + impl_->params[i] = Halide::Parameter{type(), true, dimensions(), argument_name(pred_id(), pred_name(), i,graph_id())}; } impl_->instances[i] = buf.raw_buffer(); @@ -205,9 +205,9 @@ class Port { void bind(const std::vector>& bufs) { for (int i=0; i(bufs.size()); ++i) { if (has_pred()) { - impl_->params[i] = Halide::Internal::Parameter{bufs[i].type(), true, bufs[i].dimensions(), argument_name(pred_id(), pred_name(), i, graph_id())}; + impl_->params[i] = Halide::Parameter{bufs[i].type(), true, bufs[i].dimensions(), argument_name(pred_id(), pred_name(), i, graph_id())}; } else { - impl_->params[i] = Halide::Internal::Parameter{type(), true, dimensions(), argument_name(pred_id(), pred_name(), i, graph_id())}; + impl_->params[i] = Halide::Parameter{type(), true, dimensions(), argument_name(pred_id(), pred_name(), i, graph_id())}; } impl_->instances[i] = bufs[i].raw_buffer(); diff --git a/src/port.cc b/src/port.cc index 752a8d25..2bc46e48 100644 --- a/src/port.cc +++ b/src/port.cc @@ -13,7 +13,7 @@ Port::Impl::Impl() Port::Impl::Impl(const NodeID & nid, const std::string& pn, const Halide::Type& t, int32_t d, const GraphID & gid) : id(PortID(sole::uuid4().str())), pred_chan{nid, pn}, succ_chans{}, type(t), dimensions(d), graph_id(gid) { - params[0] = Halide::Internal::Parameter(type, dimensions != 0, dimensions, argument_name(nid, pn, 0, gid)); + params[0] = Halide::Parameter(type, dimensions != 0, dimensions, argument_name(nid, pn, 0, gid)); } void Port::determine_succ(const NodeID& nid, const std::string& old_pn, const std::string& new_pn) { diff --git a/src/serializer.h b/src/serializer.h index 92ee377e..2b304d8a 100644 --- a/src/serializer.h +++ b/src/serializer.h @@ -68,7 +68,7 @@ struct adl_serializer { impl->type = j["type"].get(); impl->dimensions = j["dimensions"]; for (auto i=0; iparams[i] = Halide::Internal::Parameter(impl->type, impl->dimensions != 0, impl->dimensions, + impl->params[i] = Halide::Parameter(impl->type, impl->dimensions != 0, impl->dimensions, ion::argument_name(std::get<0>(impl->pred_chan), std::get<1>(impl->pred_chan), i, impl->graph_id.value())); } } From 68b726b7c2ed790e8b8dabf0b30d2484a2dc2c03 Mon Sep 17 00:00:00 2001 From: Xinyu Li Date: Tue, 2 Apr 2024 13:30:21 -0700 Subject: [PATCH 2/3] remove cpp portmap --- doc/index.rst | 3 - example/fpga_dnn.cc | 5 +- example/gpu_transpose.cc | 11 +- example/opencv_bb.cc | 8 +- example/u3v.cc | 66 ++++++++---- include/ion/builder.h | 3 +- include/ion/ion.h | 1 - include/ion/port_map.h | 43 -------- src/bb/sgm/bb.h | 2 +- src/builder.cc | 2 +- src/c_ion.cc | 202 ------------------------------------ test/CMakeLists.txt | 8 -- test/gpu-extern.cc | 9 +- test/gpu-extern_compile.cc | 30 ------ test/port-binding-compat.cc | 75 ------------- 15 files changed, 63 insertions(+), 405 deletions(-) delete mode 100644 include/ion/port_map.h delete mode 100644 test/port-binding-compat.cc diff --git a/doc/index.rst b/doc/index.rst index 2bc3cb04..9195a588 100644 --- a/doc/index.rst +++ b/doc/index.rst @@ -29,9 +29,6 @@ ion-core API Reference .. doxygenclass:: ion::Node :members: -.. doxygenclass:: ion::PortMap - :members: - .. doxygenclass:: ion::Builder :members: diff --git a/example/fpga_dnn.cc b/example/fpga_dnn.cc index 6fac3a40..e1c1fbfe 100644 --- a/example/fpga_dnn.cc +++ b/example/fpga_dnn.cc @@ -29,9 +29,8 @@ int main(int argc, char *argv[]) { Halide::Buffer out_buf(channel, width, height); - PortMap pm; - pm.set(n["output"], out_buf); - b.run(pm); + n["output"].bind(out_buf); + b.run(); cv::Mat predicted(height, width, CV_8UC3, out_buf.data()); cv::cvtColor(predicted, predicted, cv::COLOR_RGB2BGR); diff --git a/example/gpu_transpose.cc b/example/gpu_transpose.cc index 6b031173..b8789388 100644 --- a/example/gpu_transpose.cc +++ b/example/gpu_transpose.cc @@ -9,8 +9,8 @@ class Transpose : public BuildingBlock { GeneratorParam gc_tags{"gc_tags", "image,camera"}; GeneratorParam gc_inference{"gc_inference", R"((function(v){ return { output: [3, parseInt(v.width), parseInt(v.height)] }}))"}; GeneratorParam gc_mandatory{"gc_mandatory", "width,height"}; - GeneratorInput input{"input", Halide::type_of(), 2}; - GeneratorOutput output{"output", Halide::type_of(), 2}; + Input input{"input", Halide::type_of(), 2}; + Output output{"output", Halide::type_of(), 2}; void generate() { using namespace Halide; @@ -47,11 +47,10 @@ int main() { Port input{"input", Halide::type_of(), 2}; auto n = b.add("transpose")(input); - PortMap pm; - pm.set(input, ibuf); - pm.set(n["output"], obuf); + input.bind(ibuf); + n["output"].bind(obuf); - b.run(pm); + b.run(); } catch (const std::exception &e) { std::cerr << e.what() << std::endl; diff --git a/example/opencv_bb.cc b/example/opencv_bb.cc index 121c97ac..85786426 100644 --- a/example/opencv_bb.cc +++ b/example/opencv_bb.cc @@ -28,12 +28,12 @@ int main(int argc, char *argv[]) { Halide::Buffer r = Halide::Buffer::make_scalar(); - PortMap pm; - pm.set(in, in_buf); - pm.set(n["output"], r); + + in.bind(in_buf); + n["output"].bind(r); for (int i=0; i<1000; ++i) { - b.run(pm); + b.run(); } } catch (const std::exception &e) { diff --git a/example/u3v.cc b/example/u3v.cc index 140ab2d8..2b2fd20d 100644 --- a/example/u3v.cc +++ b/example/u3v.cc @@ -17,6 +17,37 @@ using namespace ion; +struct rawHeader { + + // ---------- 0 + int version_; + // ---------- 4 + int width_; + int height_; + // ---------- 12 + float r_gain0_; + float g_gain0_; + float b_gain0_; + // ---------- 24 + float r_gain1_; + float g_gain1_; + float b_gain1_; + // ---------- 36 + int offset0_x_; + int offset0_y_; + int offset1_x_; + int offset1_y_; + // ---------- 52 + int outputsize0_x_; + int outputsize0_y_; + int outputsize1_x_; + int outputsize1_y_; + // ---------- 68 + float fps_; + // ---------- 72 + int pfnc_pixelformat; +}; + void display_and_save(int32_t width, int32_t height, std::string directory_path, rawHeader header_info, bool last_run){ Builder b; @@ -115,28 +146,27 @@ void display_and_save(int32_t width, int32_t height, std::string directory_path, Param{"height", std::to_string(height)}); Port display_output1_p = n["output"]; - PortMap pm; - /* input */ - pm.set(wp, width); - pm.set(hp, height); - pm.set(r_gain0_p, header_info.r_gain0_); - pm.set(g_gain0_p, header_info.g_gain0_); - pm.set(b_gain0_p, header_info.b_gain0_); + /* input */ + wp.bind(&width); + hp.bind(&height); - pm.set(r_gain1_p, header_info.r_gain1_); - pm.set(g_gain1_p, header_info.g_gain1_); - pm.set(b_gain1_p, header_info.b_gain1_); + r_gain0_p.bind(&header_info.r_gain0_); + g_gain0_p.bind(&header_info.g_gain0_); + b_gain0_p.bind(&header_info.b_gain0_); + r_gain1_p.bind(&header_info.r_gain1_); + g_gain1_p.bind(&header_info.g_gain1_); + b_gain1_p.bind(&header_info.b_gain1_); /* output */ Halide::Buffer out0 = Halide::Buffer::make_scalar(); Halide::Buffer out1 = Halide::Buffer::make_scalar(); - pm.set(display_output0_p, out0); - pm.set(display_output1_p, out1); + display_output0_p.bind(out0); + display_output1_p.bind(out1); Halide::Buffer out = Halide::Buffer::make_scalar(); - pm.set(terminator, out); + terminator.bind(out); int32_t gain0 = 0; int32_t gain1 = 480; @@ -146,19 +176,13 @@ void display_and_save(int32_t width, int32_t height, std::string directory_path, int loop_num = 400; for (int i=0; i< loop_num; ++i) { - pm.set(dispose_camera, last_run && i == loop_num - 1); - pm.set(dispose_writer, i == loop_num - 1); - pm.set(gain0_p, gain0++); - pm.set(gain1_p, gain1--); - pm.set(exposure0_p, exposure0); - pm.set(exposure1_p, exposure1); - b.run(pm); + b.run(); } cv::destroyAllWindows(); } -void open_and_check(int32_t& width, int32_t& height, const filesystem::path output_directory, uint32_t& file_idx, std::ifstream& ifs, bool *finished) { +void open_and_check(int32_t& width, int32_t& height, const std::filesystem::path output_directory, uint32_t& file_idx, std::ifstream& ifs, bool *finished) { auto file_path = output_directory / ("raw-" + ::std::to_string(file_idx++) + ".bin"); ifs = ::std::ifstream(file_path, ::std::ios::binary); diff --git a/include/ion/builder.h b/include/ion/builder.h index 5f0f97cf..a7be4463 100644 --- a/include/ion/builder.h +++ b/include/ion/builder.h @@ -12,7 +12,6 @@ #include "graph.h" #include "node.h" #include "target.h" -#include "port_map.h" namespace ion { @@ -96,7 +95,7 @@ class Builder { * @arg pm: This remains just for backward compatibility. Port::bind can be used instead of PortMap. * This argument will be removed in coming major release. */ - void run(const PortMap& pm = PortMap()); + void run(); /** * Retrieve names of BBs diff --git a/include/ion/ion.h b/include/ion/ion.h index 99eddd8b..5821b0d3 100644 --- a/include/ion/ion.h +++ b/include/ion/ion.h @@ -9,7 +9,6 @@ #include "node.h" #include "param.h" #include "port.h" -#include "port_map.h" #include "target.h" #include "type.h" diff --git a/include/ion/port_map.h b/include/ion/port_map.h deleted file mode 100644 index ee036910..00000000 --- a/include/ion/port_map.h +++ /dev/null @@ -1,43 +0,0 @@ -#ifndef ION_PORT_MAP_H -#define ION_PORT_MAP_H - -#include - -#include - -namespace ion { - -/** - * PortMap is used to assign actual value to the port input. - */ -class PortMap { - -public: - template - [[deprecated("Port::bind can be used instead of PortMap.")]] - void set(Port port, T v) { - auto& buf(scalar_buffer_[argument_name(port.pred_id(), port.pred_name(), port.index(), port.graph_id())]); - buf.resize(sizeof(v)); - std::memcpy(buf.data(), &v, sizeof(v)); - port.bind(reinterpret_cast(buf.data())); - } - - template - [[deprecated("Port::bind can be used instead of PortMap.")]] - void set(Port port, Halide::Buffer& buf) { - port.bind(buf); - } - - template - [[deprecated("Port::bind can be used instead of PortMap.")]] - void set(Port port, const std::vector> &bufs) { - port.bind(bufs); - } - -private: - std::unordered_map> scalar_buffer_; -}; - -} // namespace ion - -#endif // ION_PORT_MAP_H diff --git a/src/bb/sgm/bb.h b/src/bb/sgm/bb.h index 614497c6..79f5eae0 100644 --- a/src/bb/sgm/bb.h +++ b/src/bb/sgm/bb.h @@ -30,7 +30,7 @@ Halide::Func disparity(Halide::Func cost, int32_t disp) { Func g("argmin"); g(x, y) = Tuple(0, (e.type().max)()); - g(x, y) = tuple_select(e < g(x, y)[1], Tuple(r, e), g(x, y)); + g(x, y) = select(e < g(x, y)[1], Tuple(r, e), g(x, y)); g.update().unroll(r[0]); diff --git a/src/builder.cc b/src/builder.cc index 27f342ce..3f6774a7 100644 --- a/src/builder.cc +++ b/src/builder.cc @@ -187,7 +187,7 @@ void Builder::compile(const std::string& function_name, const CompileOption& opt return; } -void Builder::run(const ion::PortMap&) { +void Builder::run() { if (!impl_->pipeline.defined()) { impl_->pipeline = lower(*this, impl_->nodes, false); if (!impl_->pipeline.defined()) { diff --git a/src/c_ion.cc b/src/c_ion.cc index 35798690..d43fc776 100644 --- a/src/c_ion.cc +++ b/src/c_ion.cc @@ -569,24 +569,6 @@ int ion_builder_run(ion_builder_t obj) return 0; } -int ion_builder_run_with_port_map(ion_builder_t obj, ion_port_map_t pm) -{ - try { - reinterpret_cast(obj)->run(*reinterpret_cast(pm)); - } catch (const Halide::Error& e) { - log::error(e.what()); - return 1; - } catch (const std::exception& e) { - log::error(e.what()); - return 1; - } catch (...) { - log::error("Unknown exception was happened"); - return 1; - } - - return 0; -} - template Halide::Buffer *make_buffer(const std::vector& sizes) { if (sizes.empty()) { @@ -859,190 +841,6 @@ int ion_buffer_read(ion_buffer_t obj, void *ptr, int size) return 0; } -int ion_port_map_create(ion_port_map_t *ptr) -{ - try { - *ptr = reinterpret_cast(new PortMap); - } catch (const Halide::Error& e) { - log::error(e.what()); - return 1; - } catch (const std::exception& e) { - log::error(e.what()); - return 1; - } catch (...) { - log::error("Unknown exception was happened"); - return 1; - } - - return 0; -} - -int ion_port_map_destroy(ion_port_map_t obj) -{ - try { - delete reinterpret_cast(obj); - } catch (const Halide::Error& e) { - log::error(e.what()); - return 1; - } catch (const std::exception& e) { - log::error(e.what()); - return 1; - } catch (...) { - log::error("Unknown exception was happened"); - return 1; - } - - return 0; -} - - -#define ION_PORT_MAP_SET_IMPL(T, POSTFIX) \ - int ion_port_map_set_##POSTFIX(ion_port_map_t obj, ion_port_t p, T v) { \ - try { \ - reinterpret_cast(obj)->set(*reinterpret_cast(p), v); \ - } catch (const Halide::Error& e) { \ - log::error(e.what()); \ - return 1; \ - } catch (const std::exception& e) { \ - log::error(e.what()); \ - return 1; \ - } catch (...) { \ - log::error("Unknown exception was happened"); \ - return 1; \ - } \ - \ - return 0; \ - } - -ION_PORT_MAP_SET_IMPL(int8_t, i8) -ION_PORT_MAP_SET_IMPL(int16_t, i16) -ION_PORT_MAP_SET_IMPL(int32_t, i32) -ION_PORT_MAP_SET_IMPL(int64_t, i64) -ION_PORT_MAP_SET_IMPL(bool, u1) -ION_PORT_MAP_SET_IMPL(uint8_t, u8) -ION_PORT_MAP_SET_IMPL(uint16_t, u16) -ION_PORT_MAP_SET_IMPL(uint32_t, u32) -ION_PORT_MAP_SET_IMPL(uint64_t, u64) -ION_PORT_MAP_SET_IMPL(float, f32) -ION_PORT_MAP_SET_IMPL(double, f64) - -#undef ION_PORT_MAP_SET_IMPL - -int ion_port_map_set_buffer(ion_port_map_t obj, ion_port_t p, ion_buffer_t b) -{ - try { - // NOTE: Halide::Buffer class layout is safe to call Halide::Buffer::type() - auto type = reinterpret_cast*>(b)->type(); - if (type.is_int()) { - if (type.bits() == 8) { - reinterpret_cast(obj)->set(*reinterpret_cast(p), *reinterpret_cast*>(b)); - } else if (type.bits() == 16) { - reinterpret_cast(obj)->set(*reinterpret_cast(p), *reinterpret_cast*>(b)); - } else if (type.bits() == 32) { - reinterpret_cast(obj)->set(*reinterpret_cast(p), *reinterpret_cast*>(b)); - } else if (type.bits() == 64) { - reinterpret_cast(obj)->set(*reinterpret_cast(p), *reinterpret_cast*>(b)); - } else { - throw std::runtime_error("Unsupported bits number"); - } - } else if (type.is_uint()) { - if (type.bits() == 1) { - reinterpret_cast(obj)->set(*reinterpret_cast(p), *reinterpret_cast*>(b)); - } else if (type.bits() == 8) { - reinterpret_cast(obj)->set(*reinterpret_cast(p), *reinterpret_cast*>(b)); - } else if (type.bits() == 16) { - reinterpret_cast(obj)->set(*reinterpret_cast(p), *reinterpret_cast*>(b)); - } else if (type.bits() == 32) { - reinterpret_cast(obj)->set(*reinterpret_cast(p), *reinterpret_cast*>(b)); - } else if (type.bits() == 64) { - reinterpret_cast(obj)->set(*reinterpret_cast(p), *reinterpret_cast*>(b)); - } else { - throw std::runtime_error("Unsupported bits number"); - } - } else if (type.is_float()) { - if (type.bits() == 32) { - reinterpret_cast(obj)->set(*reinterpret_cast(p), *reinterpret_cast*>(b)); - } else if (type.bits() == 64) { - reinterpret_cast(obj)->set(*reinterpret_cast(p), *reinterpret_cast*>(b)); - } else { - throw std::runtime_error("Unsupported bits number"); - } - } else { - throw std::runtime_error("Unsupported type code"); - } - } catch (const Halide::Error& e) { - log::error(e.what()); - return 1; - } catch (const std::exception& e) { - log::error(e.what()); - return 1; - } catch (...) { - log::error("Unknown exception was happened"); - return 1; - } - - - return 0; -} - -int ion_port_map_set_buffer_array(ion_port_map_t obj, ion_port_t p, ion_buffer_t *bs, int n) -{ - try { - // NOTE: Halide::Buffer class layout is safe to call Halide::Buffer::type() - auto type = reinterpret_cast*>(*bs)->type(); - if (type.is_int()) { - if (type.bits() == 8) { - reinterpret_cast(obj)->set(*reinterpret_cast(p), convert(bs, n)); - reinterpret_cast(obj)->set(*reinterpret_cast(p), convert(bs, n)); - } else if (type.bits() == 16) { - reinterpret_cast(obj)->set(*reinterpret_cast(p), convert(bs, n)); - } else if (type.bits() == 32) { - reinterpret_cast(obj)->set(*reinterpret_cast(p), convert(bs, n)); - } else if (type.bits() == 64) { - reinterpret_cast(obj)->set(*reinterpret_cast(p), convert(bs, n)); - } else { - throw std::runtime_error("Unsupported bits number"); - } - } else if (type.is_uint()) { - if (type.bits() == 1) { - reinterpret_cast(obj)->set(*reinterpret_cast(p), convert(bs, n)); - } else if (type.bits() == 8) { - reinterpret_cast(obj)->set(*reinterpret_cast(p), convert(bs, n)); - } else if (type.bits() == 16) { - reinterpret_cast(obj)->set(*reinterpret_cast(p), convert(bs, n)); - } else if (type.bits() == 32) { - reinterpret_cast(obj)->set(*reinterpret_cast(p), convert(bs, n)); - } else if (type.bits() == 64) { - reinterpret_cast(obj)->set(*reinterpret_cast(p), convert(bs, n)); - } else { - throw std::runtime_error("Unsupported bits number"); - } - } else if (type.is_float()) { - if (type.bits() == 32) { - reinterpret_cast(obj)->set(*reinterpret_cast(p), convert(bs, n)); - } else if (type.bits() == 64) { - reinterpret_cast(obj)->set(*reinterpret_cast(p), convert(bs, n)); - } else { - throw std::runtime_error("Unsupported bits number"); - } - } else { - throw std::runtime_error("Unsupported type code"); - } - } catch (const Halide::Error& e) { - log::error(e.what()); - return 1; - } catch (const std::exception& e) { - log::error(e.what()); - return 1; - } catch (...) { - log::error("Unknown exception was happened"); - return 1; - } - - - return 0; -} - int ion_graph_create(ion_graph_t *ptr, ion_builder_t obj, const char * name) { diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 197ec1f3..95a3da92 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -40,14 +40,6 @@ ion_jit_executable(inverted_dep SRCS inverted_dep.cc) # Duplicate port ion_jit_executable(dup SRCS dup.cc) -# Port binding in compatible style -ion_jit_executable(port-binding-compat SRCS port-binding-compat.cc) -if(UNIX AND NOT APPLE) - target_compile_options(port-binding-compat_jit PRIVATE "-Wno-deprecated-declarations") -else() - # TODO: -endif() - # Port binding ion_jit_executable(port-binding SRCS port-binding.cc) diff --git a/test/gpu-extern.cc b/test/gpu-extern.cc index a8a66af5..79b6cdf7 100644 --- a/test/gpu-extern.cc +++ b/test/gpu-extern.cc @@ -23,7 +23,7 @@ int main() n = b.add("test_extern_inc_i32x2")(ip).set_param(wp, hp, vp); n = b.add("test_extern_inc_i32x2")(n["output"]).set_param(wp, hp, vp); - PortMap pm; + Halide::Buffer ibuf(std::vector{size, size}); for (int y=0; y obuf(std::vector{size, size}); for (int y=0; y ibuf(std::vector{size, size}); - // for (int y=0; y obuf(std::vector{size, size}); - // for (int y=0; y(), 2}; - Port vp{"v", Halide::type_of()}; - n = b.add("test_incx_i32x2")(ip, vp); - - PortMap pm; - - Halide::Buffer ibuf(std::vector{1, 1}); - - Halide::Buffer obuf(std::vector{1, 1}); - - int32_t v = 0; - - pm.set(ip, ibuf); - pm.set(n["output"], obuf); - - - // Test 1 - ibuf(0, 0) = 42; - pm.set(vp, 0); - obuf(0, 0) = 0; - - b.run(pm); - if (obuf(0, 0) != 42) { - std::cerr << "Expected: " << 42 << " Actual:" << obuf(0, 0) << std::endl; - return 1; - } - - // Test 2 - ibuf(0, 0) = 42; - pm.set(vp, 1); - obuf(0, 0) = 0; - - b.run(pm); - if (obuf(0, 0) != 43) { - std::cerr << "Expected: " << 43 << " Actual:" << obuf(0, 0) << std::endl; - return 1; - } - - // Test 3 - ibuf(0, 0) = 44; - pm.set(vp, 0); - obuf(0, 0) = 0; - - b.run(pm); - if (obuf(0, 0) != 44) { - std::cerr << "Expected: " << 44 << " Actual:" << obuf(0, 0) << std::endl; - return 1; - } - - } catch (const Halide::Error& e) { - std::cerr << e.what() << std::endl; - return 1; - } catch (const std::exception& e) { - std::cerr << e.what() << std::endl; - return 1; - } - - std::cout << "Passed" << std::endl; - - return 0; -} From e4aff6a5b7ea31acbd72e6eadf8e29a92d66bdad Mon Sep 17 00:00:00 2001 From: Xinyu Li Date: Thu, 4 Apr 2024 17:53:27 -0700 Subject: [PATCH 3/3] fix port access capi --- src/c_ion.cc | 1 - 1 file changed, 1 deletion(-) diff --git a/src/c_ion.cc b/src/c_ion.cc index d43fc776..61ff11fa 100644 --- a/src/c_ion.cc +++ b/src/c_ion.cc @@ -46,7 +46,6 @@ int ion_port_create_with_index(ion_port_t *ptr, ion_port_t obj, int index) auto p = new Port(*reinterpret_cast(obj)); p->set_index(index); *ptr = reinterpret_cast(p); - reinterpret_cast(obj)->set_index(index); } catch (const Halide::Error& e) { log::error(e.what()); return 1;