"testing/vscode:/vscode.git/clone" did not exist on "d110d0871c364577427e946954ece65880fa034f"
Commit b40c020a authored by umangyadav's avatar umangyadav
Browse files

Use target_id instead of string

parent 93bcb779
...@@ -34,13 +34,13 @@ inline namespace MIGRAPHX_INLINE_NS { ...@@ -34,13 +34,13 @@ inline namespace MIGRAPHX_INLINE_NS {
struct target_assignments struct target_assignments
{ {
using iterator = std::unordered_map<instruction_ref, std::string>::const_iterator; using iterator = std::unordered_map<instruction_ref, std::size_t>::const_iterator;
using value_type = std::pair<instruction_ref, std::string>; using value_type = std::pair<instruction_ref, std::size_t>;
auto size() const { return assignments.size(); } auto size() const { return assignments.size(); }
auto& at(instruction_ref ins) const { return assignments.at(ins); } auto& at(instruction_ref ins) const { return assignments.at(ins); }
auto insert(iterator it, const std::pair<instruction_ref, std::string>& assignment) auto insert(iterator it, const std::pair<instruction_ref, std::size_t>& assignment)
{ {
return assignments.insert(it, assignment); return assignments.insert(it, assignment);
} }
...@@ -50,7 +50,7 @@ struct target_assignments ...@@ -50,7 +50,7 @@ struct target_assignments
auto end() const { return assignments.end(); } auto end() const { return assignments.end(); }
private: private:
std::unordered_map<instruction_ref, std::string> assignments; std::unordered_map<instruction_ref, std::size_t> assignments;
}; };
} // namespace MIGRAPHX_INLINE_NS } // namespace MIGRAPHX_INLINE_NS
......
...@@ -178,6 +178,7 @@ It does it by first finding subgraphs supported on a given target based on assig ...@@ -178,6 +178,7 @@ It does it by first finding subgraphs supported on a given target based on assig
It is possible that instructions have multiple target assignments and part of multiple subgraphs. It is possible that instructions have multiple target assignments and part of multiple subgraphs.
Current logic is simple and assigns entire subgraph containing supported instruction to a particular Current logic is simple and assigns entire subgraph containing supported instruction to a particular
target on first seen basis and doesn't find the "best" target assignment. target on first seen basis and doesn't find the "best" target assignment.
Assumes that all instructions will have target_assignment after this.
*/ */
target_assignments program::get_target_assignments(const std::vector<target>& targets, target_assignments program::get_target_assignments(const std::vector<target>& targets,
assignment_options options) assignment_options options)
...@@ -187,13 +188,12 @@ target_assignments program::get_target_assignments(const std::vector<target>& ta ...@@ -187,13 +188,12 @@ target_assignments program::get_target_assignments(const std::vector<target>& ta
target_assignments p; target_assignments p;
const auto* mod = get_main_module(); const auto* mod = get_main_module();
std::vector<std::pair<target, supported_segments>> target_subgraphs; std::vector<std::pair<std::size_t, supported_segments>> target_subgraphs;
target_subgraphs.reserve(targets.size()); target_subgraphs.reserve(targets.size());
std::transform(targets.begin(), for(auto tid : range(targets.size()))
targets.end(), {
std::back_inserter(target_subgraphs), target_subgraphs.push_back(std::make_pair(tid, targets[tid].find_supported(mod, m)));
[&](const auto& t) { return std::make_pair(t, t.find_supported(mod, m)); }); }
for(const auto ins : iterator_for(*mod)) for(const auto ins : iterator_for(*mod))
{ {
if(contains(p, ins)) if(contains(p, ins))
...@@ -201,24 +201,24 @@ target_assignments program::get_target_assignments(const std::vector<target>& ta ...@@ -201,24 +201,24 @@ target_assignments program::get_target_assignments(const std::vector<target>& ta
continue; continue;
} }
for(const auto& [target, subgraph] : target_subgraphs) for(const auto& [tid, subgraph] : target_subgraphs)
{ {
// can't pass a structured binding into lambda in C++17 so create a variable for it // can't pass a structured binding into lambda in C++17 so create a variable for it
const auto& t = target; const auto& t = tid;
for(const auto& segment : subgraph) for(const auto& segment : subgraph)
{ {
const auto& instructions = segment.instructions; const auto& instructions = segment.instructions;
if(not contains(instructions, ins)) if(contains(instructions, ins))
{ {
continue; std::transform(instructions.begin(),
instructions.end(),
std::inserter(p, p.end()),
[&](auto instr) { return std::make_pair(instr, t); });
} }
std::transform(instructions.begin(),
instructions.end(),
std::inserter(p, p.end()),
[&](auto instr) { return std::make_pair(instr, t.name()); });
} }
} }
} }
return p; return p;
} }
......
...@@ -56,7 +56,7 @@ TEST_CASE(is_supported) ...@@ -56,7 +56,7 @@ TEST_CASE(is_supported)
for(const auto ins : iterator_for(*mod)) for(const auto ins : iterator_for(*mod))
{ {
const auto& target = assignments.at(ins); const auto& target = assignments.at(ins);
EXPECT(target == "fpga"); EXPECT(target == 0);
} }
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment