1
1
#include " testing.hpp"
2
2
3
3
#include < ttl/cuda_tensor>
4
+ #include < ttl/experimental/copy>
4
5
#include < ttl/range>
5
6
#include < ttl/tensor>
6
7
@@ -23,11 +24,10 @@ TEST(cuda_tensor_test, test0)
23
24
{
24
25
using R = float ;
25
26
cuda_tensor<R, 0 > m0;
26
-
27
27
tensor<R, 0 > x;
28
28
29
- m0. from_host (x. data ( ));
30
- m0. to_host (x. data ( ));
29
+ ttl::copy ( ttl::ref (m0), ttl::view (x ));
30
+ ttl::copy ( ttl::ref (x), ttl::view (m0 ));
31
31
}
32
32
33
33
TEST (cuda_tensor_test, test1)
@@ -42,8 +42,8 @@ TEST(cuda_tensor_test, test2)
42
42
cuda_tensor<R, 2 > m1 (10 , 100 );
43
43
tensor<R, 2 > m2 (10 , 100 );
44
44
45
- m1. from_host (m2. data ( ));
46
- m1. to_host (m2. data ( ));
45
+ ttl::copy ( ttl::ref (m1), ttl::view (m2));
46
+ ttl::copy ( ttl::ref (m2), ttl::view (m1 ));
47
47
48
48
m1.slice (1 , 2 );
49
49
auto r = ref (m1);
@@ -58,14 +58,16 @@ TEST(cuda_tensor_test, test_3)
58
58
cuda_tensor<R, 2 > m1 (ttl::make_shape (10 , 100 ));
59
59
}
60
60
61
- template <typename R, uint8_t r> void test_auto_ref ()
61
+ template <typename R, uint8_t r>
62
+ void test_auto_ref ()
62
63
{
63
64
static_assert (
64
65
std::is_convertible<cuda_tensor<R, r>, cuda_tensor_ref<R, r>>::value,
65
66
" can't convert to ref" );
66
67
}
67
68
68
- template <typename R, uint8_t r> void test_auto_view ()
69
+ template <typename R, uint8_t r>
70
+ void test_auto_view ()
69
71
{
70
72
static_assert (
71
73
std::is_convertible<cuda_tensor<R, r>, cuda_tensor_view<R, r>>::value,
@@ -87,28 +89,30 @@ TEST(cuda_tensor_test, test_convert)
87
89
test_auto_view<int , 2 >();
88
90
}
89
91
90
- template <typename R, uint8_t r> void test_copy (const ttl::shape<r> &shape)
92
+ template <typename R, uint8_t r>
93
+ void test_copy (const ttl::shape<r> &shape)
91
94
{
92
95
tensor<R, r> x (shape);
93
96
cuda_tensor<R, r> y (shape);
94
97
tensor<R, r> z (shape);
95
98
96
99
std::iota (x.data (), x.data_end (), 1 );
97
- y.from_host (x.data ());
98
- y.to_host (z.data ());
100
+
101
+ ttl::copy (ttl::ref (y), ttl::view (x));
102
+ ttl::copy (ttl::ref (z), ttl::view (y));
99
103
100
104
for (auto i : ttl::range (shape.size ())) {
101
105
ASSERT_EQ (x.data ()[i], z.data ()[i]);
102
106
}
103
107
104
108
{
105
109
cuda_tensor_ref<R, r> ry = ref (y);
106
- ry. from_host (x. data ( ));
107
- ry. to_host (x. data ( ));
110
+ ttl::copy (ry, ttl::view (x ));
111
+ ttl::copy ( ttl::ref (z), ttl::view (ry ));
108
112
}
109
113
{
110
114
cuda_tensor_view<R, r> vy = view (y);
111
- vy. to_host (x. data () );
115
+ ttl::copy ( ttl::ref (x), vy );
112
116
}
113
117
}
114
118
0 commit comments