Skip to content

[SYCL][Fusion][NoSTL] Reimplement Indices class without std::array #12340

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Jan 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 39 additions & 1 deletion sycl-fusion/common/include/Kernel.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,45 @@ struct SYCLArgumentDescriptor {
/// List of SYCL/OpenCL kernel attributes.
using AttributeList = std::vector<SYCLKernelAttribute>;

using Indices = std::array<size_t, 3>;
///
/// Class to model a three-dimensional index.
class Indices {
public:
static constexpr size_t size() { return Size; }

constexpr Indices() : Values{0, 0, 0} {}
constexpr Indices(size_t V1, size_t V2, size_t V3) : Values{V1, V2, V3} {}

constexpr const size_t *begin() const { return Values; }
constexpr const size_t *end() const { return Values + Size; }
constexpr size_t *begin() { return Values; }
constexpr size_t *end() { return Values + Size; }

constexpr const size_t &operator[](int Idx) const { return Values[Idx]; }
constexpr size_t &operator[](int Idx) { return Values[Idx]; }

friend bool operator==(const Indices &A, const Indices &B) {
return std::equal(A.begin(), A.end(), B.begin());
}

friend bool operator!=(const Indices &A, const Indices &B) {
return !(A == B);
}

friend bool operator<(const Indices &A, const Indices &B) {
return std::lexicographical_compare(A.begin(), A.end(), B.begin(), B.end(),
std::less<size_t>{});
}

friend bool operator>(const Indices &A, const Indices &B) {
return std::lexicographical_compare(A.begin(), A.end(), B.begin(), B.end(),
std::greater<size_t>{});
}

private:
static constexpr size_t Size = 3;
size_t Values[Size];
};

///
/// Class to model SYCL nd_range
Expand Down
2 changes: 1 addition & 1 deletion sycl-fusion/jit-compiler/lib/fusion/FusionHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ Expected<std::unique_ptr<Module>> helper::FusionHelper::addFusedKernel(
{
const auto MDFromND = [&LLVMCtx](const auto &ND) {
auto MDFromIndices = [&LLVMCtx](const auto &Ind) -> Metadata * {
std::array<Metadata *, jit_compiler::Indices{}.size()> MD{nullptr};
std::array<Metadata *, jit_compiler::Indices::size()> MD{nullptr};
std::transform(
Ind.begin(), Ind.end(), MD.begin(),
[&LLVMCtx](auto I) { return getConstantIntMD(LLVMCtx, I); });
Expand Down
4 changes: 4 additions & 0 deletions sycl-fusion/jit-compiler/lib/fusion/Hashing.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ inline llvm::hash_code hash_value(const ParameterIdentity &IP) {
return llvm::hash_combine(IP.LHS, IP.RHS);
}

inline llvm::hash_code hash_value(const Indices &I) {
return llvm::hash_combine_range(I.begin(), I.end());
}

inline llvm::hash_code hash_value(const NDRange &ND) {
return llvm::hash_combine(ND.getDimensions(), ND.getGlobalSize(),
ND.getLocalSize(), ND.getOffset());
Expand Down