This repository was archived by the owner on Mar 28, 2023. It is now read-only.
forked from llvm/llvm-test-suite
-
Notifications
You must be signed in to change notification settings - Fork 130
[SYCL][ESIMD] Add tests on simd copy and move assignment operators #762
Merged
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
5e4fa35
[SYCL][ESIMD] Add tests on simd copy and move assignment operators
vasilytric c08d8bc
[SYCL][ESIMD] Update file structure
vasilytric 8180aea
[SYCL][ESIMD] Add shared element that lets interact with USM
vasilytric afbf175
[SYCL][ESIMD] Update shared_elem and small changes
vasilytric 4be7ac9
[SYCL][ESIMD] Move tests on operators into separate folder
vasilytric cdfde0a
[SYCL][ESIMD] Use bool for shared_element
vasilytric a475d09
[SYCL][ESIMD] Apply clang-format
vasilytric 92df51c
[SYCL][ESIMD] Small updates
vasilytric b0637d6
Merge branch 'intel' into copy_move_assgnment
vasilytric 85f66a6
[SYCL][ESIMD] Use separate common files for tests on ctors and operators
vasilytric 58eab1a
Merge branch 'intel' into copy_move_assgnment
vasilytric e2cd610
[SYCL][ESIMD] Apply clang-format
vasilytric bc238e4
[SYCL][ESIMD] Use for_all_combinations instead of for_all_types_and_dims
vasilytric a80c2e3
[SYCL][ESIMD] Unite tests on copy and move assignment operators into …
vasilytric f6c0e98
[SYCL][ESIMD] Update comments
vasilytric e8b8148
[SYCL][ESIMD] Remove unused kernel definitions
vasilytric 15be4a4
Merge branch 'intel' into copy_move_assgnment
vasilytric 527c0cb
[SYCL][ESIMD] Replace ctors::Kernel with Kernel
vasilytric File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
//===-- common.hpp - Define common code for simd operators tests ----------===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
/// | ||
/// \file | ||
/// This file provides common things for simd operators tests. | ||
/// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#pragma once | ||
|
||
#include "../common.hpp" | ||
|
||
namespace esimd_test::api::functional::operators { | ||
|
||
template <typename DataT, int NumElems> | ||
class TestDescription : public ITestDescription { | ||
public: | ||
TestDescription(size_t index, DataT retrieved_val, DataT expected_val, | ||
const std::string &data_type) | ||
: m_data_type(data_type), m_retrieved_val(retrieved_val), | ||
m_expected_val(expected_val), m_index(index) {} | ||
|
||
std::string to_string() const override { | ||
// TODO: Make strings for fp values more short during failure output, may be | ||
// by using hex representation | ||
std::string log_msg("Failed for simd<"); | ||
|
||
log_msg += m_data_type + ", " + std::to_string(NumElems) + ">"; | ||
log_msg += ", retrieved: " + std::to_string(m_retrieved_val); | ||
log_msg += ", expected: " + std::to_string(m_expected_val); | ||
log_msg += ", at index: " + std::to_string(m_index); | ||
|
||
return log_msg; | ||
} | ||
|
||
private: | ||
const std::string m_data_type; | ||
const DataT m_retrieved_val; | ||
const DataT m_expected_val; | ||
const size_t m_index; | ||
}; | ||
|
||
} // namespace esimd_test::api::functional::operators |
98 changes: 98 additions & 0 deletions
98
SYCL/ESIMD/api/functional/operators/operator_assignment.hpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
//===-- operator_assignment.hpp - Functions for tests on simd assignment | ||
// operators. --------------------------------------------------------===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
/// | ||
/// \file | ||
/// This file provides functions for tests on simd assignment operators. | ||
/// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#pragma once | ||
|
||
// The test proxy is used to verify the move assignment was called actually. | ||
#define __ESIMD_ENABLE_TEST_PROXY | ||
|
||
#include "../shared_element.hpp" | ||
#include "common.hpp" | ||
|
||
namespace esimd_test::api::functional::operators { | ||
|
||
// The main test routine. | ||
// Using functor class to be able to iterate over the pre-defined data types. | ||
template <typename DataT, typename DimT, typename TestCaseT> class run_test { | ||
static constexpr int NumElems = DimT::value; | ||
|
||
public: | ||
bool operator()(sycl::queue &queue, const std::string &data_type) { | ||
bool passed = true; | ||
const std::vector<DataT> ref_data = generate_ref_data<DataT, NumElems>(); | ||
|
||
// If current number of elements is equal to one, then run test with each | ||
// one value from reference data. | ||
// If current number of elements is greater than one, then run tests with | ||
// whole reference data. | ||
if constexpr (NumElems == 1) { | ||
for (size_t i = 0; i < ref_data.size(); ++i) { | ||
passed = run_verification(queue, {ref_data[i]}, data_type); | ||
} | ||
} else { | ||
passed = run_verification(queue, ref_data, data_type); | ||
} | ||
return passed; | ||
} | ||
|
||
private: | ||
bool run_verification(sycl::queue &queue, const std::vector<DataT> &ref_data, | ||
const std::string &data_type) { | ||
assert(ref_data.size() == NumElems && | ||
"Reference data size is not equal to the simd vector length."); | ||
|
||
bool passed = true; | ||
|
||
shared_allocator<DataT> allocator(queue); | ||
shared_vector<DataT> result(NumElems, allocator); | ||
shared_vector<DataT> shared_ref_data(ref_data.begin(), ref_data.end(), | ||
allocator); | ||
|
||
shared_element<bool> is_correct_operator(queue, false); | ||
|
||
queue.submit([&](sycl::handler &cgh) { | ||
const DataT *const ref = shared_ref_data.data(); | ||
DataT *const out = result.data(); | ||
const auto is_correct_operator_storage = is_correct_operator.data(); | ||
|
||
cgh.single_task<Kernel<DataT, NumElems, TestCaseT>>( | ||
[=]() SYCL_ESIMD_KERNEL { | ||
*is_correct_operator_storage = | ||
TestCaseT::template run<DataT, NumElems>(ref, out); | ||
}); | ||
}); | ||
queue.wait_and_throw(); | ||
|
||
for (size_t i = 0; i < result.size(); ++i) { | ||
if (!are_bitwise_equal(ref_data[i], result[i])) { | ||
passed = false; | ||
|
||
const auto description = TestDescription<DataT, NumElems>( | ||
i, result[i], ref_data[i], data_type); | ||
log::fail(description); | ||
} | ||
} | ||
|
||
if (!is_correct_operator.value()) { | ||
passed = false; | ||
log::note("Test failed due to " + TestCaseT::get_description() + | ||
" hasn't called for simd<" + data_type + ", " + | ||
std::to_string(NumElems) + ">."); | ||
} | ||
|
||
return passed; | ||
} | ||
}; | ||
|
||
} // namespace esimd_test::api::functional::operators |
77 changes: 77 additions & 0 deletions
77
SYCL/ESIMD/api/functional/operators/operator_assignment_move_and_copy_core.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
//==------- operator_assignment_move_and_copy_core.cpp - DPC++ ESIMD on-device | ||
// test -----------------------------------------------------------==// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
// REQUIRES: gpu, level_zero | ||
// XREQUIRES: gpu | ||
// TODO gpu and level_zero in REQUIRES due to only this platforms supported yet. | ||
// The current "REQUIRES" should be replaced with "gpu" only as mentioned in | ||
// "XREQUIRES". | ||
// RUN: %clangxx -fsycl %s -fsycl-device-code-split=per_kernel -o %t.out | ||
// RUN: %GPU_RUN_PLACEHOLDER %t.out | ||
// XFAIL: * | ||
// TODO Remove XFAIL once the simd vector provides move assignment operator | ||
// | ||
// Test for simd move and copy assignment operators. | ||
// The test creates source simd instance with reference data and invokes move or | ||
// copy assignment operator from source to destination simd instance. It is | ||
// expected for destination simd instance to store a bitwise same data as the | ||
// reference one. | ||
|
||
#include "operator_assignment.hpp" | ||
|
||
using namespace sycl::ext::intel::experimental::esimd; | ||
using namespace esimd_test::api::functional; | ||
|
||
// Descriptor class for the case of calling move assignment operator. | ||
struct move_assignment { | ||
static std::string get_description() { return "move assignment operator"; } | ||
|
||
template <typename DataT, int NumElems> | ||
static bool run(const DataT *const ref_data, DataT *const out) { | ||
simd<DataT, NumElems> source_simd; | ||
source_simd.copy_from(ref_data); | ||
simd<DataT, NumElems> simd_obj; | ||
simd_obj = std::move(source_simd); | ||
simd_obj.copy_to(out); | ||
return simd_obj.get_test_proxy().was_move_destination() == true; | ||
} | ||
}; | ||
|
||
// Descriptor class for the case of calling copy assignment operator. | ||
struct copy_assignment { | ||
static std::string get_description() { return "copy assignment operator"; } | ||
|
||
template <typename DataT, int NumElems> | ||
static bool run(const DataT *const ref_data, DataT *const out) { | ||
simd<DataT, NumElems> source_simd; | ||
source_simd.copy_from(ref_data); | ||
simd<DataT, NumElems> simd_obj; | ||
simd_obj = source_simd; | ||
simd_obj.copy_to(out); | ||
return simd_obj.get_test_proxy().was_move_destination() == false; | ||
} | ||
}; | ||
|
||
int main(int, char **) { | ||
sycl::queue queue(esimd_test::ESIMDSelector{}, | ||
esimd_test::createExceptionHandler()); | ||
|
||
bool passed = true; | ||
|
||
const auto types = get_tested_types<tested_types::all>(); | ||
const auto dims = get_all_dimensions(); | ||
|
||
const auto context = | ||
unnamed_type_pack<move_assignment, copy_assignment>::generate(); | ||
|
||
passed &= | ||
for_all_combinations<operators::run_test>(types, dims, context, queue); | ||
|
||
std::cout << (passed ? "=== Test passed\n" : "=== Test FAILED\n"); | ||
return passed ? 0 : 1; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
//===-- shared_elements.hpp - Function that provides USM with a smart pointer. | ||
// -------------------------------------------------------------------===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
/// | ||
/// \file | ||
/// This file provides data struct that lets interact with USM with a smart | ||
/// pointer that lets avoid memory leaks. | ||
/// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#pragma once | ||
|
||
#include <sycl/sycl.hpp> | ||
|
||
#include <functional> | ||
#include <memory> | ||
|
||
namespace esimd_test::api::functional { | ||
|
||
// Provides APIs to interact with USM pointer without memory leaks for a single | ||
// variable. Might be useful to provide access to a single boolean flag to store | ||
// success, for example. | ||
template <typename T> class shared_element { | ||
std::unique_ptr<T, std::function<void(T *)>> m_allocated_data; | ||
|
||
public: | ||
shared_element(sycl::queue &queue, T initial_value) { | ||
const auto &device{queue.get_device()}; | ||
const auto &context{queue.get_context()}; | ||
|
||
auto deleter = [=](T *ptr) { sycl::free(ptr, context); }; | ||
|
||
m_allocated_data = std::unique_ptr<T, decltype(deleter)>( | ||
sycl::malloc_shared<T>(1, device, context), deleter); | ||
|
||
assert(m_allocated_data && "USM memory allocation failed"); | ||
*m_allocated_data = initial_value; | ||
} | ||
|
||
T *data() { return m_allocated_data.get(); } | ||
|
||
const T *data() const { return m_allocated_data.get(); } | ||
|
||
T value() { return *m_allocated_data.get(); } | ||
vasilytric marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
T value() const { return *m_allocated_data.get(); } | ||
}; | ||
|
||
} // namespace esimd_test::api::functional |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.