Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions test/infiniop/libinfiniop/liboperators.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
from ctypes import c_int, c_int64, c_uint64, Structure, POINTER, c_size_t
from .datatypes import *
from .devices import *
from pathlib import Path

Device = c_int
Optype = c_int

INFINI_ROOT = os.environ.get("INFINI_ROOT")
INFINI_ROOT = os.getenv("INFINI_ROOT") or str(Path.home() / ".infini")


class TensorDescriptor(Structure):
Expand All @@ -30,9 +31,10 @@ def invalidate(self):


class CTensor:
def __init__(self, desc, data):
def __init__(self, desc, torch_tensor):
self.descriptor = desc
self.data = data
self.torch_tensor_ = torch_tensor
self.data = torch_tensor.data_ptr()


class Handle(Structure):
Expand Down
3 changes: 1 addition & 2 deletions test/infiniop/libinfiniop/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ def to_tensor(tensor, lib):
ndim = tensor.ndimension()
shape = (ctypes.c_size_t * ndim)(*tensor.shape)
strides = (ctypes.c_int64 * ndim)(*(tensor.stride()))
data_ptr = tensor.data_ptr()
# fmt: off
dt = (
InfiniDtype.I8 if tensor.dtype == torch.int8 else
Expand All @@ -46,7 +45,7 @@ def to_tensor(tensor, lib):
ctypes.byref(tensor_desc), ndim, shape, strides, dt
)
# Create Tensor
return CTensor(tensor_desc, data_ptr)
return CTensor(tensor_desc, tensor)


def create_workspace(size, torch_device):
Expand Down