diff --git a/include/ttl/bits/std_tensor_mixin.hpp b/include/ttl/bits/std_tensor_mixin.hpp index 36cce84..48dcb99 100644 --- a/include/ttl/bits/std_tensor_mixin.hpp +++ b/include/ttl/bits/std_tensor_mixin.hpp @@ -40,16 +40,6 @@ class basic_scalar_mixin data_ptr data_end() const { return data_.get() + 1; } S shape() const { return S(); } - - void from_host(const void *data) const - { - basic_copier()(data_.get(), data, data_size()); - } - - void to_host(void *data) const - { - basic_copier()(data, data_.get(), data_size()); - } }; template @@ -158,16 +148,6 @@ class basic_tensor_mixin return slice_type(data_.get() + i * sub_shape.size(), batch(j - i, sub_shape)); } - - void from_host(const void *data) const - { - basic_copier()(data_.get(), data, data_size()); - } - - void to_host(void *data) const - { - basic_copier()(data, data_.get(), data_size()); - } }; } // namespace internal } // namespace ttl diff --git a/tests/bench_cuda_tensor.cpp b/tests/bench_cuda_tensor.cpp index 7bb5ddd..c21debd 100644 --- a/tests/bench_cuda_tensor.cpp +++ b/tests/bench_cuda_tensor.cpp @@ -1,16 +1,18 @@ #include "benchmark.hpp" #include +#include -template struct bench_cuda_tensor { +template +struct bench_cuda_tensor { static void run(benchmark::State &state) { ttl::cuda_tensor m1(n); ttl::tensor m2(n); for (auto _ : state) { - m1.from_host(m2.data()); - m1.to_host(m2.data()); + ttl::copy(ttl::ref(m1), ttl::view(m2)); + ttl::copy(ttl::ref(m2), ttl::view(m1)); } } }; diff --git a/tests/test_cuda_tensor.cpp b/tests/test_cuda_tensor.cpp index 3c431ab..bba1942 100644 --- a/tests/test_cuda_tensor.cpp +++ b/tests/test_cuda_tensor.cpp @@ -1,6 +1,7 @@ #include "testing.hpp" #include +#include #include #include @@ -23,11 +24,10 @@ TEST(cuda_tensor_test, test0) { using R = float; cuda_tensor m0; - tensor x; - m0.from_host(x.data()); - m0.to_host(x.data()); + ttl::copy(ttl::ref(m0), ttl::view(x)); + ttl::copy(ttl::ref(x), ttl::view(m0)); } TEST(cuda_tensor_test, test1) @@ -42,8 +42,8 @@ TEST(cuda_tensor_test, test2) cuda_tensor m1(10, 100); tensor m2(10, 100); - m1.from_host(m2.data()); - m1.to_host(m2.data()); + ttl::copy(ttl::ref(m1), ttl::view(m2)); + ttl::copy(ttl::ref(m2), ttl::view(m1)); m1.slice(1, 2); auto r = ref(m1); @@ -58,14 +58,16 @@ TEST(cuda_tensor_test, test_3) cuda_tensor m1(ttl::make_shape(10, 100)); } -template void test_auto_ref() +template +void test_auto_ref() { static_assert( std::is_convertible, cuda_tensor_ref>::value, "can't convert to ref"); } -template void test_auto_view() +template +void test_auto_view() { static_assert( std::is_convertible, cuda_tensor_view>::value, @@ -87,15 +89,17 @@ TEST(cuda_tensor_test, test_convert) test_auto_view(); } -template void test_copy(const ttl::shape &shape) +template +void test_copy(const ttl::shape &shape) { tensor x(shape); cuda_tensor y(shape); tensor z(shape); std::iota(x.data(), x.data_end(), 1); - y.from_host(x.data()); - y.to_host(z.data()); + + ttl::copy(ttl::ref(y), ttl::view(x)); + ttl::copy(ttl::ref(z), ttl::view(y)); for (auto i : ttl::range(shape.size())) { ASSERT_EQ(x.data()[i], z.data()[i]); @@ -103,12 +107,12 @@ template void test_copy(const ttl::shape &shape) { cuda_tensor_ref ry = ref(y); - ry.from_host(x.data()); - ry.to_host(x.data()); + ttl::copy(ry, ttl::view(x)); + ttl::copy(ttl::ref(z), ttl::view(ry)); } { cuda_tensor_view vy = view(y); - vy.to_host(x.data()); + ttl::copy(ttl::ref(x), vy); } }