Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Refine] Refine __cuda_array_interface__ #68227

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
b7d04aa
Merge pull request #230 from PaddlePaddle/develop
HydrogenSulfate May 10, 2024
2fd9dc0
Merge branch 'develop' of https://github.com/HydrogenSulfate/Paddle i…
HydrogenSulfate May 10, 2024
4c5afe2
Merge branch 'develop' of https://github.com/HydrogenSulfate/Paddle i…
HydrogenSulfate May 15, 2024
056d19b
Merge branch 'develop' of https://github.com/HydrogenSulfate/Paddle i…
HydrogenSulfate May 15, 2024
c022e44
Merge branch 'develop' of https://github.com/HydrogenSulfate/Paddle i…
HydrogenSulfate May 31, 2024
d723c27
Merge branch 'develop' of https://github.com/HydrogenSulfate/Paddle i…
HydrogenSulfate Jun 6, 2024
04664b8
Merge branch 'develop' of https://github.com/HydrogenSulfate/Paddle i…
HydrogenSulfate Jun 6, 2024
2f2777c
Merge branch 'develop' of https://github.com/HydrogenSulfate/Paddle i…
HydrogenSulfate Jun 19, 2024
36efc60
Merge branch 'develop' of https://github.com/HydrogenSulfate/Paddle i…
HydrogenSulfate Jul 4, 2024
6d3d314
Merge pull request #268 from PaddlePaddle/develop
HydrogenSulfate Jul 4, 2024
8eed6d0
Merge branch 'develop' of https://github.com/HydrogenSulfate/Paddle i…
HydrogenSulfate Jul 4, 2024
f6815d3
Merge branch 'develop' of https://github.com/HydrogenSulfate/Paddle i…
HydrogenSulfate Jul 12, 2024
1b3a43b
Merge branch 'develop' of https://github.com/HydrogenSulfate/Paddle i…
HydrogenSulfate Jul 16, 2024
9550534
Merge branch 'develop' of https://github.com/HydrogenSulfate/Paddle i…
HydrogenSulfate Jul 22, 2024
0053ffb
Merge branch 'develop' of https://github.com/HydrogenSulfate/Paddle i…
HydrogenSulfate Jul 24, 2024
928d668
Merge branch 'develop' of https://github.com/HydrogenSulfate/Paddle i…
HydrogenSulfate Jul 24, 2024
2c3ba4b
Merge branch 'develop' of https://github.com/HydrogenSulfate/Paddle i…
HydrogenSulfate Sep 9, 2024
a993efa
Merge branch 'develop' of https://github.com/HydrogenSulfate/Paddle i…
HydrogenSulfate Sep 10, 2024
8e40e50
add new patch method 'cuda_array_interface' for intergrated with numba
HydrogenSulfate Sep 12, 2024
88eddaa
support numelkernel for int8 and update cuda_array_interface to v2 an…
HydrogenSulfate Sep 13, 2024
bf25e63
add __cuda_array_interface__ to attr_not_need_keys
HydrogenSulfate Sep 13, 2024
1fa9aae
add int8 support to numel's docstring
HydrogenSulfate Sep 14, 2024
a5c1573
use Tensor.place.is_gpu_place to determine if is on GPU
HydrogenSulfate Sep 14, 2024
f32a46f
use unitest assert instead python assert
HydrogenSulfate Sep 14, 2024
b0e1134
Merge branch 'develop' of https://github.com/HydrogenSulfate/Paddle i…
HydrogenSulfate Sep 14, 2024
1dee08f
Merge branch 'develop' into refine___cuda_array_interface__
HydrogenSulfate Sep 14, 2024
97c7f85
add uint8 to numel's docstring
HydrogenSulfate Sep 14, 2024
1bfcaf5
fixing small bug...
HydrogenSulfate Sep 14, 2024
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 python/paddle/base/dygraph/tensor_patch_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -1260,7 +1260,7 @@ def __cuda_array_interface__(self):

# raise AttributeError for unsupported tensors, so that
# hasattr(cpu_tensor, "__cuda_array_interface__") is False.
if "gpu" not in str(self.place):
if not self.place.is_gpu_place():
raise AttributeError(
"Can't get __cuda_array_interface__ on non-CUDA tensor. "
"If CUDA data is required use tensor.cuda() to copy tensor to device memory."
Expand Down
2 changes: 1 addition & 1 deletion python/paddle/tensor/stat.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ def numel(x: Tensor, name: str | None = None) -> Tensor:
Returns the number of elements for a tensor, which is a 0-D int64 Tensor with shape [].

Args:
x (Tensor): The input Tensor, it's data type can be bool, float16, float32, float64, int32, int64, complex64, complex128.
x (Tensor): The input Tensor, it's data type can be bool, float16, float32, float64, uint8, int8, int32, int64, complex64, complex128.
name (str|None, optional): Name for the operation (optional, default is None).
For more information, please refer to :ref:`api_guide_Name`.

Expand Down
34 changes: 18 additions & 16 deletions test/legacy_test/test_eager_tensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -1217,18 +1217,18 @@ def test___cuda_array_interface__(self):
# strides should be None if contiguous
tensor = paddle.randn([3, 3]).to(device=gpu_place)
interface = tensor.__cuda_array_interface__
assert interface["strides"] is None
self.assertIsNone(interface["strides"])

# strides should be tuple of int if not contiguous
tensor = paddle.randn([10, 10]).to(device=gpu_place)
tensor = tensor[::2]
interface = tensor.__cuda_array_interface__
assert interface["strides"] == (80, 4)
self.assertEqual(interface["strides"], (80, 4))

# data_ptr should be 0 if tensor is 0-size
tensor = paddle.randn([0, 10]).to(device=gpu_place)
interface = tensor.__cuda_array_interface__
assert interface["data"][0] == 0
self.assertEqual(interface["data"][0], 0)

# raise AttributeError for tensor that requires grad.
tensor = paddle.randn([3, 3]).to(device=gpu_place)
Expand Down Expand Up @@ -1261,22 +1261,24 @@ def test___cuda_array_interface__(self):
.astype(dtype)
)
interface = tensor.__cuda_array_interface__
assert "typestr" in interface and isinstance(
interface["typestr"], str
)
assert "shape" in interface and isinstance(
interface["shape"], tuple
)
assert "strides" in interface and (
self.assertIn("typestr", interface)
self.assertIsInstance(interface["typestr"], str)

self.assertIn("shape", interface)
self.assertIsInstance(interface["shape"], tuple)

self.assertIn("strides", interface)
self.assertTrue(
isinstance(interface["strides"], tuple)
or interface["strides"] is None
)
assert (
"data" in interface
and isinstance(interface["data"], tuple)
and len(interface["data"]) == 2
)
assert "version" in interface and interface["version"] == 2

self.assertIn("data", interface)
self.assertIsInstance(interface["data"], tuple)
self.assertEqual(len(interface["data"]), 2)

self.assertIn("version", interface)
self.assertEqual(interface["version"], 2)


class TestEagerTensorSetitem(unittest.TestCase):
Expand Down