Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
544f175
[SYCL] Rename sycl-fusion to sycl-jit
jchlanda Jul 25, 2024
7ae1d18
SYCLKernelJit -> SYCLKernelJIT
jchlanda Jul 25, 2024
14a9bc8
LLVM_EXTERNAL_SYCL_FUSION_SOURCE_DIR -> LLVM_EXTERNAL_SYCL_JIT_SOURCE…
jchlanda Jul 25, 2024
b0ac4af
SYCL_FUSION_WARNING_FLAGS -> SYCL_JIT_WARNING_FLAGS
jchlanda Jul 25, 2024
279d4e5
Merge remote-tracking branch 'upstream/sycl' into jakub/fusion_rename
jchlanda Jul 25, 2024
2bcd59c
Merge remote-tracking branch 'upstream/sycl' into jakub/fusion_rename
jchlanda Jul 26, 2024
5c86873
Mention JIT in getting started (alongside fusion)
jchlanda Jul 29, 2024
8b8930c
Merge remote-tracking branch 'upstream/sycl' into jakub/fusion_rename
jchlanda Jul 29, 2024
4fcc7f1
Merge remote-tracking branch 'upstream/sycl' into jakub/fusion_rename
jchlanda Jul 30, 2024
dcc58c6
Merge remote-tracking branch 'upstream/sycl' into jakub/fusion_rename
jchlanda Jul 31, 2024
e05856a
Merge remote-tracking branch 'upstream/sycl' into jakub/fusion_rename
jchlanda Jul 31, 2024
e3122f8
Doc build fix
jchlanda Jul 31, 2024
665b028
Use correct ifndef identifier in jit
jchlanda Jul 31, 2024
b7d4e03
[SYCL-JIT] Store env variables in configuration
jchlanda Jul 31, 2024
0ee95fe
Merge remote-tracking branch 'upstream/sycl' into jakub/jit_config_en…
jchlanda Aug 12, 2024
aa49240
Merge fix
jchlanda Aug 12, 2024
86f9219
std::string to DynArray<char>
jchlanda Aug 13, 2024
234b29e
DynArray fixes
jchlanda Aug 13, 2024
d75c255
Merge remote-tracking branch 'upstream/sycl' into jakub/jit_config_en…
jchlanda Aug 20, 2024
9a11446
PR feedback -dyn array constructor
jchlanda Aug 20, 2024
acbd19b
DynArray constructor tweak
jchlanda Aug 21, 2024
ad8802c
Merge remote-tracking branch 'upstream/sycl' into jakub/jit_config_en…
jchlanda Aug 21, 2024
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
6 changes: 6 additions & 0 deletions sycl-jit/common/include/DynArray.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#define SYCL_FUSION_COMMON_DYNARRAY_H

#include <algorithm>
#include <cstring>

namespace jit_compiler {

Expand All @@ -22,6 +23,11 @@ template <typename T> class DynArray {

explicit DynArray(size_t Size) { init(Size); }

template <typename InputIt> DynArray(InputIt Begin, InputIt End) {
init(End - Begin);
std::copy(Begin, End, this->begin());
}

~DynArray() { deinit(); }

DynArray(const DynArray &Other) {
Expand Down
4 changes: 1 addition & 3 deletions sycl-jit/jit-compiler/include/KernelFusion.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,7 @@ JITResult fuseKernels(View<SYCLKernelInfo> KernelInformation,

JITResult materializeSpecConstants(const char *KernelName,
jit_compiler::SYCLKernelBinaryInfo &BinInfo,
View<unsigned char> SpecConstBlob,
const char *TargetCPU,
const char *TargetFeatures);
View<unsigned char> SpecConstBlob);

/// Clear all previously set options.
void resetJITConfiguration();
Expand Down
19 changes: 18 additions & 1 deletion sycl-jit/jit-compiler/include/Options.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,13 @@

namespace jit_compiler {

enum OptionID { VerboseOutput, EnableCaching, TargetDeviceInfo };
enum OptionID {
VerboseOutput,
EnableCaching,
TargetDeviceInfo,
TargetCPU,
TargetFeatures
};

class OptionPtrBase {
protected:
Expand Down Expand Up @@ -90,6 +96,17 @@ struct JITTargetInfo
using OptionBase::OptionBase;
};

struct JITTargetCPU
: public OptionBase<JITTargetCPU, OptionID::TargetCPU, DynArray<char>> {
using OptionBase::OptionBase;
};

struct JITTargetFeatures
: public OptionBase<JITTargetFeatures, OptionID::TargetFeatures,
DynArray<char>> {
using OptionBase::OptionBase;
};

} // namespace option
} // namespace jit_compiler

Expand Down
6 changes: 2 additions & 4 deletions sycl-jit/jit-compiler/lib/KernelFusion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,7 @@ static bool isTargetFormatSupported(BinaryFormat TargetFormat) {
extern "C" JITResult
materializeSpecConstants(const char *KernelName,
jit_compiler::SYCLKernelBinaryInfo &BinInfo,
View<unsigned char> SpecConstBlob,
const char *TargetCPU, const char *TargetFeatures) {
View<unsigned char> SpecConstBlob) {
auto &JITCtx = JITContext::getInstance();

TargetInfo TargetInfo = ConfigHelper::get<option::JITTargetInfo>();
Expand Down Expand Up @@ -107,8 +106,7 @@ materializeSpecConstants(const char *KernelName,

SYCLKernelInfo &MaterializerKernelInfo = *ModuleInfo.getKernelFor(KernelName);
if (auto Error = translation::KernelTranslator::translateKernel(
MaterializerKernelInfo, *NewMod, JITCtx, TargetFormat, TargetCPU,
TargetFeatures)) {
MaterializerKernelInfo, *NewMod, JITCtx, TargetFormat)) {
return errorToFusionResult(std::move(Error),
"Translation to output format failed");
}
Expand Down
40 changes: 21 additions & 19 deletions sycl-jit/jit-compiler/lib/translation/KernelTranslation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
//===----------------------------------------------------------------------===//

#include "KernelTranslation.h"
#include "helper/ConfigHelper.h"

#include "SPIRVLLVMTranslation.h"
#include "llvm/Bitcode/BitcodeReader.h"
Expand Down Expand Up @@ -168,11 +169,10 @@ KernelTranslator::loadSPIRVKernel(llvm::LLVMContext &LLVMCtx,
return SPIRVLLVMTranslator::loadSPIRVKernel(LLVMCtx, Kernel);
}

llvm::Error
KernelTranslator::translateKernel(SYCLKernelInfo &Kernel, llvm::Module &Mod,
JITContext &JITCtx, BinaryFormat Format,
const std::string &TargetCPU,
const std::string &TargetFeatures) {
llvm::Error KernelTranslator::translateKernel(SYCLKernelInfo &Kernel,
llvm::Module &Mod,
JITContext &JITCtx,
BinaryFormat Format) {

KernelBinary *KernelBin = nullptr;
switch (Format) {
Expand All @@ -187,7 +187,7 @@ KernelTranslator::translateKernel(SYCLKernelInfo &Kernel, llvm::Module &Mod,
}
case BinaryFormat::PTX: {
llvm::Expected<KernelBinary *> BinaryOrError =
translateToPTX(Kernel, Mod, JITCtx, TargetCPU, TargetFeatures);
translateToPTX(Kernel, Mod, JITCtx);
if (auto Error = BinaryOrError.takeError()) {
return Error;
}
Expand All @@ -196,7 +196,7 @@ KernelTranslator::translateKernel(SYCLKernelInfo &Kernel, llvm::Module &Mod,
}
case BinaryFormat::AMDGCN: {
llvm::Expected<KernelBinary *> BinaryOrError =
translateToAMDGCN(Kernel, Mod, JITCtx, TargetCPU, TargetFeatures);
translateToAMDGCN(Kernel, Mod, JITCtx);
if (auto Error = BinaryOrError.takeError())
return Error;
KernelBin = *BinaryOrError;
Expand Down Expand Up @@ -227,10 +227,9 @@ KernelTranslator::translateToSPIRV(llvm::Module &Mod, JITContext &JITCtx) {
return SPIRVLLVMTranslator::translateLLVMtoSPIRV(Mod, JITCtx);
}

llvm::Expected<KernelBinary *> KernelTranslator::translateToPTX(
SYCLKernelInfo &KernelInfo, llvm::Module &Mod, JITContext &JITCtx,
[[maybe_unused]] const std::string &TargetCPU,
[[maybe_unused]] const std::string &TargetFeatures) {
llvm::Expected<KernelBinary *>
KernelTranslator::translateToPTX(SYCLKernelInfo &KernelInfo, llvm::Module &Mod,
JITContext &JITCtx) {
#ifndef JIT_SUPPORT_PTX
(void)KernelInfo;
(void)Mod;
Expand Down Expand Up @@ -261,8 +260,10 @@ llvm::Expected<KernelBinary *> KernelTranslator::translateToPTX(

// Give priority to user specified values (through environment variables:
// SYCL_JIT_AMDGCN_PTX_TARGET_CPU and SYCL_JIT_AMDGCN_PTX_TARGET_FEATURES).
llvm::StringRef CPU{TargetCPU};
llvm::StringRef Features{TargetFeatures};
auto CPUVal = ConfigHelper::get<option::JITTargetCPU>();
auto FeaturesVal = ConfigHelper::get<option::JITTargetFeatures>();
llvm::StringRef CPU = CPUVal.begin();
llvm::StringRef Features = FeaturesVal.begin();

auto *KernelFunc = Mod.getFunction(KernelInfo.Name.c_str());
// If they were not set, use default and consult the module for alternatives
Expand Down Expand Up @@ -309,10 +310,9 @@ llvm::Expected<KernelBinary *> KernelTranslator::translateToPTX(
#endif // JIT_SUPPORT_PTX
}

llvm::Expected<KernelBinary *> KernelTranslator::translateToAMDGCN(
SYCLKernelInfo &KernelInfo, llvm::Module &Mod, JITContext &JITCtx,
[[maybe_unused]] const std::string &TargetCPU,
[[maybe_unused]] const std::string &TargetFeatures) {
llvm::Expected<KernelBinary *>
KernelTranslator::translateToAMDGCN(SYCLKernelInfo &KernelInfo,
llvm::Module &Mod, JITContext &JITCtx) {
#ifndef JIT_SUPPORT_AMDGCN
(void)KernelInfo;
(void)Mod;
Expand Down Expand Up @@ -341,8 +341,10 @@ llvm::Expected<KernelBinary *> KernelTranslator::translateToAMDGCN(
"Failed to load and translate AMDGCN LLVM IR module with error %s",
ErrorMessage.c_str());

llvm::StringRef CPU{TargetCPU};
llvm::StringRef Features{TargetFeatures};
auto CPUVal = ConfigHelper::get<option::JITTargetCPU>();
auto FeaturesVal = ConfigHelper::get<option::JITTargetFeatures>();
llvm::StringRef CPU = CPUVal.begin();
llvm::StringRef Features = FeaturesVal.begin();

auto *KernelFunc = Mod.getFunction(KernelInfo.Name.c_str());
if (CPU.empty()) {
Expand Down
11 changes: 3 additions & 8 deletions sycl-jit/jit-compiler/lib/translation/KernelTranslation.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ class KernelTranslator {
loadKernels(llvm::LLVMContext &LLVMCtx, std::vector<SYCLKernelInfo> &Kernels);

static llvm::Error translateKernel(SYCLKernelInfo &Kernel, llvm::Module &Mod,
JITContext &JITCtx, BinaryFormat Format,
const std::string &TargetCPU = {},
const std::string &TargetFeatures = {});
JITContext &JITCtx, BinaryFormat Format);

private:
///
Expand All @@ -44,14 +42,11 @@ class KernelTranslator {
JITContext &JITCtx);

static llvm::Expected<KernelBinary *>
translateToPTX(SYCLKernelInfo &Kernel, llvm::Module &Mod, JITContext &JITCtx,
const std::string &TargetCPU = {},
const std::string &TargetFeatures = {});
translateToPTX(SYCLKernelInfo &Kernel, llvm::Module &Mod, JITContext &JITCtx);

static llvm::Expected<KernelBinary *>
translateToAMDGCN(SYCLKernelInfo &KernelInfo, llvm::Module &Mod,
JITContext &JITCtx, const std::string &TargetCPU = {},
const std::string &TargetFeatures = {});
JITContext &JITCtx);
};
} // namespace translation
} // namespace jit_compiler
Expand Down
19 changes: 12 additions & 7 deletions sycl/source/detail/jit_compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -663,15 +663,20 @@ ur_kernel_handle_t jit_compiler::materializeSpecConstants(
detail::SYCLConfig<detail::SYCL_RT_WARNING_LEVEL>::get() > 0;
AddToConfigHandle(
::jit_compiler::option::JITEnableVerbose::set(DebugEnabled));

std::string TargetCPU =
detail::SYCLConfig<detail::SYCL_JIT_AMDGCN_PTX_TARGET_CPU>::get();
std::string TargetFeatures =
detail::SYCLConfig<detail::SYCL_JIT_AMDGCN_PTX_TARGET_FEATURES>::get();
auto SetUpOption = [](const std::string &Value) {
::jit_compiler::JITEnvVar Option(Value.begin(), Value.end());
return Option;
};
::jit_compiler::JITEnvVar TargetCPUOpt = SetUpOption(
detail::SYCLConfig<detail::SYCL_JIT_AMDGCN_PTX_TARGET_CPU>::get());
AddToConfigHandle(::jit_compiler::option::JITTargetCPU::set(TargetCPUOpt));
::jit_compiler::JITEnvVar TargetFeaturesOpt = SetUpOption(
detail::SYCLConfig<detail::SYCL_JIT_AMDGCN_PTX_TARGET_FEATURES>::get());
AddToConfigHandle(
::jit_compiler::option::JITTargetFeatures::set(TargetFeaturesOpt));

auto MaterializerResult =
MaterializeSpecConstHandle(KernelName.c_str(), BinInfo, SpecConstBlob,
TargetCPU.c_str(), TargetFeatures.c_str());
MaterializeSpecConstHandle(KernelName.c_str(), BinInfo, SpecConstBlob);
if (MaterializerResult.failed()) {
std::string Message{"Compilation for kernel failed with message:\n"};
Message.append(MaterializerResult.getErrorMessage());
Expand Down
1 change: 1 addition & 0 deletions sycl/source/detail/jit_compiler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ struct SYCLKernelInfo;
struct SYCLKernelAttribute;
template <typename T> class DynArray;
using ArgUsageMask = DynArray<uint8_t>;
using JITEnvVar = DynArray<char>;
} // namespace jit_compiler

namespace sycl {
Expand Down