| 54 | } |
| 55 | |
| 56 | DLDevice 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 | |
| 82 | CompNode as_comp_node(const std::string& name) { |
| 83 | thread_local struct { |
nothing calls this directly
no test coverage detected