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/restructure port map #177

Merged
merged 47 commits into from
Jan 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
aad7bfa
WIP: Restructuing port mapping
Fixstars-iizuka Dec 19, 2023
dfd43ee
Fully moved into Halide::Internal::Parameter
Fixstars-iizuka Dec 19, 2023
878f344
Enabled testcase for array output
Fixstars-iizuka Dec 19, 2023
0fcc4c4
Reverted
Fixstars-iizuka Dec 19, 2023
74ad6a5
Fixed python tests
Fixstars-iizuka Dec 19, 2023
c84e16d
WIP: Reorganizing array I/O
Fixstars-iizuka Dec 19, 2023
d4afb8a
WIP: input array
Fixstars-iizuka Dec 19, 2023
f702132
WIP: Fixing testcase
Fixstars-iizuka Dec 20, 2023
90eab97
Avoid to use same variable name
Fixstars-iizuka Dec 20, 2023
083c9df
WIP: Pimplize Port class
Fixstars-iizuka Dec 20, 2023
25cd76b
Fixed parameter name conflict
Fixstars-iizuka Dec 20, 2023
e5ef1ed
Fixed port deserializer to manage uniqueness of object
Fixstars-iizuka Dec 20, 2023
050b697
WIP: Holding parameter nicely
Fixstars-iizuka Dec 21, 2023
48643d3
WIP: Map_at error
Fixstars-iizuka Dec 21, 2023
d9bc39f
Fixed python test
Fixstars-iizuka Dec 21, 2023
024d9c5
Merge remote-tracking branch 'origin/master' into feature/restructure…
Fixstars-iizuka Dec 21, 2023
95c13a6
Merge remote-tracking branch 'origin/feature/restructure-port-map' in…
Fixstars-iizuka Dec 21, 2023
39ca5dc
WIP: Port can bind buffer or scalar value
Fixstars-iizuka Dec 21, 2023
df33e8b
WIP
Fixstars-iizuka Dec 21, 2023
87fc382
Passing proper argument stub and instance
Fixstars-iizuka Dec 21, 2023
7477eab
WIP: Work for both JIT and AOT
Fixstars-iizuka Dec 21, 2023
759f026
Merge remote-tracking branch 'origin/master' into feature/restructure…
Fixstars-iizuka Dec 22, 2023
6fce047
Handle deserialied port properly
Fixstars-iizuka Dec 22, 2023
12ab96a
Retrieve port properly
Fixstars-iizuka Dec 23, 2023
00ee078
Fixed testcase to retrieve port from bb
Fixstars-iizuka Dec 23, 2023
51224fa
Removed old code
Fixstars-iizuka Dec 26, 2023
e73dc1e
WIP: Non-scalar parameter should be treated as non-embedded buffer
Fixstars-iizuka Dec 26, 2023
d1b3f73
WIP
Fixstars-iizuka Dec 27, 2023
c9b2c71
Reorganized buffer binding
Fixstars-iizuka Dec 27, 2023
ec5bb36
WIP: vparam
Fixstars-iizuka Dec 28, 2023
c048c1d
Fix
Fixstars-iizuka Dec 28, 2023
f25673c
Restructured
Fixstars-iizuka Dec 28, 2023
edd5f26
WIP
Fixstars-iizuka Dec 28, 2023
39a8b99
Inserted try-catch on test
Fixstars-iizuka Dec 28, 2023
f254072
Treat parameter instance as a raw pointer
Fixstars-iizuka Dec 28, 2023
cbaea7b
Cleaned
Fixstars-iizuka Dec 28, 2023
bca44b0
Unified to use Internal::Parameter
Fixstars-iizuka Dec 28, 2023
bfdaee6
Basepoint of port restructuring
Fixstars-iizuka Dec 28, 2023
6105526
WIP: port has pred and succ info
Fixstars-iizuka Dec 28, 2023
68baf18
WIP: Debug port binding
Fixstars-iizuka Dec 29, 2023
224c803
Confirmed all test passes. TODO: Test from scratch
Fixstars-iizuka Dec 29, 2023
5d5603c
Fixed output binding
Fixstars-iizuka Dec 30, 2023
5871f04
Fixed output binding #2
Fixstars-iizuka Dec 30, 2023
c576dea
Deprecated
Fixstars-iizuka Dec 30, 2023
f7d85d6
Reverted API name
Fixstars-iizuka Jan 2, 2024
9f7c693
Fixed python binding
Fixstars-iizuka Jan 2, 2024
66160ac
Merge branch 'master' into feature/restructure-port-map
iitaku Jan 2, 2024
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
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/build*
__pycache__
.vscode
.DS_Store
.vscode
logs
2 changes: 1 addition & 1 deletion example/isp.cc
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ int main(int argc, char *argv[]) {
pm.set(shading_correction_offset_g, 1.f);
pm.set(shading_correction_offset_b, 1.f);
pm.set(coef_color, 100.f);
pm.set(coef_space, 0.03);
pm.set(coef_space, 0.03f);
pm.set(gamma, 1.f / 2.2f);
pm.set(k1, 0.f);
pm.set(k2, 0.f);
Expand Down
4 changes: 2 additions & 2 deletions example/isp_and_sgm.cc
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ int main(int argc, char *argv[]) {
pm.set(shading_correction_offset_g_l, 1.f);
pm.set(shading_correction_offset_b_l, 1.f);
pm.set(coef_color_l, 100.f);
pm.set(coef_space_l, 0.03);
pm.set(coef_space_l, 0.03f);
pm.set(gamma_l, 1.f / 2.2f);
pm.set(k1_l, 0.f);
pm.set(k2_l, 0.f);
Expand All @@ -118,7 +118,7 @@ int main(int argc, char *argv[]) {
pm.set(shading_correction_offset_g_r, 1.f);
pm.set(shading_correction_offset_b_r, 1.f);
pm.set(coef_color_r, 100.f);
pm.set(coef_space_r, 0.03);
pm.set(coef_space_r, 0.03f);
pm.set(gamma_r, 1.f / 2.2f);
pm.set(k1_r, 0.f);
pm.set(k2_r, 0.f);
Expand Down
15 changes: 7 additions & 8 deletions include/ion/builder.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,11 @@ class Builder {
*/
void compile(const std::string& function_name, const CompileOption& option = CompileOption{});

/**
* Compile and execute the pipeline.
* @arg r: The list of output.
* @arg ports: The mapping of the port and actual value.
* @return Execution result of the pipeline.
* See https://halide-lang.org/docs/class_halide_1_1_realization.html for more details.
*/
void run();

void run(ion::PortMap& ports);


/**
* Retrieve metadata of Building Block in json format.
*/
Expand All @@ -102,7 +98,10 @@ class Builder {

private:

Halide::Pipeline build(ion::PortMap& ports);
Halide::Pipeline build(bool implicit_output = false);

std::vector<Halide::Argument> get_arguments_stub() const;
std::vector<const void*> get_arguments_instance() const;

void set_jit_externs(const std::map<std::string, Halide::JITExtern> &externs) {
pipeline_.set_jit_externs(externs);
Expand Down
33 changes: 31 additions & 2 deletions include/ion/c_ion.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,29 @@ typedef struct ion_buffer_t_ *ion_buffer_t;
typedef struct ion_port_map_t_ *ion_port_map_t;

int ion_port_create(ion_port_t *, const char *, ion_type_t, int);
int ion_port_index_access(ion_port_t , int);
int ion_port_create_with_index(ion_port_t *, ion_port_t , int);
int ion_port_destroy(ion_port_t);
int ion_port_bind_i8(ion_port_t, int8_t*);
int ion_port_bind_i16(ion_port_t, int16_t*);
int ion_port_bind_i32(ion_port_t, int32_t*);
int ion_port_bind_i64(ion_port_t, int64_t*);
int ion_port_bind_u1(ion_port_t, bool*);
int ion_port_bind_u8(ion_port_t, uint8_t*);
int ion_port_bind_u16(ion_port_t, uint16_t*);
int ion_port_bind_u32(ion_port_t, uint32_t*);
int ion_port_bind_u64(ion_port_t, uint64_t*);
int ion_port_bind_f32(ion_port_t, float*);
int ion_port_bind_f64(ion_port_t, double*);
int ion_port_bind_buffer(ion_port_t, ion_buffer_t);
int ion_port_bind_buffer_array(ion_port_t, ion_buffer_t *, int);

int ion_param_create(ion_param_t *, const char *, const char *);
int ion_param_destroy(ion_param_t);

int ion_node_create(ion_node_t *);
int ion_node_destroy(ion_node_t);
int ion_node_get_port(ion_node_t, const char *, ion_port_t *);
int ion_node_set_port(ion_node_t, ion_port_t *, int);
int ion_node_set_iport(ion_node_t, ion_port_t *, int);
int ion_node_set_param(ion_node_t, ion_param_t *, int);

int ion_builder_create(ion_builder_t *);
Expand All @@ -57,24 +70,40 @@ int ion_builder_bb_metadata(ion_builder_t, char *, int, int *);
int ion_builder_run(ion_builder_t, ion_port_map_t);

int ion_buffer_create(ion_buffer_t *, ion_type_t, int *, int);
int ion_buffer_create_with_ptr(ion_buffer_t *, ion_type_t, void *, int *, int);
int ion_buffer_destroy(ion_buffer_t);
int ion_buffer_write(ion_buffer_t, void *, int size);
int ion_buffer_read(ion_buffer_t, void *, int size);

[[deprecated("ion_port_bind* can be used instead of ion_port_map.")]]
int ion_port_map_create(ion_port_map_t *);
[[deprecated("ion_port_bind* can be used instead of ion_port_map.")]]
int ion_port_map_destroy(ion_port_map_t);
[[deprecated("ion_port_bind* can be used instead of ion_port_map.")]]
int ion_port_map_set_i8(ion_port_map_t, ion_port_t, int8_t);
[[deprecated("ion_port_bind* can be used instead of ion_port_map.")]]
int ion_port_map_set_i16(ion_port_map_t, ion_port_t, int16_t);
[[deprecated("ion_port_bind* can be used instead of ion_port_map.")]]
int ion_port_map_set_i32(ion_port_map_t, ion_port_t, int32_t);
[[deprecated("ion_port_bind* can be used instead of ion_port_map.")]]
int ion_port_map_set_i64(ion_port_map_t, ion_port_t, int64_t);
[[deprecated("ion_port_bind* can be used instead of ion_port_map.")]]
int ion_port_map_set_u1(ion_port_map_t, ion_port_t, bool);
[[deprecated("ion_port_bind* can be used instead of ion_port_map.")]]
int ion_port_map_set_u8(ion_port_map_t, ion_port_t, uint8_t);
[[deprecated("ion_port_bind* can be used instead of ion_port_map.")]]
int ion_port_map_set_u16(ion_port_map_t, ion_port_t, uint16_t);
[[deprecated("ion_port_bind* can be used instead of ion_port_map.")]]
int ion_port_map_set_u32(ion_port_map_t, ion_port_t, uint32_t);
[[deprecated("ion_port_bind* can be used instead of ion_port_map.")]]
int ion_port_map_set_u64(ion_port_map_t, ion_port_t, uint64_t);
[[deprecated("ion_port_bind* can be used instead of ion_port_map.")]]
int ion_port_map_set_f32(ion_port_map_t, ion_port_t, float);
[[deprecated("ion_port_bind* can be used instead of ion_port_map.")]]
int ion_port_map_set_f64(ion_port_map_t, ion_port_t, double);
[[deprecated("ion_port_bind* can be used instead of ion_port_map.")]]
int ion_port_map_set_buffer(ion_port_map_t, ion_port_t, ion_buffer_t);
[[deprecated("ion_port_bind* can be used instead of ion_port_map.")]]
int ion_port_map_set_buffer_array(ion_port_map_t, ion_port_t, ion_buffer_t *, int);

#if defined __cplusplus
Expand Down
81 changes: 37 additions & 44 deletions include/ion/node.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,24 @@ namespace ion {
* Node class is used to manage node which consists graph structure.
*/
class Node {
struct Node_ {
friend class Builder;
friend class nlohmann::adl_serializer<Node>;

struct Impl {
std::string id;
std::string name;
Halide::Target target;
std::vector<Param> params;
std::vector<Port> ports;
std::vector<Halide::Internal::AbstractGenerator::ArgInfo> arginfos;

Node_(): id(), name(), target(), params(), ports() {}
Impl(): id(), name(), target(), params(), ports() {}

Node_(const std::string& id_, const std::string& name_, const Halide::Target& target_)
: id(id_), name(name_), target(target_), params(), ports() {
}
Impl(const std::string& id_, const std::string& name_, const Halide::Target& target_);
};

public:
friend class Builder;

Node() : impl_(new Node_) {};
Node() : impl_(new Impl) {};

/**
* Set the target of the node.
Expand Down Expand Up @@ -74,70 +74,63 @@ class Node {
*/
template<typename... Args>
Node operator()(Args ...args) {
impl_->ports = std::vector<Port>{args...};
set_iport({args...});
return *this;
}

void operator()(const std::vector<Port>& ports) {
impl_->ports = ports;
}
void set_iport(const std::vector<Port>& ports);

/**
* Retrieve output port of the node.
* @arg key: The key of port name which is matched with first argument of Output declared in user-defined class deriving BuildingBlock.
* @return Port object which is specified by key.
* Retrieve relevant port of the node.
* @arg name: The name of port name which is matched with first argument of Input/Output declared in user-defined class deriving BuildingBlock.
* @return Port object which is specified by name.
*/
Port operator[](const std::string& key) {
return Port(key, impl_->id);
}
Port operator[](const std::string& name);

std::string id() const {
const std::string& id() const {
return impl_->id;
}

std::string& id() {
return impl_->id;
}

std::string name() const {
const std::string& name() const {
return impl_->name;
}

std::string& name(){
return impl_->name;
}

Halide::Target target() const {
return impl_->target;
}

Halide::Target& target() {
const Halide::Target& target() const {
return impl_->target;
}

std::vector<Param> params() const {
const std::vector<Param>& params() const {
return impl_->params;
}

std::vector<Param>& params() {
return impl_->params;
}

std::vector<Port> ports() const {
return impl_->ports;
std::vector<Port> iports() const {
std::vector<Port> iports;
for (const auto& p: impl_->ports) {
if (std::count_if(p.impl_->succ_chans.begin(), p.impl_->succ_chans.end(),
[&](const Port::Channel& c) { return std::get<0>(c) == impl_->id; })) {
iports.push_back(p);
}
}
return iports;
}

std::vector<Port>& ports() {
return impl_->ports;
std::vector<Port> oports() const {
std::vector<Port> oports;
for (const auto& p: impl_->ports) {
if (id() == p.pred_id()) {
oports.push_back(p);
}
}
return oports;
}

private:
Node(const std::string& id, const std::string& name, const Halide::Target& target)
: impl_(new Node_{id, name, target})
: impl_(new Impl{id, name, target})
{
}

std::shared_ptr<Node_> impl_;
std::shared_ptr<Impl> impl_;
};

} // namespace ion
Expand Down
Loading
Loading