diff --git a/lite/include/lite/common_enum_c.h b/lite/include/lite/common_enum_c.h index 26547de63d35b05eeb837d7a68fbf18a128431db..23b1894a04451b0aee62d159b8aa7d6a402073c2 100644 --- a/lite/include/lite/common_enum_c.h +++ b/lite/include/lite/common_enum_c.h @@ -31,9 +31,10 @@ typedef enum { LITE_CUDA = 1, LITE_ATLAS = 3, LITE_NPU = 4, + LITE_CAMBRICON = 5, //! when the device information is set in model, so set LITE_DEVICE_DEFAULT //! in lite - LITE_DEVICE_DEFAULT = 5, + LITE_DEVICE_DEFAULT = 6, } LiteDeviceType; typedef enum { diff --git a/lite/pylite/megenginelite/struct.py b/lite/pylite/megenginelite/struct.py index 57a7505e38d09c908b8ddf7025034e04d721da53..937c46c6eb93da033136b3713ebc222ce0b74534 100644 --- a/lite/pylite/megenginelite/struct.py +++ b/lite/pylite/megenginelite/struct.py @@ -21,7 +21,8 @@ class LiteDeviceType(IntEnum): LITE_CUDA = 1 LITE_ATLAS = 3 LITE_NPU = 4 - LITE_DEVICE_DEFAULT = 5 + LITE_CAMBRICON = 5 + LITE_DEVICE_DEFAULT = 6 class LiteDataType(IntEnum): diff --git a/lite/src/mge/common.cpp b/lite/src/mge/common.cpp index 6b0ceb4d982413935d892b04a7d4441d3f1aa721..fba4f9eff517493aacd4bd07b1d4d49eee428924 100644 --- a/lite/src/mge/common.cpp +++ b/lite/src/mge/common.cpp @@ -164,6 +164,9 @@ mgb::CompNode::Locator lite::to_compnode_locator(const LiteDeviceType& device) { case LiteDeviceType::LITE_ATLAS: loc.type = mgb::CompNode::DeviceType::ATLAS; break; + case LiteDeviceType::LITE_CAMBRICON: + loc.type = mgb::CompNode::DeviceType::CAMBRICON; + break; case LiteDeviceType::LITE_DEVICE_DEFAULT: loc.type = mgb::CompNode::DeviceType::UNSPEC; break; @@ -183,6 +186,8 @@ LiteDeviceType lite::get_device_from_locator(const mgb::CompNode::Locator& locat return LiteDeviceType::LITE_CUDA; case mgb::CompNode::DeviceType::ATLAS: return LiteDeviceType::LITE_ATLAS; + case mgb::CompNode::DeviceType::CAMBRICON: + return LiteDeviceType::LITE_CAMBRICON; case mgb::CompNode::DeviceType::UNSPEC: return LiteDeviceType::LITE_DEVICE_DEFAULT; default: diff --git a/lite/src/parse_info/default_parse.h b/lite/src/parse_info/default_parse.h index 7873e10e852c5e94b95a3d738dcc5971ee856e0d..16815df8572d72809b60e31cb1e8c90fb8027a18 100644 --- a/lite/src/parse_info/default_parse.h +++ b/lite/src/parse_info/default_parse.h @@ -69,6 +69,8 @@ bool default_parse_info( return LiteDeviceType::LITE_CUDA; if (type == "ATLAS") return LiteDeviceType::LITE_ATLAS; + if (type == "CAMBRICON") + return LiteDeviceType::LITE_CAMBRICON; if (type == "NPU") return LiteDeviceType::LITE_NPU; else { diff --git a/lite/test/test_network.cpp b/lite/test/test_network.cpp index 5acace4ea0fdfa26bebf5a7acce4e7582f324acd..ad17fa14f04e9ce7a1cc77e4e1933f09aedb38d5 100644 --- a/lite/test/test_network.cpp +++ b/lite/test/test_network.cpp @@ -1232,72 +1232,102 @@ TEST(TestNetWork, DeviceAsyncExec) { #endif #endif -#if MGB_ATLAS -TEST(TestNetWork, AtlasLoadNoDevice) { + +#if MGB_ATLAS || MGB_CAMBRICON +namespace { +void load_no_device(LiteDeviceType device_type, const std::string& model_path) { lite::Config config; - config.device_type = LiteDeviceType::LITE_DEVICE_DEFAULT; + config.device_type = device_type; auto network = std::make_shared(config); - network->load_model("./model_atlas.mgb"); + network->load_model(model_path); network->forward(); network->wait(); } -TEST(TestNetWork, AtlasLoadDeviceInput) { +void load_device_input( + LiteDeviceType device_type, const std::string& model_path, + const std::vector& inputs) { lite::NetworkIO networkio; lite::IO input_data_io = {}; - input_data_io.name = "data"; + input_data_io.name = inputs[0]; input_data_io.is_host = false; networkio.inputs.emplace_back(input_data_io); lite::IO input_input0_io = {}; - input_input0_io.name = "input0"; + input_input0_io.name = inputs[1]; input_input0_io.is_host = false; networkio.inputs.emplace_back(input_input0_io); lite::Config config; - config.device_type = LiteDeviceType::LITE_DEVICE_DEFAULT; + config.device_type = device_type; auto network = std::make_shared(config, networkio); - network->load_model("./model_atlas.mgb"); + network->load_model(model_path); network->forward(); network->wait(); } -TEST(TestNetWork, AtlasLoadAtlas) { +void load_device_id( + LiteDeviceType device_type, int device_id, const std::string& model_path) { lite::Config config; - config.device_type = LiteDeviceType::LITE_ATLAS; + config.device_type = device_type; auto network = std::make_shared(config); - network->load_model("./model_atlas.mgb"); + network->set_device_id(device_id); + network->load_model(model_path); + std::shared_ptr input_tensor = network->get_input_tensor(0); + std::shared_ptr output_tensor = network->get_output_tensor(0); network->forward(); network->wait(); + ASSERT_EQ(output_tensor->get_device_id(), device_id); +} +} // namespace +#endif + +#if MGB_ATLAS +TEST(TestNetWork, AtlasLoadNoDevice) { + load_no_device(LiteDeviceType::LITE_DEVICE_DEFAULT, "./model_atlas.mgb"); +} + +TEST(TestNetWork, AtlasLoadDeviceInput) { + load_device_input( + LiteDeviceType::LITE_DEVICE_DEFAULT, "./model_atlas.mgb", + {"data", "input0"}); +} + +TEST(TestNetWork, AtlasLoadAtlas) { + load_no_device(LiteDeviceType::LITE_ATLAS, "./model_atlas.mgb"); } TEST(TestNetWork, AtlasLoadAtlasDeviceInput) { - lite::NetworkIO networkio; - lite::IO input_data_io = {}; - input_data_io.name = "data"; - input_data_io.is_host = false; - networkio.inputs.emplace_back(input_data_io); - lite::IO input_input0_io = {}; - input_input0_io.name = "input0"; - input_input0_io.is_host = false; - networkio.inputs.emplace_back(input_input0_io); - lite::Config config; - config.device_type = LiteDeviceType::LITE_ATLAS; - auto network = std::make_shared(config, networkio); - network->load_model("./model_atlas.mgb"); - network->forward(); - network->wait(); + load_device_input( + LiteDeviceType::LITE_ATLAS, "./model_atlas.mgb", {"data", "input0"}); } TEST(TestNetWork, AtlasDeviceID) { - lite::Config config; - config.device_type = LiteDeviceType::LITE_ATLAS; - auto network = std::make_shared(config); - network->set_device_id(1); - network->load_model("./model_atlas.mgb"); - std::shared_ptr input_tensor = network->get_input_tensor(0); - std::shared_ptr output_tensor = network->get_output_tensor(0); - network->forward(); - network->wait(); - ASSERT_EQ(output_tensor->get_device_id(), 1); + load_device_id(LiteDeviceType::LITE_ATLAS, 1, "./model_atlas.mgb"); +} +#endif + +#if MGB_CAMBRICON +TEST(TestNetWork, CambriconLoadNoDevice) { + load_no_device(LiteDeviceType::LITE_DEVICE_DEFAULT, "./model_magicmind.mgb"); +} + +TEST(TestNetWork, CambriconLoadDeviceInput) { + load_device_input( + LiteDeviceType::LITE_DEVICE_DEFAULT, "./model_magicmind.mgb", + {"data", "input0"}); +} + +TEST(TestNetWork, CambriconLoadCambricon) { + load_no_device(LiteDeviceType::LITE_CAMBRICON, "./model_magicmind.mgb"); +} + +TEST(TestNetWork, CambriconLoadCambriconDeviceInput) { + load_device_input( + LiteDeviceType::LITE_CAMBRICON, "./model_magicmind.mgb", + {"data", "input0"}); +} + +TEST(TestNetWork, CambriconDeviceID) { + load_device_id(LiteDeviceType::LITE_CAMBRICON, 0, "./model_magicmind.mgb"); } #endif #endif diff --git a/src/cambricon/test/magicmind_runtime_opr.cpp b/src/cambricon/test/magicmind_runtime_opr.cpp index 55e3ebc50f1a3da2e8d86283a9221485968555b3..4a7a446041f39f6e6bfc4b473ceaf1f3246e9f50 100644 --- a/src/cambricon/test/magicmind_runtime_opr.cpp +++ b/src/cambricon/test/magicmind_runtime_opr.cpp @@ -679,7 +679,7 @@ TEST(TestMagicMindRuntimeOpr, Serialization) { reinterpret_cast(buf.data()), buf.size(), {x_, add_}); auto out1 = outs[0]; auto out2 = outs[1]; - auto fname = output_file("MagicMindRuntimeOprTest"); + auto fname = output_file("model_magicmind.mgb"); auto dump = [&]() { auto dumper = GraphDumper::make(OutputFile::make_fs(fname.c_str())); auto rst = dumper->dump({out1, out2});