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
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

[project]
name = "apache-tvm-ffi"
version = "0.1.0b10"
version = "0.1.0b11"
description = "tvm ffi"

authors = [{ name = "TVM FFI team" }]
Expand Down
2 changes: 1 addition & 1 deletion python/tvm_ffi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"""TVM FFI Python package."""

# version
__version__ = "0.1.0b10"
__version__ = "0.1.0b11"

# order matters here so we need to skip isort here
# isort: skip_file
Expand Down
2 changes: 1 addition & 1 deletion python/tvm_ffi/cython/function.pxi
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ cdef int TVMFFIPyArgSetterDLPackCExporter_(
if this.c_dlpack_tensor_allocator != NULL:
ctx.c_dlpack_tensor_allocator = this.c_dlpack_tensor_allocator

if ctx.device_id != -1:
if ctx.device_type != -1:
# already queried device, do not do it again, pass NULL to stream
if (this.c_dlpack_from_pyobject)(arg, &temp_managed_tensor, NULL) != 0:
return -1
Expand Down
15 changes: 13 additions & 2 deletions tests/python/test_load_inline.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ def test_load_inline_cuda() -> None:
}
}

void add_one_cuda(tvm::ffi::Tensor x, tvm::ffi::Tensor y) {
void add_one_cuda(tvm::ffi::Tensor x, tvm::ffi::Tensor y, int64_t raw_stream) {
// implementation of a library function
TVM_FFI_ICHECK(x->ndim == 1) << "x must be a 1D tensor";
DLDataType f32_dtype{kDLFloat, 32, 1};
Expand All @@ -184,6 +184,8 @@ def test_load_inline_cuda() -> None:
// with torch.Tensors
cudaStream_t stream = static_cast<cudaStream_t>(
TVMFFIEnvGetStream(x->device.device_type, x->device.device_id));
TVM_FFI_ICHECK_EQ(reinterpret_cast<int64_t>(stream), raw_stream)
<< "stream must be the same as raw_stream";
// launch the kernel
AddOneKernel<<<nblock, nthread_per_block, 0, stream>>>(static_cast<float*>(x->data),
static_cast<float*>(y->data), n);
Expand All @@ -193,9 +195,18 @@ def test_load_inline_cuda() -> None:
)

if torch is not None:
# test with raw stream
x_cuda = torch.asarray([1, 2, 3, 4, 5], dtype=torch.float32, device="cuda")
y_cuda = torch.empty_like(x_cuda)
mod.add_one_cuda(x_cuda, y_cuda)
mod.add_one_cuda(x_cuda, y_cuda, 0)
torch.testing.assert_close(x_cuda + 1, y_cuda)

# test with torch stream
y_cuda = torch.empty_like(x_cuda)
stream = torch.cuda.Stream()
with torch.cuda.stream(stream):
mod.add_one_cuda(x_cuda, y_cuda, stream.cuda_stream)
stream.synchronize()
torch.testing.assert_close(x_cuda + 1, y_cuda)


Expand Down
Loading