MCPcopy Create free account
hub / github.com/MegEngine/MegEngine / get_dl_device

Method get_dl_device

imperative/python/src/dlpack_convertor.cpp:56–80  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

54}
55
56DLDevice mgb::imperative::get_dl_device(const DeviceTensorND& dv) {
57 auto cn = dv.comp_node();
58 DLDevice ctx;
59 switch (cn.device_type()) {
60 case CompNode::DeviceType::CPU: {
61 ctx.device_id = 0;
62 ctx.device_type = DLDeviceType::kDLCPU;
63 break;
64 }
65 case CompNode::DeviceType::CUDA: {
66#if MGB_CUDA
67 auto&& env = CompNodeEnv::from_comp_node(cn).cuda_env();
68 ctx.device_id = env.device;
69 ctx.device_type = DLDeviceType::kDLCUDA;
70#else
71 mgb_throw(MegBrainError, "CUDA device is not available");
72#endif
73 break;
74 }
75 default:
76 mgb_throw(
77 MegBrainError, "Cannot pack tensors on %s", cn.to_string().c_str());
78 }
79 return ctx;
80}
81
82CompNode as_comp_node(const std::string& name) {
83 thread_local struct {

Callers

nothing calls this directly

Calls 3

comp_nodeMethod · 0.45
device_typeMethod · 0.45
to_stringMethod · 0.45

Tested by

no test coverage detected