MCPcopy Create free account
hub / github.com/davisking/dlib / test_copy_tensor_slice_add_to_gpu

Function test_copy_tensor_slice_add_to_gpu

dlib/test/dnn.cpp:3741–3807  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3739 }
3740 }
3741 void test_copy_tensor_slice_add_to_gpu()
3742 {
3743 using namespace dlib::tt;
3744 print_spinner();
3745 resizable_tensor dest(10, 9, 7, 15);
3746 resizable_tensor src1(10, 3, 7, 15);
3747 resizable_tensor src2(10, 3, 6, 12);
3748 resizable_tensor src3(10, 9, 7, 15);
3749 tt::tensor_rand rnd;
3750 rnd.fill_gaussian(dest);
3751 rnd.fill_gaussian(src1);
3752 rnd.fill_gaussian(src2);
3753 rnd.fill_gaussian(src3);
3754
3755 const resizable_tensor old_dest = dest;
3756
3757 cuda::copy_tensor(true, dest, 0, 0, 0, src1, 0, 0, 0, src1.k(), src1.nr(), src1.nc()); //full copy src1->dest
3758 cuda::copy_tensor(true, dest, src1.k(), 0, 0, src2, 0, 0, 0, src2.k(), src2.nr(), src2.nc()); //full copy src2->dest with offset of src1
3759 cuda::copy_tensor(true, dest, src1.k() + src2.k(), 1, 1, src3, 3, 1, 1, 3, src3.nr()-2, src3.nc()-2); //partial copy src3 into the rest place of dest
3760
3761 for (long i = 0; i < dest.num_samples(); ++i)
3762 {
3763 for (long k = 0; k < dest.k(); ++k)
3764 {
3765 for (long r = 0; r < dest.nr(); ++r)
3766 {
3767 for (long c = 0; c < dest.nc(); ++c)
3768 {
3769 float old_dest_value = tensor_read_cpu(old_dest, i, k, r, c);
3770 float dest_value = tensor_read_cpu(dest, i, k, r, c);
3771 // first part is from src1
3772 if (k < src1.k())
3773 {
3774 float src_value = tensor_read_cpu(src1, i, k, r, c)+old_dest_value;
3775 DLIB_TEST(std::abs(src_value - dest_value) < 1e-6);
3776 }
3777 // second part is from src2
3778 else if (k < src1.k() + src2.k())
3779 {
3780 if (r < src2.nr() && c < src2.nc())
3781 {
3782 float src_value = tensor_read_cpu(src2, i, k - src1.k(), r, c)+old_dest_value;
3783 DLIB_TEST(std::abs(src_value - dest_value) < 1e-6);
3784 }
3785 else
3786 {
3787 DLIB_TEST(old_dest_value == dest_value);
3788 }
3789 }
3790 // third part is from src3
3791 else
3792 {
3793 if (r > 0 && c > 0 && r + 1 < src3.nr() && c + 1 < src3.nc())
3794 {
3795 float src_value = tensor_read_cpu(src3, i, k - src1.k() - src2.k() + 3, r, c)+old_dest_value;
3796 DLIB_TEST(std::abs(src_value - dest_value) < 1e-6);
3797 }
3798 else

Callers

nothing calls this directly

Calls 8

print_spinnerFunction · 0.85
tensor_read_cpuFunction · 0.85
absFunction · 0.85
copy_tensorFunction · 0.50
kMethod · 0.45
nrMethod · 0.45
ncMethod · 0.45
num_samplesMethod · 0.45

Tested by

no test coverage detected