-
Notifications
You must be signed in to change notification settings - Fork 5.9k
【SCU】【Paddle Tensor No.3】新增 Tensor.__dlpack__
#69689
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
Changes from all commits
15399e4
8986f04
17bbaeb
773e954
09fe571
d20ae97
18349c5
34d57d5
2461584
72fc12d
6d4addc
eeb07ec
48e14ac
ae0a24b
82c622c
73bb823
cf81a6d
376e452
777324f
43a4d5c
214b64c
b1a12a2
3bb3cdd
c99d929
a456dbe
fddc3c2
c8e6a5f
024397d
9348366
a79bad9
0b65ceb
6976b37
4e6dc05
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -325,6 +325,15 @@ def test_to_dlpack_from_zero_size(self): | |
| np.testing.assert_array_equal(x.numpy(), y1.numpy()) | ||
| np.testing.assert_array_equal(x.numpy(), y2.numpy()) | ||
|
|
||
| def test_dlpack_basic(self): | ||
| tensor = paddle.to_tensor([1.0, 2.0, 3.0]) | ||
| dlpack_capsule = tensor.__dlpack__() | ||
| self.assertIsNotNone(dlpack_capsule) | ||
|
Comment on lines
+328
to
+331
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 只判断是不是None是不够的,需要将dlpack_capsule用paddle.from_dlpack重新转回Tensor,检测转换前的两个tensor里的值,以及
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 好的老师 |
||
|
|
||
| converted_tensor = paddle.from_dlpack(dlpack_capsule) | ||
| self.assertTrue(paddle.equal_all(tensor, converted_tensor)) | ||
| self.assertEqual(tensor.data_ptr(), converted_tensor.data_ptr()) | ||
|
Comment on lines
+328
to
+335
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这个单测有两个问题:
|
||
|
|
||
|
|
||
| class TestRaiseError(unittest.TestCase): | ||
| def test_to_dlpack_raise_type_error(self): | ||
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这个文件记得还原回去 |
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
__dlpack__作为Tensor的类方法,和__cuda_array_interface__是类似的:Paddle/python/paddle/base/dygraph/tensor_patch_methods.py
Line 1261 in fa26020