1 /* 2 //@HEADER 3 // ************************************************************************ 4 // 5 // Kokkos v. 3.0 6 // Copyright (2020) National Technology & Engineering 7 // Solutions of Sandia, LLC (NTESS). 8 // 9 // Under the terms of Contract DE-NA0003525 with NTESS, 10 // the U.S. Government retains certain rights in this software. 11 // 12 // Redistribution and use in source and binary forms, with or without 13 // modification, are permitted provided that the following conditions are 14 // met: 15 // 16 // 1. Redistributions of source code must retain the above copyright 17 // notice, this list of conditions and the following disclaimer. 18 // 19 // 2. Redistributions in binary form must reproduce the above copyright 20 // notice, this list of conditions and the following disclaimer in the 21 // documentation and/or other materials provided with the distribution. 22 // 23 // 3. Neither the name of the Corporation nor the names of the 24 // contributors may be used to endorse or promote products derived from 25 // this software without specific prior written permission. 26 // 27 // THIS SOFTWARE IS PROVIDED BY NTESS "AS IS" AND ANY 28 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 29 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 30 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL NTESS OR THE 31 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 32 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 33 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 34 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 35 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 36 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 37 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 38 // 39 // Questions? Contact Christian R. Trott (crtrott@sandia.gov) 40 // 41 // ************************************************************************ 42 //@HEADER 43 */ 44 45 #ifndef KOKKOS_SYCLDEEPCOPY_HPP 46 #define KOKKOS_SYCLDEEPCOPY_HPP 47 48 #include <Kokkos_Core_fwd.hpp> 49 #include <Kokkos_SYCL.hpp> 50 51 #ifdef KOKKOS_ENABLE_SYCL 52 53 namespace Kokkos { 54 namespace Impl { 55 56 template <> 57 struct DeepCopy<Kokkos::Experimental::SYCLDeviceUSMSpace, 58 Kokkos::Experimental::SYCLDeviceUSMSpace, 59 Kokkos::Experimental::SYCL> { 60 DeepCopy(void* dst, const void* src, size_t); 61 DeepCopy(const Kokkos::Experimental::SYCL&, void* dst, const void* src, 62 size_t); 63 }; 64 65 template <> 66 struct DeepCopy<Kokkos::HostSpace, Kokkos::Experimental::SYCLDeviceUSMSpace, 67 Kokkos::Experimental::SYCL> { 68 DeepCopy(void* dst, const void* src, size_t); 69 DeepCopy(const Kokkos::Experimental::SYCL&, void* dst, const void* src, 70 size_t); 71 }; 72 73 template <> 74 struct DeepCopy<Kokkos::Experimental::SYCLDeviceUSMSpace, Kokkos::HostSpace, 75 Kokkos::Experimental::SYCL> { 76 DeepCopy(void* dst, const void* src, size_t); 77 DeepCopy(const Kokkos::Experimental::SYCL&, void* dst, const void* src, 78 size_t); 79 }; 80 81 template <class ExecutionSpace> 82 struct DeepCopy<Kokkos::Experimental::SYCLDeviceUSMSpace, 83 Kokkos::Experimental::SYCLDeviceUSMSpace, ExecutionSpace> { DeepCopyKokkos::Impl::DeepCopy84 DeepCopy(void* dst, const void* src, size_t n) { 85 (void)DeepCopy<Kokkos::Experimental::SYCLDeviceUSMSpace, 86 Kokkos::Experimental::SYCLDeviceUSMSpace, 87 Kokkos::Experimental::SYCL>(dst, src, n); 88 } 89 DeepCopyKokkos::Impl::DeepCopy90 DeepCopy(const ExecutionSpace& exec, void* dst, const void* src, size_t n) { 91 exec.fence(); 92 DeepCopy<Kokkos::Experimental::SYCLDeviceUSMSpace, 93 Kokkos::Experimental::SYCLDeviceUSMSpace, 94 Kokkos::Experimental::SYCL>(Kokkos::Experimental::SYCL(), dst, src, 95 n); 96 Kokkos::Experimental::SYCL().fence(); 97 } 98 }; 99 100 template <class ExecutionSpace> 101 struct DeepCopy<Kokkos::HostSpace, Kokkos::Experimental::SYCLDeviceUSMSpace, 102 ExecutionSpace> { DeepCopyKokkos::Impl::DeepCopy103 DeepCopy(void* dst, const void* src, size_t n) { 104 (void)DeepCopy<Kokkos::HostSpace, Kokkos::Experimental::SYCLDeviceUSMSpace, 105 Kokkos::Experimental::SYCL>(dst, src, n); 106 } 107 DeepCopyKokkos::Impl::DeepCopy108 DeepCopy(const ExecutionSpace& exec, void* dst, const void* src, size_t n) { 109 exec.fence(); 110 DeepCopy<Kokkos::HostSpace, Kokkos::Experimental::SYCLDeviceUSMSpace, 111 Kokkos::Experimental::SYCL>(Kokkos::Experimental::SYCL(), dst, src, 112 n); 113 Kokkos::Experimental::SYCL().fence(); 114 } 115 }; 116 117 template <class ExecutionSpace> 118 struct DeepCopy<Kokkos::Experimental::SYCLDeviceUSMSpace, Kokkos::HostSpace, 119 ExecutionSpace> { DeepCopyKokkos::Impl::DeepCopy120 DeepCopy(void* dst, const void* src, size_t n) { 121 (void)DeepCopy<Kokkos::Experimental::SYCLDeviceUSMSpace, Kokkos::HostSpace, 122 Kokkos::Experimental::SYCL>(dst, src, n); 123 } 124 DeepCopyKokkos::Impl::DeepCopy125 DeepCopy(const ExecutionSpace& exec, void* dst, const void* src, size_t n) { 126 exec.fence(); 127 DeepCopy<Kokkos::Experimental::SYCLDeviceUSMSpace, Kokkos::HostSpace, 128 Kokkos::Experimental::SYCL>(Kokkos::Experimental::SYCL(), dst, src, 129 n); 130 Kokkos::Experimental::SYCL().fence(); 131 } 132 }; 133 134 template <> 135 struct DeepCopy<Experimental::SYCLSharedUSMSpace, 136 Experimental::SYCLSharedUSMSpace, Kokkos::Experimental::SYCL> 137 : public DeepCopy<Experimental::SYCLDeviceUSMSpace, 138 Experimental::SYCLDeviceUSMSpace, 139 Kokkos::Experimental::SYCL> { 140 using DeepCopy<Experimental::SYCLDeviceUSMSpace, 141 Experimental::SYCLDeviceUSMSpace, 142 Kokkos::Experimental::SYCL>::DeepCopy; 143 }; 144 145 template <> 146 struct DeepCopy<Experimental::SYCLSharedUSMSpace, HostSpace, 147 Kokkos::Experimental::SYCL> 148 : public DeepCopy<Experimental::SYCLDeviceUSMSpace, HostSpace, 149 Kokkos::Experimental::SYCL> { 150 using DeepCopy<Experimental::SYCLDeviceUSMSpace, HostSpace, 151 Kokkos::Experimental::SYCL>::DeepCopy; 152 }; 153 154 template <> 155 struct DeepCopy<HostSpace, Experimental::SYCLSharedUSMSpace, 156 Kokkos::Experimental::SYCL> 157 : public DeepCopy<HostSpace, Experimental::SYCLDeviceUSMSpace, 158 Kokkos::Experimental::SYCL> { 159 using DeepCopy<HostSpace, Experimental::SYCLDeviceUSMSpace, 160 Kokkos::Experimental::SYCL>::DeepCopy; 161 }; 162 163 template <> 164 struct DeepCopy<Experimental::SYCLSharedUSMSpace, 165 Experimental::SYCLDeviceUSMSpace, Kokkos::Experimental::SYCL> 166 : public DeepCopy<Experimental::SYCLDeviceUSMSpace, 167 Experimental::SYCLDeviceUSMSpace, 168 Kokkos::Experimental::SYCL> { 169 using DeepCopy<Experimental::SYCLDeviceUSMSpace, 170 Experimental::SYCLDeviceUSMSpace, 171 Kokkos::Experimental::SYCL>::DeepCopy; 172 }; 173 174 template <> 175 struct DeepCopy<Experimental::SYCLDeviceUSMSpace, 176 Experimental::SYCLSharedUSMSpace, Kokkos::Experimental::SYCL> 177 : public DeepCopy<Experimental::SYCLDeviceUSMSpace, 178 Experimental::SYCLDeviceUSMSpace, 179 Kokkos::Experimental::SYCL> { 180 using DeepCopy<Experimental::SYCLDeviceUSMSpace, 181 Experimental::SYCLDeviceUSMSpace, 182 Kokkos::Experimental::SYCL>::DeepCopy; 183 }; 184 185 template <class ExecutionSpace> 186 struct DeepCopy<Experimental::SYCLDeviceUSMSpace, 187 Experimental::SYCLSharedUSMSpace, ExecutionSpace> 188 : public DeepCopy<Experimental::SYCLDeviceUSMSpace, 189 Experimental::SYCLDeviceUSMSpace, ExecutionSpace> { 190 using DeepCopy<Experimental::SYCLDeviceUSMSpace, 191 Experimental::SYCLDeviceUSMSpace, ExecutionSpace>::DeepCopy; 192 }; 193 194 template <class ExecutionSpace> 195 struct DeepCopy<Experimental::SYCLSharedUSMSpace, 196 Experimental::SYCLDeviceUSMSpace, ExecutionSpace> 197 : public DeepCopy<Experimental::SYCLDeviceUSMSpace, 198 Experimental::SYCLDeviceUSMSpace, ExecutionSpace> { 199 using DeepCopy<Experimental::SYCLDeviceUSMSpace, 200 Experimental::SYCLDeviceUSMSpace, ExecutionSpace>::DeepCopy; 201 }; 202 203 template <class ExecutionSpace> 204 struct DeepCopy<Experimental::SYCLSharedUSMSpace, 205 Experimental::SYCLSharedUSMSpace, ExecutionSpace> 206 : public DeepCopy<Experimental::SYCLDeviceUSMSpace, 207 Experimental::SYCLDeviceUSMSpace, ExecutionSpace> { 208 using DeepCopy<Experimental::SYCLDeviceUSMSpace, 209 Experimental::SYCLDeviceUSMSpace, ExecutionSpace>::DeepCopy; 210 }; 211 212 template <class ExecutionSpace> 213 struct DeepCopy<Experimental::SYCLSharedUSMSpace, HostSpace, ExecutionSpace> 214 : public DeepCopy<Experimental::SYCLDeviceUSMSpace, HostSpace, 215 ExecutionSpace> { 216 using DeepCopy<Experimental::SYCLDeviceUSMSpace, HostSpace, 217 ExecutionSpace>::DeepCopy; 218 }; 219 220 template <class ExecutionSpace> 221 struct DeepCopy<HostSpace, Experimental::SYCLSharedUSMSpace, ExecutionSpace> 222 : public DeepCopy<HostSpace, Experimental::SYCLDeviceUSMSpace, 223 ExecutionSpace> { 224 using DeepCopy<HostSpace, Experimental::SYCLDeviceUSMSpace, 225 ExecutionSpace>::DeepCopy; 226 }; 227 228 } // namespace Impl 229 } // namespace Kokkos 230 #endif 231 #endif 232