|
| 1 | +//==------- ctor_copy.cpp - DPC++ ESIMD on-device test --------------------==// |
| 2 | +// |
| 3 | +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | +// See https://llvm.org/LICENSE.txt for license information. |
| 5 | +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 | +// |
| 7 | +//===----------------------------------------------------------------------===// |
| 8 | +// REQUIRES: gpu, level_zero |
| 9 | +// XREQUIRES: gpu |
| 10 | +// TODO gpu and level_zero in REQUIRES due to only this platforms supported yet. |
| 11 | +// The current "REQUIRES" should be replaced with "gpu" only as mentioned in |
| 12 | +// "XREQUIRES". |
| 13 | +// UNSUPPORTED: cuda, hip |
| 14 | +// XRUN: %clangxx -fsycl %s -fsycl-device-code-split=per_kernel -o %t.out |
| 15 | +// XRUN: %GPU_RUN_PLACEHOLDER %t.out |
| 16 | +// RUN: false |
| 17 | +// XFAIL: * |
| 18 | +// TODO Unexpected static_assert was retrieved while calling simd::copy_from() |
| 19 | +// function. The issue was created (https://github.com/intel/llvm/issues/5112) |
| 20 | +// and the test must be enabled when it is resolved. |
| 21 | +// |
| 22 | +// Test for esimd copy constructor. |
| 23 | + |
| 24 | +#include "common.hpp" |
| 25 | + |
| 26 | +using namespace sycl; |
| 27 | +using namespace sycl::ext::intel::experimental::esimd; |
| 28 | +using namespace esimd_test::api::functional::ctors; |
| 29 | +using namespace esimd_test::api::functional; |
| 30 | + |
| 31 | +// Descriptor class for the case of calling constructor in initializer context. |
| 32 | +struct initializer { |
| 33 | + static std::string get_description() { return "initializer"; } |
| 34 | + |
| 35 | + template <typename DataT, int NumElems> |
| 36 | + static simd<DataT, NumElems> call_simd_ctor(const DataT *ref_data) { |
| 37 | + simd<DataT, NumElems> source_simd; |
| 38 | + source_simd.copy_from(ref_data); |
| 39 | + simd<DataT, NumElems> simd_by_init = simd<DataT, NumElems>(source_simd); |
| 40 | + return simd_by_init; |
| 41 | + } |
| 42 | +}; |
| 43 | + |
| 44 | +// Descriptor class for the case of calling constructor in variable declaration |
| 45 | +// context. |
| 46 | +struct var_declaration { |
| 47 | + static std::string get_description() { return "variable declaration"; } |
| 48 | + |
| 49 | + template <typename DataT, int NumElems> |
| 50 | + static simd<DataT, NumElems> call_simd_ctor(const DataT *ref_data) { |
| 51 | + simd<DataT, NumElems> source_simd; |
| 52 | + source_simd.copy_from(ref_data); |
| 53 | + simd<DataT, NumElems> simd_by_var_decl{source_simd}; |
| 54 | + return simd_by_var_decl; |
| 55 | + } |
| 56 | +}; |
| 57 | + |
| 58 | +// Descriptor class for the case of calling constructor in rvalue in an |
| 59 | +// expression context. |
| 60 | +struct rval_in_expression { |
| 61 | + static std::string get_description() { return "rvalue in an expression"; } |
| 62 | + |
| 63 | + template <typename DataT, int NumElems> |
| 64 | + static simd<DataT, NumElems> call_simd_ctor(const DataT *ref_data) { |
| 65 | + simd<DataT, NumElems> source_simd; |
| 66 | + source_simd.copy_from(ref_data); |
| 67 | + simd<DataT, NumElems> simd_by_rval; |
| 68 | + simd_by_rval = simd<DataT, NumElems>(source_simd); |
| 69 | + return simd_by_rval; |
| 70 | + } |
| 71 | +}; |
| 72 | + |
| 73 | +// Descriptor class for the case of calling constructor in const reference |
| 74 | +// context. |
| 75 | +class const_ref { |
| 76 | +public: |
| 77 | + static std::string get_description() { return "const reference"; } |
| 78 | + |
| 79 | + template <typename DataT, int NumElems> |
| 80 | + static simd<DataT, NumElems> call_simd_ctor(const DataT *ref_data) { |
| 81 | + simd<DataT, NumElems> source_simd; |
| 82 | + source_simd.copy_from(ref_data); |
| 83 | + return call_simd_by_const_ref<DataT, NumElems>( |
| 84 | + simd<DataT, NumElems>(source_simd)); |
| 85 | + } |
| 86 | + |
| 87 | +private: |
| 88 | + template <typename DataT, int NumElems> |
| 89 | + static simd<DataT, NumElems> |
| 90 | + call_simd_by_const_ref(const simd<DataT, NumElems> &simd_by_const_ref) { |
| 91 | + return simd_by_const_ref; |
| 92 | + } |
| 93 | +}; |
| 94 | + |
| 95 | +template <typename DataT, typename TestT> |
| 96 | +using run_test_with_one_elem = test<DataT, 1, TestT>; |
| 97 | + |
| 98 | +template <typename DataT, typename TestT> |
| 99 | +using run_test_with_eight_elems = test<DataT, 8, TestT>; |
| 100 | + |
| 101 | +template <typename DataT, typename TestT> |
| 102 | +using run_test_with_sixteen_elems = test<DataT, 16, TestT>; |
| 103 | + |
| 104 | +template <typename DataT, typename TestT> |
| 105 | +using run_test_with_thirty_two_elems = test<DataT, 32, TestT>; |
| 106 | + |
| 107 | +template <typename TestT, typename... T> |
| 108 | +bool run_verification_for_type(sycl::queue &queue, |
| 109 | + const named_type_pack<T...> &types) { |
| 110 | + bool passed{true}; |
| 111 | + |
| 112 | + passed &= for_all_types<run_test_with_one_elem, TestT>(types, queue); |
| 113 | + passed &= for_all_types<run_test_with_eight_elems, TestT>(types, queue); |
| 114 | + passed &= for_all_types<run_test_with_sixteen_elems, TestT>(types, queue); |
| 115 | + passed &= for_all_types<run_test_with_thirty_two_elems, TestT>(types, queue); |
| 116 | + return passed; |
| 117 | +} |
| 118 | + |
| 119 | +int main(int argc, char **argv) { |
| 120 | + sycl::queue queue{esimd_test::ESIMDSelector{}, |
| 121 | + esimd_test::createExceptionHandler()}; |
| 122 | + |
| 123 | + bool passed{true}; |
| 124 | + |
| 125 | + auto types{get_tested_types<tested_types::all>()}; |
| 126 | + |
| 127 | + passed &= run_verification_for_type<initializer>(queue, types); |
| 128 | + passed &= run_verification_for_type<var_declaration>(queue, types); |
| 129 | + passed &= run_verification_for_type<rval_in_expression>(queue, types); |
| 130 | + passed &= run_verification_for_type<const_ref>(queue, types); |
| 131 | + |
| 132 | + std::cout << (passed ? "=== Test passed\n" : "=== Test FAILED\n"); |
| 133 | + return passed ? 0 : 1; |
| 134 | +} |
0 commit comments