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 mutator for test input data #789
Merged
Merged
Changes from 4 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
0d8b1d4
[SYCL][ESIMD] Add mutator for test input data
vasilytric 7cc2f67
[SYCL][ESIMD] Update logic for mutator functors and update comments
vasilytric 5355c22
[SYCL][ESIMD] Add necessary includes
vasilytric 4d4d192
[SYCL][ESIMD] Small updates
vasilytric 41df5e5
[SYCL][ESIMD] Update functions logic and comments
vasilytric c9ec74d
[SYCL][ESIMD] Update case with negative numbers for "For_multiplication"
vasilytric 3341294
[SYCL][ESIMD] Skip deletion in case that current element is infinity
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
//===-- mutator.hpp - This file provides common function and classes to mutate | ||
// reference data. ---------------------------------------------------===// | ||
// | ||
// 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 function and classes to mutate reference data. | ||
/// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#pragma once | ||
|
||
#include "type_traits.hpp" | ||
#include "value.hpp" | ||
#include <sycl/sycl.hpp> | ||
|
||
// for std::for_each | ||
#include <algorithm> | ||
#include <vector> | ||
|
||
namespace esimd_test::api::functional { | ||
|
||
// In some test cases it’s possible to pass a reference data as the input data | ||
// directly without any modification. For example, if we check some copy | ||
// constructor or memory move operation it’s OK to have any data values as the | ||
// input ones. But in most cases we need to consider the possibility of UB for | ||
// C++ operations due to modification of input values. | ||
// | ||
// Mutation mechanism covers such requirement. | ||
// The mutator namespace is intended to store such mutators alongside with | ||
// the generic ones provided below. | ||
namespace mutator { | ||
|
||
// Replace specific reference values to the bigger ones, so we can safely | ||
// substract `val` later. | ||
template <typename T> class For_subtraction { | ||
T m_value; | ||
|
||
public: | ||
For_subtraction(T val) | ||
: m_value((assert(val > 0 && "Invalid value."), val)) {} | ||
|
||
void operator()(T &val) { | ||
// Floating point variable with infinity value shouldn't be changed. | ||
if constexpr (type_traits::is_sycl_signed_v<T>) { | ||
if constexpr (type_traits::is_sycl_floating_point_v<T>) { | ||
// sycl::half will be converted to float | ||
if (std::isinf(val)) { | ||
return; | ||
} | ||
} | ||
|
||
const T lower_border = value<T>::lowest() + m_value; | ||
if (val < lower_border) { | ||
val = lower_border; | ||
} | ||
vasilytric marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
} | ||
}; | ||
|
||
// Replace specific reference values to the smaller ones, so we can safely add | ||
// `val` later. | ||
template <typename T> class For_addition { | ||
T m_value; | ||
|
||
public: | ||
For_addition(T val) : m_value((assert(val > 0 && "Invalid value."), val)) {} | ||
|
||
void operator()(T &val) { | ||
// Floating point variable with infinity value shouldn't be changed. | ||
if constexpr (type_traits::is_sycl_floating_point_v<T>) { | ||
// sycl::half will be converted to float | ||
if (std::isinf(val)) { | ||
return; | ||
} | ||
} | ||
|
||
if constexpr (type_traits::is_sycl_signed_v<T>) { | ||
const T upper_border = value<T>::max() - m_value; | ||
if (val > upper_border) { | ||
val = upper_border; | ||
} | ||
} | ||
} | ||
}; | ||
|
||
// Replace specific reference values to the divided ones, so we can safely | ||
// multiply to `val` later. | ||
template <typename T> class For_multiplication { | ||
T m_value; | ||
|
||
public: | ||
For_multiplication(T val) | ||
: m_value((assert(val > 0 && "Invalid value."), val)) {} | ||
|
||
void operator()(T &val) { | ||
if (val != value<T>::denorm_min()) { | ||
val /= m_value; | ||
} | ||
} | ||
}; | ||
|
||
} // namespace mutator | ||
|
||
// Applies provided mutator to each value for provided container. | ||
template <typename T, typename MutatorT> | ||
inline void mutate(std::vector<T> &input_vector, MutatorT &&mutator) { | ||
std::for_each(input_vector.begin(), input_vector.end(), mutator); | ||
} | ||
|
||
} // namespace esimd_test::api::functional |
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
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.