Skip to content

Commit 9ca2b0d

Browse files
kiya00pre-commit-ci[bot]shino16
authored
Add is_cpu op (#2758)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Masato Shinokawa <[email protected]>
1 parent 4d3a3c3 commit 9ca2b0d

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

thunder/tests/opinfos.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -555,6 +555,20 @@ def _is_cuda_torch(x: torch.Tensor) -> bool:
555555
tensor_properties.append(is_cuda_opinfo)
556556

557557

558+
def _is_cpu_torch(x: torch.Tensor) -> bool:
559+
return x.is_cpu
560+
561+
562+
is_cpu_opinfo = OpInfo(
563+
ltorch.is_cpu,
564+
sample_input_generator=elementwise_unary_generator,
565+
torch_reference=_is_cpu_torch,
566+
dtypes=(datatypes.all_dtypes),
567+
)
568+
569+
tensor_properties.append(is_cpu_opinfo)
570+
571+
558572
def _is_nested_torch(x: torch.Tensor) -> bool:
559573
return x.is_nested
560574

thunder/torch/__init__.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,14 @@ def is_cuda(a: TensorLike, /) -> bool:
333333
return a.device.devicetype is devices.DeviceType.CUDA
334334

335335

336+
@torchsymbol(torch.Tensor.is_cpu, is_property=True, id="torch.Tensor.is_cpu")
337+
def is_cpu(a: TensorLike, /) -> bool:
338+
return a.device.devicetype is devices.DeviceType.CPU
339+
340+
341+
register_method("is_cpu", is_cpu)
342+
343+
336344
@torchsymbol(torch.polar, id="torch.polar")
337345
def polar(abs_: TensorLike, angle: TensorLike):
338346
# Decompose polar into real/imag using Thunder ops and construct complex via mapped torch.complex

0 commit comments

Comments
 (0)