-
Notifications
You must be signed in to change notification settings - Fork 517
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
67aa2f2
commit 876ec6e
Showing
2 changed files
with
40 additions
and
0 deletions.
There are no files selected for viewing
30 changes: 30 additions & 0 deletions
30
python/torch_mlir/csrc/base_lazy_backend/utils/tensor_utils.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#pragma once | ||
|
||
#include "torch/csrc/lazy/backend/backend_device.h" | ||
#include "torch/csrc/lazy/core/tensor.h" | ||
|
||
#include "../ops/device_data.h" | ||
|
||
|
||
namespace torch { | ||
namespace lazy { | ||
|
||
inline torch::lazy::DeviceData* device_data_cast( | ||
const at::Tensor& tensor, c10::optional<torch::lazy::BackendDevice> device = c10::nullopt | ||
) { | ||
if (!device) { | ||
device = torch::lazy::GetBackendDevice(tensor); | ||
} | ||
TORCH_CHECK(device); | ||
torch::lazy::LazyTensorPtr lazy_tensor = torch::lazy::GetLtcTensorOrCreateForWrappedNumber(tensor, *device); | ||
if (lazy_tensor) { | ||
torch::lazy::Value param_value = lazy_tensor->GetIrValue(); | ||
if (param_value && param_value->op() == torch::lazy::DeviceData::ClassOpKind()) { | ||
return dynamic_cast<torch::lazy::DeviceData*>(param_value.node.get()); | ||
} | ||
} | ||
return nullptr; | ||
} | ||
|
||
} // namespace lazy | ||
} // namespace torch |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters