Commit b205db35 by eqy Committed by Tianqi Chen

preserve input option order (#1068)

parent 267f0294
...@@ -126,36 +126,36 @@ struct TargetContext { ...@@ -126,36 +126,36 @@ struct TargetContext {
/*! \brief This namespace provides functions to construct Target instances */ /*! \brief This namespace provides functions to construct Target instances */
namespace target { namespace target {
/*! \return A target for LLVM */ /*! \return A target for LLVM */
EXPORT Target llvm(const std::unordered_set<std::string>& options = EXPORT Target llvm(const std::vector<std::string>& options =
std::unordered_set<std::string>()); std::vector<std::string>());
/*! \return A target for CUDA */ /*! \return A target for CUDA */
EXPORT Target cuda(const std::unordered_set<std::string>& options = EXPORT Target cuda(const std::vector<std::string>& options =
std::unordered_set<std::string>()); std::vector<std::string>());
/*! \return A target for ROCm */ /*! \return A target for ROCm */
EXPORT Target rocm(const std::unordered_set<std::string>& options = EXPORT Target rocm(const std::vector<std::string>& options =
std::unordered_set<std::string>()); std::vector<std::string>());
/*! \return A target for OpenCL */ /*! \return A target for OpenCL */
EXPORT Target opencl(const std::unordered_set<std::string>& options = EXPORT Target opencl(const std::vector<std::string>& options =
std::unordered_set<std::string>()); std::vector<std::string>());
/*! \return A target for Metal */ /*! \return A target for Metal */
EXPORT Target metal(const std::unordered_set<std::string>& options = EXPORT Target metal(const std::vector<std::string>& options =
std::unordered_set<std::string>()); std::vector<std::string>());
/*! \return A target for rasp */ /*! \return A target for rasp */
EXPORT Target rasp(const std::unordered_set<std::string>& options = EXPORT Target rasp(const std::vector<std::string>& options =
std::unordered_set<std::string>()); std::vector<std::string>());
/*! \return A target for Mali */ /*! \return A target for Mali */
EXPORT Target mali(const std::unordered_set<std::string>& options = EXPORT Target mali(const std::vector<std::string>& options =
std::unordered_set<std::string>()); std::vector<std::string>());
/*! \return A target for stackvm */ /*! \return A target for stackvm */
EXPORT Target stackvm(const std::unordered_set<std::string>& options = EXPORT Target stackvm(const std::vector<std::string>& options =
std::unordered_set<std::string>()); std::vector<std::string>());
} // namespace target } // namespace target
......
...@@ -31,7 +31,7 @@ TVM_STATIC_IR_FUNCTOR(IRPrinter, vtable) ...@@ -31,7 +31,7 @@ TVM_STATIC_IR_FUNCTOR(IRPrinter, vtable)
* \return The constructed Target * \return The constructed Target
*/ */
Target CreateTarget(const std::string& target_name, Target CreateTarget(const std::string& target_name,
const std::unordered_set<std::string>& options) { const std::vector<std::string>& options) {
auto target = Target(std::make_shared<TargetNode>()); auto target = Target(std::make_shared<TargetNode>());
auto t = static_cast<TargetNode*>(target.node_.get()); auto t = static_cast<TargetNode*>(target.node_.get());
...@@ -58,7 +58,6 @@ Target CreateTarget(const std::string& target_name, ...@@ -58,7 +58,6 @@ Target CreateTarget(const std::string& target_name,
if (device_name.length() > 0) { if (device_name.length() > 0) {
t->keys_array.push_back(ir::StringImm::make(device_name)); t->keys_array.push_back(ir::StringImm::make(device_name));
} }
t->device_type = kDLCPU; t->device_type = kDLCPU;
t->thread_warp_size = 1; t->thread_warp_size = 1;
if (target_name == "llvm") { if (target_name == "llvm") {
...@@ -95,10 +94,10 @@ Target CreateTarget(const std::string& target_name, ...@@ -95,10 +94,10 @@ Target CreateTarget(const std::string& target_name,
TVM_REGISTER_API("_TargetCreate") TVM_REGISTER_API("_TargetCreate")
.set_body([](TVMArgs args, TVMRetValue* ret) { .set_body([](TVMArgs args, TVMRetValue* ret) {
std::string target_name = args[0]; std::string target_name = args[0];
std::unordered_set<std::string> options; std::vector<std::string> options;
for (int i = 1; i < args.num_args; ++i) { for (int i = 1; i < args.num_args; ++i) {
std::string arg = args[i]; std::string arg = args[i];
options.insert(arg); options.push_back(arg);
} }
*ret = CreateTarget(target_name, options); *ret = CreateTarget(target_name, options);
...@@ -175,10 +174,10 @@ Target Target::create(const std::string& target_str) { ...@@ -175,10 +174,10 @@ Target Target::create(const std::string& target_str) {
ss >> target_name; ss >> target_name;
auto device_name = GetDeviceName(target_str); auto device_name = GetDeviceName(target_str);
std::unordered_set<std::string> options; std::vector<std::string> options;
std::string item; std::string item;
while (ss >> item) { while (ss >> item) {
options.insert(item); options.push_back(item);
} }
if (device_name == "rasp") { if (device_name == "rasp") {
...@@ -224,33 +223,33 @@ tvm::Target Target::current_target(bool allow_not_defined) { ...@@ -224,33 +223,33 @@ tvm::Target Target::current_target(bool allow_not_defined) {
} }
namespace target { namespace target {
std::unordered_set<std::string> MergeOptions(std::unordered_set<std::string> opts, std::vector<std::string> MergeOptions(std::vector<std::string> opts,
const std::unordered_set<std::string>& new_opts) { const std::vector<std::string>& new_opts) {
opts.insert(new_opts.begin(), new_opts.end()); opts.insert(opts.end(), new_opts.begin(), new_opts.end());
return opts; return opts;
} }
Target llvm(const std::unordered_set<std::string>& options) { Target llvm(const std::vector<std::string>& options) {
return CreateTarget("llvm", options); return CreateTarget("llvm", options);
} }
Target cuda(const std::unordered_set<std::string>& options) { Target cuda(const std::vector<std::string>& options) {
return CreateTarget("cuda", options); return CreateTarget("cuda", options);
} }
Target rocm(const std::unordered_set<std::string>& options) { Target rocm(const std::vector<std::string>& options) {
return CreateTarget("rocm", options); return CreateTarget("rocm", options);
} }
Target opencl(const std::unordered_set<std::string>& options) { Target opencl(const std::vector<std::string>& options) {
return CreateTarget("opencl", options); return CreateTarget("opencl", options);
} }
Target metal(const std::unordered_set<std::string>& options) { Target metal(const std::vector<std::string>& options) {
return CreateTarget("metal", options); return CreateTarget("metal", options);
} }
Target rasp(const std::unordered_set<std::string>& options) { Target rasp(const std::vector<std::string>& options) {
return CreateTarget("llvm", MergeOptions(options, { return CreateTarget("llvm", MergeOptions(options, {
"-device=rasp", "-device=rasp",
"-mtriple=armv7l-none-linux-gnueabihf", "-mtriple=armv7l-none-linux-gnueabihf",
...@@ -259,14 +258,14 @@ Target rasp(const std::unordered_set<std::string>& options) { ...@@ -259,14 +258,14 @@ Target rasp(const std::unordered_set<std::string>& options) {
})); }));
} }
Target mali(const std::unordered_set<std::string>& options) { Target mali(const std::vector<std::string>& options) {
return CreateTarget("opencl", MergeOptions(options, { return CreateTarget("opencl", MergeOptions(options, {
"-device=mali" "-device=mali"
})); }));
} }
Target stackvm(const std::unordered_set<std::string>& options) { Target stackvm(const std::vector<std::string>& options) {
return CreateTarget("stackvm", options); return CreateTarget("stackvm", options);
} }
} // namespace target } // namespace target
......
...@@ -32,6 +32,9 @@ TEST(BuildModule, Basic) { ...@@ -32,6 +32,9 @@ TEST(BuildModule, Basic) {
auto lowered = lower(s, args, "func", binds, config); auto lowered = lower(s, args, "func", binds, config);
auto module = build(lowered, target, Target(), config); auto module = build(lowered, target, Target(), config);
auto mali_target = Target::create("opencl -model=Mali-T860MP4@800Mhz -device=mali");
CHECK_EQ(mali_target->str(), "opencl -model=Mali-T860MP4@800Mhz -device=mali");
} }
......
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