Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
20 changes: 0 additions & 20 deletions include/ttl/bits/std_tensor_mixin.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<D, host_memory>()(data_.get(), data, data_size());
}

void to_host(void *data) const
{
basic_copier<host_memory, D>()(data, data_.get(), data_size());
}
};

template <typename R, typename S, typename D, typename A>
Expand Down Expand Up @@ -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<D, host_memory>()(data_.get(), data, data_size());
}

void to_host(void *data) const
{
basic_copier<host_memory, D>()(data, data_.get(), data_size());
}
};
} // namespace internal
} // namespace ttl
8 changes: 5 additions & 3 deletions tests/bench_cuda_tensor.cpp
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
#include "benchmark.hpp"

#include <ttl/cuda_tensor>
#include <ttl/experimental/copy>

template <typename R, int n> struct bench_cuda_tensor {
template <typename R, int n>
struct bench_cuda_tensor {
static void run(benchmark::State &state)
{
ttl::cuda_tensor<R, 1> m1(n);
ttl::tensor<R, 1> 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));
}
}
};
Expand Down
30 changes: 17 additions & 13 deletions tests/test_cuda_tensor.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "testing.hpp"

#include <ttl/cuda_tensor>
#include <ttl/experimental/copy>
#include <ttl/range>
#include <ttl/tensor>

Expand All @@ -23,11 +24,10 @@ TEST(cuda_tensor_test, test0)
{
using R = float;
cuda_tensor<R, 0> m0;

tensor<R, 0> 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)
Expand All @@ -42,8 +42,8 @@ TEST(cuda_tensor_test, test2)
cuda_tensor<R, 2> m1(10, 100);
tensor<R, 2> 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);
Expand All @@ -58,14 +58,16 @@ TEST(cuda_tensor_test, test_3)
cuda_tensor<R, 2> m1(ttl::make_shape(10, 100));
}

template <typename R, uint8_t r> void test_auto_ref()
template <typename R, uint8_t r>
void test_auto_ref()
{
static_assert(
std::is_convertible<cuda_tensor<R, r>, cuda_tensor_ref<R, r>>::value,
"can't convert to ref");
}

template <typename R, uint8_t r> void test_auto_view()
template <typename R, uint8_t r>
void test_auto_view()
{
static_assert(
std::is_convertible<cuda_tensor<R, r>, cuda_tensor_view<R, r>>::value,
Expand All @@ -87,28 +89,30 @@ TEST(cuda_tensor_test, test_convert)
test_auto_view<int, 2>();
}

template <typename R, uint8_t r> void test_copy(const ttl::shape<r> &shape)
template <typename R, uint8_t r>
void test_copy(const ttl::shape<r> &shape)
{
tensor<R, r> x(shape);
cuda_tensor<R, r> y(shape);
tensor<R, r> 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]);
}

{
cuda_tensor_ref<R, r> 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<R, r> vy = view(y);
vy.to_host(x.data());
ttl::copy(ttl::ref(x), vy);
}
}

Expand Down