Skip to content

Commit

Permalink
Merge branch 'sycl' into pietro/barriers
Browse files Browse the repository at this point in the history
  • Loading branch information
PietroGhg committed Jan 24, 2024
2 parents 1065747 + 2414a15 commit 4917157
Show file tree
Hide file tree
Showing 7 changed files with 97 additions and 79 deletions.
18 changes: 9 additions & 9 deletions devops/dependencies.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
{
"linux": {
"compute_runtime": {
"github_tag": "23.30.26918.9",
"version": "23.30.26918.9",
"url": "https://github.com/intel/compute-runtime/releases/tag/23.30.26918.9",
"github_tag": "23.43.27642.18",
"version": "23.43.27642.18",
"url": "https://github.com/intel/compute-runtime/releases/tag/23.43.27642.18",
"root": "{DEPS_ROOT}/opencl/runtime/linux/oclgpu"
},
"igc": {
"github_tag": "igc-1.0.14828.8",
"version": "1.0.14828.8",
"url": "https://github.com/intel/intel-graphics-compiler/releases/tag/igc-1.0.14828.8",
"github_tag": "igc-1.0.15468.11",
"version": "1.0.15468.11",
"url": "https://github.com/intel/intel-graphics-compiler/releases/tag/igc-1.0.15468.11",
"root": "{DEPS_ROOT}/opencl/runtime/linux/oclgpu"
},
"cm": {
Expand All @@ -19,9 +19,9 @@
"root": "{DEPS_ROOT}/opencl/runtime/linux/oclgpu"
},
"level_zero": {
"github_tag": "v1.14.0",
"version": "v1.14.0",
"url": "https://github.com/oneapi-src/level-zero/releases/tag/v1.14.0",
"github_tag": "v1.15.8",
"version": "v1.15.8",
"url": "https://github.com/oneapi-src/level-zero/releases/tag/v1.15.8",
"root": "{DEPS_ROOT}/opencl/runtime/linux/oclgpu"
},
"tbb": {
Expand Down
27 changes: 20 additions & 7 deletions sycl-fusion/jit-compiler/include/KernelFusion.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,26 @@ class FusionResult {
class KernelFusion {

public:
static FusionResult fuseKernels(
Config &&JITConfig, const std::vector<SYCLKernelInfo> &KernelInformation,
const char *FusedKernelName, jit_compiler::ParamIdentList &Identities,
BarrierFlags BarriersFlags,
const std::vector<jit_compiler::ParameterInternalization>
&Internalization,
const std::vector<jit_compiler::JITConstant> &JITConstants);
static FusionResult
fuseKernels(const std::vector<SYCLKernelInfo> &KernelInformation,
const char *FusedKernelName,
jit_compiler::ParamIdentList &Identities,
BarrierFlags BarriersFlags,
const std::vector<jit_compiler::ParameterInternalization>
&Internalization,
const std::vector<jit_compiler::JITConstant> &JITConstants);

/// Clear all previously set options.
static void resetConfiguration();

/// Set \p Opt to the value built in-place by \p As.
template <typename Opt, typename... Args> static void set(Args &&...As) {
set(new Opt{std::forward<Args>(As)...});
}

private:
/// Take ownership of \p Option and include it in the current configuration.
static void set(OptionPtrBase *Option);
};

} // namespace jit_compiler
Expand Down
70 changes: 18 additions & 52 deletions sycl-fusion/jit-compiler/include/Options.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,77 +11,43 @@

#include "Kernel.h"

#include <memory>
#include <unordered_map>

namespace jit_compiler {

enum OptionID { VerboseOutput, EnableCaching, TargetDeviceInfo };

class OptionPtrBase {};

class Config {
class OptionPtrBase {
protected:
explicit OptionPtrBase(OptionID Id) : Id(Id) {}

public:
template <typename Opt> void set(typename Opt::ValueType Value) {
Opt::set(*this, Value);
}

template <typename Opt> typename Opt::ValueType get() {
return Opt::get(*this);
}

private:
std::unordered_map<OptionID, std::unique_ptr<OptionPtrBase>> OptionValues;

void set(OptionID ID, std::unique_ptr<OptionPtrBase> Value) {
OptionValues[ID] = std::move(Value);
}

OptionPtrBase *get(OptionID ID) {
if (OptionValues.count(ID)) {
return OptionValues.at(ID).get();
}
return nullptr;
}

template <OptionID ID, typename T> friend class OptionBase;
const OptionID Id;
};

template <OptionID ID, typename T> class OptionBase : public OptionPtrBase {
public:
template <OptionID ID, typename T> struct OptionBase : public OptionPtrBase {
static constexpr OptionID Id = ID;
using ValueType = T;

protected:
static void set(Config &Cfg, T Value) {
Cfg.set(ID,
std::unique_ptr<OptionBase<ID, T>>{new OptionBase<ID, T>{Value}});
}

static const T get(Config &Cfg) {
auto *ConfigValue = Cfg.get(ID);
if (!ConfigValue) {
return T{};
}
return static_cast<OptionBase<ID, T> *>(ConfigValue)->Value;
}
template <typename... Args>
explicit OptionBase(Args &&...As)
: OptionPtrBase{ID}, Value{std::forward<Args>(As)...} {}

private:
T Value;

OptionBase(T Val) : Value{Val} {}

friend Config;
};

namespace option {

struct JITEnableVerbose : public OptionBase<OptionID::VerboseOutput, bool> {};
struct JITEnableVerbose : public OptionBase<OptionID::VerboseOutput, bool> {
using OptionBase::OptionBase;
};

struct JITEnableCaching : public OptionBase<OptionID::EnableCaching, bool> {};
struct JITEnableCaching : public OptionBase<OptionID::EnableCaching, bool> {
using OptionBase::OptionBase;
};

struct JITTargetInfo
: public OptionBase<OptionID::TargetDeviceInfo, TargetInfo> {};
: public OptionBase<OptionID::TargetDeviceInfo, TargetInfo> {
using OptionBase::OptionBase;
};

} // namespace option
} // namespace jit_compiler
Expand Down
11 changes: 7 additions & 4 deletions sycl-fusion/jit-compiler/lib/KernelFusion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,11 @@ static bool isTargetFormatSupported(BinaryFormat TargetFormat) {
}

FusionResult KernelFusion::fuseKernels(
Config &&JITConfig, const std::vector<SYCLKernelInfo> &KernelInformation,
const std::vector<SYCLKernelInfo> &KernelInformation,
const char *FusedKernelName, ParamIdentList &Identities,
BarrierFlags BarriersFlags,
const std::vector<jit_compiler::ParameterInternalization> &Internalization,
const std::vector<jit_compiler::JITConstant> &Constants) {
// Initialize the configuration helper to make the options for this invocation
// available (on a per-thread basis).
ConfigHelper::setConfig(std::move(JITConfig));

std::vector<std::string> KernelsToFuse;
llvm::transform(KernelInformation, std::back_inserter(KernelsToFuse),
Expand Down Expand Up @@ -194,3 +191,9 @@ FusionResult KernelFusion::fuseKernels(

return FusionResult{FusedKernelInfo};
}

void KernelFusion::resetConfiguration() { ConfigHelper::reset(); }

void KernelFusion::set(OptionPtrBase *Option) {
ConfigHelper::getConfig().set(Option);
}
35 changes: 34 additions & 1 deletion sycl-fusion/jit-compiler/lib/helper/ConfigHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,44 @@

#include "Options.h"

#include <memory>
#include <unordered_map>

namespace jit_compiler {

class Config {

public:
template <typename Opt> typename Opt::ValueType get() const {
using T = typename Opt::ValueType;

auto *ConfigValue = get(Opt::Id);
if (!ConfigValue) {
return T{};
}
return static_cast<const OptionBase<Opt::Id, T> *>(ConfigValue)->Value;
}

void set(OptionPtrBase *Option) {
OptionValues[Option->Id] = std::unique_ptr<OptionPtrBase>(Option);
}

private:
std::unordered_map<OptionID, std::unique_ptr<OptionPtrBase>> OptionValues;

const OptionPtrBase *get(OptionID ID) const {
const auto Iter = OptionValues.find(ID);
if (Iter == OptionValues.end()) {
return nullptr;
}
return Iter->second.get();
}
};

class ConfigHelper {
public:
static void setConfig(Config &&JITConfig) { Cfg = std::move(JITConfig); }
static void reset() { Cfg = {}; }
static Config &getConfig() { return Cfg; }

template <typename Opt> static typename Opt::ValueType get() {
return Cfg.get<Opt>();
Expand Down
14 changes: 8 additions & 6 deletions sycl/source/detail/jit_compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -823,20 +823,22 @@ jit_compiler::fuseKernels(QueueImplPtr Queue,

static size_t FusedKernelNameIndex = 0;
auto FusedKernelName = "fused_" + std::to_string(FusedKernelNameIndex++);
::jit_compiler::Config JITConfig;
::jit_compiler::KernelFusion::resetConfiguration();
bool DebugEnabled =
detail::SYCLConfig<detail::SYCL_RT_WARNING_LEVEL>::get() > 0;
JITConfig.set<::jit_compiler::option::JITEnableVerbose>(DebugEnabled);
JITConfig.set<::jit_compiler::option::JITEnableCaching>(
::jit_compiler::KernelFusion::set<::jit_compiler::option::JITEnableVerbose>(
DebugEnabled);
::jit_compiler::KernelFusion::set<::jit_compiler::option::JITEnableCaching>(
detail::SYCLConfig<detail::SYCL_ENABLE_FUSION_CACHING>::get());

::jit_compiler::TargetInfo TargetInfo = getTargetInfo(Queue);
::jit_compiler::BinaryFormat TargetFormat = TargetInfo.getFormat();
JITConfig.set<::jit_compiler::option::JITTargetInfo>(TargetInfo);
::jit_compiler::KernelFusion::set<::jit_compiler::option::JITTargetInfo>(
std::move(TargetInfo));

auto FusionResult = ::jit_compiler::KernelFusion::fuseKernels(
std::move(JITConfig), InputKernelInfo, FusedKernelName.c_str(),
ParamIdentities, BarrierFlags, InternalizeParams, JITConstants);
InputKernelInfo, FusedKernelName.c_str(), ParamIdentities, BarrierFlags,
InternalizeParams, JITConstants);

if (FusionResult.failed()) {
if (DebugEnabled) {
Expand Down
1 change: 1 addition & 0 deletions sycl/test-e2e/ESIMD/matrix_transpose_glb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
// UNSUPPORTED: *
// Use -O2 to avoid huge stack usage under -O0.
// RUN: %{build} -O2 -o %t.out
// RUN: %{run} %t.out
Expand Down

0 comments on commit 4917157

Please sign in to comment.