MCPcopy Create free account
hub / github.com/Oneflow-Inc/oneflow / operator()

Method operator()

oneflow/core/functional/impl/array_functor.cpp:3160–3182  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3158class 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
3185class To3Functor {

Callers

nothing calls this directly

Calls 11

GlobalTensorToFunction · 0.85
LocalTensorToFunction · 0.85
ToReprMethod · 0.80
is_enabledFunction · 0.50
is_globalMethod · 0.45
has_valueMethod · 0.45
parallel_descMethod · 0.45
value_orMethod · 0.45
dtypeMethod · 0.45
typeMethod · 0.45
deviceMethod · 0.45

Tested by

no test coverage detected