Skip to content

Commit 3367d96

Browse files
authored
[SYCL][Fusion][NoSTL] Store JIT constant data in a DynArray (#12392)
Use our custom `DynArray` container instead of an `std::string` to store a JIT constant's bytes. *This PR is part of a series of changes to remove uses of STL classes in the kernel fusion interface to prevent ABI issues in the future.* Signed-off-by: Julian Oppermann <[email protected]>
1 parent e62f3ba commit 3367d96

File tree

4 files changed

+22
-5
lines changed

4 files changed

+22
-5
lines changed

sycl-fusion/common/include/DynArray.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,14 @@ template <typename T> class DynArray {
5555
const T &operator[](int Idx) const { return Values[Idx]; }
5656
T &operator[](int Idx) { return Values[Idx]; }
5757

58+
friend bool operator==(const DynArray<T> &A, const DynArray<T> &B) {
59+
return std::equal(A.begin(), A.end(), B.begin(), B.end());
60+
}
61+
62+
friend bool operator!=(const DynArray<T> &A, const DynArray<T> &B) {
63+
return !(A == B);
64+
}
65+
5866
private:
5967
T *Values = nullptr;
6068
size_t Size = 0;

sycl-fusion/jit-compiler/include/Parameter.h

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@
99
#ifndef SYCL_FUSION_JIT_COMPILER_PARAMETER_H
1010
#define SYCL_FUSION_JIT_COMPILER_PARAMETER_H
1111

12+
#include "DynArray.h"
13+
14+
#include <algorithm>
1215
#include <cstdint>
13-
#include <string>
1416
#include <vector>
1517

1618
namespace jit_compiler {
@@ -103,10 +105,13 @@ struct ParameterInternalization {
103105
/// Client of the API owns the data held by `ValPtr`.
104106
struct JITConstant {
105107
Parameter Param;
106-
std::string Value;
108+
DynArray<char> Value;
107109
JITConstant() = default;
108110
JITConstant(const Parameter &Parameter, void *Ptr, size_t Size)
109-
: Param{Parameter}, Value{reinterpret_cast<const char *>(Ptr), Size} {}
111+
: Param{Parameter}, Value{Size} {
112+
auto *CPtr = reinterpret_cast<const char *>(Ptr);
113+
std::copy(CPtr, CPtr + Size, Value.begin());
114+
}
110115

111116
friend bool operator==(const JITConstant &LHS,
112117
const JITConstant &RHS) noexcept {

sycl-fusion/jit-compiler/lib/fusion/FusionHelper.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ static Metadata *getConstantIntMD(llvm::LLVMContext &LLVMContext, T Val) {
2222
}
2323

2424
static Metadata *getConstantMD(llvm::LLVMContext &LLVMCtx,
25-
llvm::StringRef Data) {
26-
return MDString::get(LLVMCtx, Data);
25+
const jit_compiler::DynArray<char> &Data) {
26+
return MDString::get(LLVMCtx, StringRef{Data.begin(), Data.size()});
2727
}
2828

2929
static Metadata *getMDParam(LLVMContext &LLVMCtx,

sycl-fusion/jit-compiler/lib/fusion/Hashing.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ inline llvm::hash_code hash_value(const NDRange &ND) {
4242
return llvm::hash_combine(ND.getDimensions(), ND.getGlobalSize(),
4343
ND.getLocalSize(), ND.getOffset());
4444
}
45+
46+
template <typename T> inline llvm::hash_code hash_value(const DynArray<T> &DA) {
47+
return llvm::hash_combine_range(DA.begin(), DA.end());
48+
}
4549
} // namespace jit_compiler
4650

4751
namespace std {

0 commit comments

Comments
 (0)