<
8000
svg aria-hidden="true" focusable="false" class="octicon octicon-fold-up" viewBox="0 0 16 16" width="16" height="16" fill="currentColor" display="inline-block" overflow="visible" style="vertical-align:text-bottom"> @@ -7096,35 +7096,38 @@ def compare_strides(s1, s2, div):
7096
7096
7097
7097
@skipMeta
7098
7098
@onlyOnCPUAndCUDA
7099
- @dtypes (* torch . testing . get_all_dtypes (include_bool = False ))
7099
+ @dtypes (* get_all_dtypes (include_bool = False ))
7100
7100
def test_dlpack_capsule_conversion (self , device , dtype ):
7101
7101
# DLpack does not explicitly support bool (xref dmlc/dlpack#75)
7102
- x = make_tensor ((5 ,), device , dtype , low = - 9 , high = 9 )
7102
+ x = make_tensor ((5 ,), device , dtype )
7103
7103
z = from_dlpack (to_dlpack (x ))
7104
7104
self .assertEqual (z , x )
7105
7105
7106
7106
@skipMeta
7107
7107
@onlyOnCPUAndCUDA
7108
- @dtypes (* torch . testing . get_all_dtypes (include_bool = False ))
7108
+ @dtypes (* get_all_dtypes (include_bool = False ))
7109
7109
def test_dlpack_protocol_conversion (self , device , dtype ):
7110
- x = make_tensor ((5 ,), device , dtype , low = - 9 , high = 9 )
7110
+ x = make_tensor ((5 ,), device , dtype )
7111
7111
z = from_dlpack (x )
7112
7112
self .assertEqual (z , x )
7113
7113
7114
7114
@skipMeta
7115
7115
@onlyOnCPUAndCUDA
7116
7116
def test_dlpack_shared_storage (self , device ):
7117
- x = make_tensor ((5 ,), device , torch .float64 , low = - 9 , high = 9 )
7117
+ x = make_tensor ((5 ,), device , torch .float64 )
7118
7118
z = from_dlpack (to_dlpack (x ))
7119
7119
z [0 ] = z [0 ] + 20.0
7120
7120
self .assertEqual (z , x )
7121
7121
7122
7122
@skipMeta
7123
7123
@onlyCUDA
7124
- @dtypes (* torch . testing . get_all_dtypes (include_bool = False ))
7124
+ @dtypes (* get_all_dtypes (include_bool = False ))
7125
7125
def test_dlpack_conversion_with_streams (self , device , dtype ):
7126
7126
# Create a stream where the tensor will reside
7127
- x = make_tensor ((5 ,), device , dtype , low = - 9 , high = 9 )
7127
+ stream = torch .cuda .Stream ()
7128
+ with torch .cuda .stream (stream ):
7129
+ # Do an operation in the actual stream
7130
+ x = make_tensor ((5 ,), device , dtype ) + 1
7128
7131
# DLPack protocol helps establish a correct stream order
7129
7132
# (hence data dependency) at the exchange boundary.
7130
7133
# DLPack manages this synchronization for us, so we don't need to
@@ -7137,28 +7140,28 @@ def test_dlpack_conversion_with_streams(self, device, dtype):
7137
7140
7138
7141
@skipMeta
7139
7142
@onlyCUDA
7140
- @dtypes (* torch . testing . get_all_dtypes (include_bool = False ))
7143
+ @dtypes (* get_all_dtypes (include_bool = False ))
7141
7144
def test_dlpack_conversion_with_diff_streams (self , device , dtype ):
7142
7145
from torch ._C import _from_dlpack
7143
- x = make_tensor ((5 ,), device , dtype , low = - 9 , high = 9 )
7144
7146
stream_a = torch .cuda .Stream ()
7145
7147
stream_b = torch .cuda .Stream ()
7146
7148
# DLPack protocol helps establish a correct stream order
7147
7149
# (hence data dependency) at the exchange boundary.
7148
7150
# the `tensor.__dlpack__` method will insert a synchronization event
7149
7151
# in the current stream to make sure that it was correctly populated.
7150
7152
with torch .cuda .stream (stream_a ):
7153
+ x = make_tensor ((5 ,), device , dtype ) + 1
7151
7154
z = _from_dlpack (x .__dlpack__ (stream_b .cuda_stream ))
7152
7155
stream_a .synchronize ()
7153
7156
stream_b .synchronize ()
7154
7157
self .assertEqual (z , x )
7155
7158
7156
7159
@skipMeta
7157
7160
@onlyOnCPUAndCUDA
7158
- @dtypes (* torch . testing . get_all_dtypes (include_bool = False ))
7161
+ @dtypes (* get_all_dtypes (include_bool = False ))
7159
7162
def test_dlpack_tensor_invalid_stream (self , device , dtype ):
7160
7163
with self .assertRaises (TypeError ):
7161
- x = make_tensor ((5 ,), device , dtype , low = - 9 , high = 9 )
7164
+ x = make_tensor ((5 ,), device , dtype )
7162
7165
x .__dlpack__ (stream = object ())
7163
7166
7164
7167
@skipMeta
@@ -7182,6 +7185,13 @@ def test_dlpack_export_is_conj(self):
7182
7185
with self .assertRaisesRegex (RuntimeError , r"conjugate bit" ):
7183
7186
y .__dlpack__ ()
7184
7187
7188
+ @skipMeta
7189
+ def test_dlpack_export_non_strided (self ):
7190
+ x = torch .sparse_coo_tensor ([[0 ]], [1 ], size = (1 ,))
7191
+ y = torch .conj (x )
7192
+ with self .assertRaisesRegex (RuntimeError , r"strided" ):
7193
+ y .__dlpack__ ()
7194
+
7185
7195
@onlyCUDA
7186
7196
@unittest .skipIf (PYTORCH_CUDA_MEMCHECK , "is_pinned uses failure to detect pointer property" )
7187
7197
def test_pin_memory_from_constructor (self , device ):
0 commit comments