|
| 1 | +//***************************************************************************** |
| 2 | +// Copyright (c) 2016-2020, Intel Corporation |
| 3 | +// All rights reserved. |
| 4 | +// |
| 5 | +// Redistribution and use in source and binary forms, with or without |
| 6 | +// modification, are permitted provided that the following conditions are met: |
| 7 | +// - Redistributions of source code must retain the above copyright notice, |
| 8 | +// this list of conditions and the following disclaimer. |
| 9 | +// - Redistributions in binary form must reproduce the above copyright notice, |
| 10 | +// this list of conditions and the following disclaimer in the documentation |
| 11 | +// and/or other materials provided with the distribution. |
| 12 | +// |
| 13 | +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 14 | +// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 15 | +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 16 | +// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
| 17 | +// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 18 | +// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 19 | +// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 20 | +// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 21 | +// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 22 | +// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
| 23 | +// THE POSSIBILITY OF SUCH DAMAGE. |
| 24 | +//***************************************************************************** |
| 25 | + |
| 26 | +#include <iostream> |
| 27 | + |
| 28 | +#include "dpnp_fptr.hpp" |
| 29 | +#include "dpnp_iface.hpp" |
| 30 | +#include "queue_sycl.hpp" |
| 31 | + |
| 32 | +template <typename _KernelNameSpecialization> |
| 33 | +class dpnp_arange_c_kernel; |
| 34 | + |
| 35 | +template <typename _DataType> |
| 36 | +void dpnp_arange_c(size_t start, size_t step, void* result1, size_t size) |
| 37 | +{ |
| 38 | + // parameter `size` used instead `stop` to avoid dependency on array length calculation algorithm |
| 39 | + // TODO: floating point (and negatives) types from `start` and `step` |
| 40 | + |
| 41 | + if (!size) |
| 42 | + { |
| 43 | + return; |
| 44 | + } |
| 45 | + |
| 46 | + cl::sycl::event event; |
| 47 | + |
| 48 | + _DataType* result = reinterpret_cast<_DataType*>(result1); |
| 49 | + |
| 50 | + cl::sycl::range<1> gws(size); |
| 51 | + auto kernel_parallel_for_func = [=](cl::sycl::id<1> global_id) { |
| 52 | + size_t i = global_id[0]; |
| 53 | + |
| 54 | + result[i] = start + i * step; |
| 55 | + }; |
| 56 | + |
| 57 | + auto kernel_func = [&](cl::sycl::handler& cgh) { |
| 58 | + cgh.parallel_for<class dpnp_arange_c_kernel<_DataType>>(gws, kernel_parallel_for_func); |
| 59 | + }; |
| 60 | + |
| 61 | + event = DPNP_QUEUE.submit(kernel_func); |
| 62 | + |
| 63 | + event.wait(); |
| 64 | +} |
| 65 | + |
| 66 | +template <typename _KernelNameSpecialization> |
| 67 | +class dpnp_full_c_kernel; |
| 68 | + |
| 69 | +template <typename _DataType> |
| 70 | +void dpnp_full_c(void* array_in, void* result, const size_t size) |
| 71 | +{ |
| 72 | + dpnp_initval_c<_DataType>(result, array_in, size); |
| 73 | +} |
| 74 | + |
| 75 | +void func_map_init_arraycreation(func_map_t& fmap) |
| 76 | +{ |
| 77 | + fmap[DPNPFuncName::DPNP_FN_ARANGE][eft_INT][eft_INT] = {eft_INT, (void*)dpnp_arange_c<int>}; |
| 78 | + fmap[DPNPFuncName::DPNP_FN_ARANGE][eft_LNG][eft_LNG] = {eft_LNG, (void*)dpnp_arange_c<long>}; |
| 79 | + fmap[DPNPFuncName::DPNP_FN_ARANGE][eft_FLT][eft_FLT] = {eft_FLT, (void*)dpnp_arange_c<float>}; |
| 80 | + fmap[DPNPFuncName::DPNP_FN_ARANGE][eft_DBL][eft_DBL] = {eft_DBL, (void*)dpnp_arange_c<double>}; |
| 81 | + |
| 82 | + fmap[DPNPFuncName::DPNP_FN_FULL][eft_INT][eft_INT] = {eft_INT, (void*)dpnp_full_c<int>}; |
| 83 | + fmap[DPNPFuncName::DPNP_FN_FULL][eft_LNG][eft_LNG] = {eft_LNG, (void*)dpnp_full_c<long>}; |
| 84 | + fmap[DPNPFuncName::DPNP_FN_FULL][eft_FLT][eft_FLT] = {eft_FLT, (void*)dpnp_full_c<float>}; |
| 85 | + fmap[DPNPFuncName::DPNP_FN_FULL][eft_DBL][eft_DBL] = {eft_DBL, (void*)dpnp_full_c<double>}; |
| 86 | + |
| 87 | + return; |
| 88 | +} |
0 commit comments