Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

kokkos: view_copy fix #2863

Merged
merged 1 commit into from
Jun 1, 2018
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
5 changes: 2 additions & 3 deletions packages/kokkos/core/src/Kokkos_CopyViews.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1493,7 +1493,7 @@ void deep_copy
Kokkos::fence();
} else {
Kokkos::fence();
Impl::view_copy(typename dst_type::uniform_runtime_nomemspace_type(dst),typename src_type::uniform_runtime_const_nomemspace_type(src));
Impl::view_copy(dst, src);
Kokkos::fence();
}
}
Expand Down Expand Up @@ -1739,8 +1739,7 @@ void deep_copy
exec_space.fence();
} else {
exec_space.fence();
Impl::view_copy(typename dst_type::uniform_runtime_nomemspace_type(dst),
typename src_type::uniform_runtime_const_nomemspace_type(src));
Impl::view_copy(dst, src);
exec_space.fence();
}
}
Expand Down
2 changes: 2 additions & 0 deletions packages/kokkos/core/unit_test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@ IF(Kokkos_ENABLE_Cuda)
SOURCES
UnitTestMainInit.cpp
cuda/TestCudaHostPinned_SharedAlloc.cpp
cuda/TestCudaHostPinned_ViewCopy.cpp
cuda/TestCudaHostPinned_ViewAPI_a.cpp
cuda/TestCudaHostPinned_ViewAPI_b.cpp
cuda/TestCudaHostPinned_ViewAPI_c.cpp
Expand All @@ -293,6 +294,7 @@ IF(Kokkos_ENABLE_Cuda)
cuda/TestCudaHostPinned_ViewMapping_b.cpp
cuda/TestCudaHostPinned_ViewMapping_subview.cpp
cuda/TestCudaUVM_SharedAlloc.cpp
cuda/TestCudaUVM_ViewCopy.cpp
cuda/TestCudaUVM_ViewAPI_a.cpp
cuda/TestCudaUVM_ViewAPI_b.cpp
cuda/TestCudaUVM_ViewAPI_c.cpp
Expand Down
6 changes: 3 additions & 3 deletions packages/kokkos/core/unit_test/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ ifeq ($(KOKKOS_INTERNAL_USE_CUDA), 1)
OBJ_CUDA += TestCuda_RangePolicy.o
OBJ_CUDA += TestCuda_ViewAPI_a.o TestCuda_ViewAPI_b.o TestCuda_ViewAPI_c.o TestCuda_ViewAPI_d.o TestCuda_ViewAPI_e.o
OBJ_CUDA += TestCuda_ViewMapping_a.o TestCuda_ViewMapping_b.o TestCuda_ViewMapping_subview.o
OBJ_CUDA += TestCudaUVM_ViewAPI_a.o TestCudaUVM_ViewAPI_b.o TestCudaUVM_ViewAPI_c.o TestCudaUVM_ViewAPI_d.o TestCudaUVM_ViewAPI_e.o
OBJ_CUDA += TestCudaUVM_ViewCopy.o TestCudaUVM_ViewAPI_a.o TestCudaUVM_ViewAPI_b.o TestCudaUVM_ViewAPI_c.o TestCudaUVM_ViewAPI_d.o TestCudaUVM_ViewAPI_e.o
OBJ_CUDA += TestCudaUVM_ViewMapping_a.o TestCudaUVM_ViewMapping_b.o TestCudaUVM_ViewMapping_subview.o
OBJ_CUDA += TestCudaHostPinned_ViewAPI_a.o TestCudaHostPinned_ViewAPI_b.o TestCudaHostPinned_ViewAPI_c.o TestCudaHostPinned_ViewAPI_d.o TestCudaHostPinned_ViewAPI_e.o
OBJ_CUDA += TestCudaHostPinned_ViewCopy.o TestCudaHostPinned_ViewAPI_a.o TestCudaHostPinned_ViewAPI_b.o TestCudaHostPinned_ViewAPI_c.o TestCudaHostPinned_ViewAPI_d.o TestCudaHostPinned_ViewAPI_e.o
OBJ_CUDA += TestCudaHostPinned_ViewMapping_a.o TestCudaHostPinned_ViewMapping_b.o TestCudaHostPinned_ViewMapping_subview.o
OBJ_CUDA += TestCuda_View_64bit.o
OBJ_CUDA += TestCuda_ViewOfClass.o
Expand Down Expand Up @@ -117,7 +117,7 @@ ifeq ($(KOKKOS_INTERNAL_USE_ROCM), 1)
OBJ_ROCM += TestROCm_ViewMapping_a.o
OBJ_ROCM += TestROCm_ViewMapping_b.o
OBJ_ROCM += TestROCm_ViewMapping_subview.o
OBJ_ROCM += TestROCmHostPinned_ViewAPI_a.o TestROCmHostPinned_ViewAPI_b.o TestROCmHostPinned_ViewAPI_c.o TestROCmHostPinned_ViewAPI_d.o TestROCmHostPinned_ViewAPI_e.o
OBJ_ROCM += TestROCmHostPinned_ViewCopy.o TestROCmHostPinned_ViewAPI_a.o TestROCmHostPinned_ViewAPI_b.o TestROCmHostPinned_ViewAPI_c.o TestROCmHostPinned_ViewAPI_d.o TestROCmHostPinned_ViewAPI_e.o
OBJ_ROCM += TestROCmHostPinned_View_64bit.o
OBJ_ROCM += TestROCmHostPinned_ViewMapping_a.o
OBJ_ROCM += TestROCmHostPinned_ViewMapping_b.o
Expand Down
134 changes: 134 additions & 0 deletions packages/kokkos/core/unit_test/TestViewCopy.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
/*
//@HEADER
// ************************************************************************
//
// Kokkos v. 2.0
// Copyright (2014) Sandia Corporation
//
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
// the U.S. Government retains certain rights in this software.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// 1. Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// 3. Neither the name of the Corporation nor the names of the
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// Questions? Contact Christian R. Trott (crtrott@sandia.gov)
//
// ************************************************************************
//@HEADER
*/

#include <cstdio>

#include <gtest/gtest.h>

#include <Kokkos_Core.hpp>

namespace Test {

namespace {

template < typename ExecSpace >
struct TestViewCopy {

using InExecSpace = ExecSpace;

static void test_view_copy()
{
#if defined( KOKKOS_ENABLE_CUDA ) || defined( KOKKOS_ENABLE_ROCM )
// ExecSpace = CudaUVM, CudaHostPinned
// This test will fail at runtime with an illegal memory access if something goes wrong
// Test 1: deep_copy from host_space to ExecSpace and ExecSpace back to host_space
{
const int dim0 = 4;
const int dim1 = 2;
const int dim2 = 3;

typedef Kokkos::View<double****,InExecSpace> Rank4ViewType;
Rank4ViewType view_4;
view_4 = Rank4ViewType("view_4", dim0, dim1, dim2, dim2);

typedef typename Kokkos::Impl::is_space<InExecSpace>::host_mirror_space::execution_space host_space_type;
Kokkos::View<double**,Kokkos::LayoutLeft,host_space_type> srcView("srcView", dim2, dim2);

// Strided dst view
auto dstView = Kokkos::subview(view_4, 0, 0, Kokkos::ALL(), Kokkos::ALL());

const Kokkos::pair<int,int> range(0, dim2);

// host_space to ExecSpace
Kokkos::deep_copy( dstView, srcView );
Kokkos::fence();

// ExecSpace to host_space
Kokkos::deep_copy( srcView, dstView );
Kokkos::fence();
}

// Test 2: deep_copy from Cuda to ExecSpace and ExecSpace back to Cuda
{
const int dim0 = 4;
const int dim1 = 2;
const int dim2 = 3;

typedef Kokkos::View<double****,InExecSpace> Rank4ViewType;
Rank4ViewType view_4;
view_4 = Rank4ViewType("view_4", dim0, dim1, dim2, dim2);

#if defined( KOKKOS_ENABLE_CUDA )
typedef Kokkos::Cuda space_type;
#endif
#if defined( KOKKOS_ENABLE_ROCM )
typedef Kokkos::Experimental::ROCm space_type;
#endif
Kokkos::View<double**,Kokkos::LayoutLeft,space_type> srcView("srcView", dim2, dim2);

// Strided dst view
auto dstView = Kokkos::subview(view_4, 0, 0, Kokkos::ALL(), Kokkos::ALL());

const Kokkos::pair<int,int> range(0, dim2);

// Cuda to ExecSpace
Kokkos::deep_copy( dstView, srcView );
Kokkos::fence();

// ExecSpace to Cuda
Kokkos::deep_copy( srcView, dstView );
Kokkos::fence();
}
#endif
} // end test_view_copy

}; // end struct

} // namespace

TEST_F( TEST_CATEGORY , view_copy_tests ) {
//Only include this file to be compiled with CudaUVM and CudaHostPinned
TestViewCopy< TEST_EXECSPACE >::test_view_copy();
}

} // namespace Test
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
//@HEADER
// ************************************************************************
//
// Kokkos v. 2.0
// Copyright (2014) Sandia Corporation
//
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
// the U.S. Government retains certain rights in this software.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// 1. Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// 3. Neither the name of the Corporation nor the names of the
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// Questions? Contact Christian R. Trott (crtrott@sandia.gov)
//
// ************************************************************************
//@HEADER
*/

#include <cuda/TestCudaHostPinned_Category.hpp>
#include <TestViewCopy.hpp>
45 changes: 45 additions & 0 deletions packages/kokkos/core/unit_test/cuda/TestCudaUVM_ViewCopy.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
//@HEADER
// ************************************************************************
//
// Kokkos v. 2.0
// Copyright (2014) Sandia Corporation
//
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
// the U.S. Government retains certain rights in this software.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// 1. Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// 3. Neither the name of the Corporation nor the names of the
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// Questions? Contact Christian R. Trott (crtrott@sandia.gov)
//
// ************************************************************************
//@HEADER
*/

#include <cuda/TestCudaUVM_Category.hpp>
#include <TestViewCopy.hpp>
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
//@HEADER
// ************************************************************************
//
// Kokkos v. 2.0
// Copyright (2014) Sandia Corporation
//
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
// the U.S. Government retains certain rights in this software.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// 1. Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// 3. Neither the name of the Corporation nor the names of the
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// Questions? Contact Christian R. Trott (crtrott@sandia.gov)
//
// ************************************************************************
//@HEADER
*/

#include <rocm/TestROCmHostPinned_Category.hpp>
#include <TestViewCopy.hpp>