Commit b205db35 by eqy Committed by Tianqi Chen

preserve input option order (#1068)

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