| 3158 | class To2Functor { |
| 3159 | public: |
| 3160 | Maybe<Tensor> operator()(const std::shared_ptr<Tensor>& input, |
| 3161 | const Optional<Symbol<Device>>& device_, |
| 3162 | const Optional<Symbol<DType>>& dtype_, bool copy) const { |
| 3163 | if (input->is_global()) { |
| 3164 | if (!device_.has_value()) { |
| 3165 | std::string device_type = JUST(input->parallel_desc())->device_tag(); |
| 3166 | return JUST(GlobalTensorTo(input, device_type, dtype_.value_or(input->dtype()), copy)); |
| 3167 | } else { |
| 3168 | if (!GlobalMode::is_enabled()) { |
| 3169 | CHECK_OR_RETURN(!device_.has_value()) |
| 3170 | << Error::RuntimeError() |
| 3171 | << "Only string device without device id (eg. \"cpu\" or \"cuda\") is expected " |
| 3172 | << "for global tensor, but got " << device_.value_or(Symbol<Device>())->ToRepr(); |
| 3173 | } |
| 3174 | std::string device_type = device_.value_or(Symbol<Device>())->type(); |
| 3175 | return JUST(GlobalTensorTo(input, device_type, dtype_.value_or(input->dtype()), copy)); |
| 3176 | } |
| 3177 | } else { |
| 3178 | auto dtype = dtype_.value_or(input->dtype()); |
| 3179 | auto device = device_.value_or(JUST(input->device())); |
| 3180 | return JUST(LocalTensorTo(input, device, dtype, copy)); |
| 3181 | } |
| 3182 | } |
| 3183 | }; |
| 3184 | |
| 3185 | class To3Functor { |
nothing calls this directly
no test coverage detected