tqchen commented on PR #87:
URL: https://github.com/apache/tvm-ffi/pull/87#issuecomment-3367064607
```python
import tvm_ffi
import tvm_ffi.cpp
import torch
def test_cuda_memory_allocated():
mod = tvm_ffi.cpp.load_inline(
name="hello",
cuda_sources=r"""
#include <tvm/ffi/function.h>
#include <tvm/ffi/container/tensor.h>
namespace ffi = tvm::ffi;
ffi::Tensor add_one_cuda(tvm::ffi::TensorView x) {
ffi::Tensor y = ffi::Tensor::FromDLPackAlloc(
TVMFFIEnvGetTensorAllocator(), x.shape(), x.dtype(),
x->device);
return y;
}
""",
functions=["add_one_cuda"],
)
x = torch.arange(1024 * 1024, dtype=torch.float32, device="cuda")
repeat = 100
for i in range(repeat):
y = torch.empty_like(x)
y = mod.add_one_cuda(x)
allocated = torch.cuda.memory_allocated()
print(f"Allocated memory: {allocated / (1024**2):.2f} MB")
test_cuda_memory_allocated()
```
Validated through the script above
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]