Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
cd9818b
[SYCL][NFC] Call getCacheItemPath only if cache is enabled
bader Dec 28, 2021
04e3869
[SYCL][NFC] Don't include sycl.hpp from headers
bader Dec 28, 2021
ba29bbe
[SYCL][NFC] Factor out empty kernel creation boilerplate
bader Dec 28, 2021
f5b380b
[SYCL] Do not build device code for sub-devices.
bader Dec 23, 2021
5a3587e
Apply clang-format
bader Dec 28, 2021
28b7f80
Fix issues caught by pre-commit CI.
bader Dec 29, 2021
61e09bd
[NFC] Fix a few typos in the comments
bader Dec 29, 2021
d5b93f0
Merge remote-tracking branch 'intel/sycl' into optimize-build
bader Jan 20, 2022
a1e483a
Improved build results caching for GPU devices.
bader Jan 21, 2022
7ac48ae
Improve GPU caching.
bader Jan 24, 2022
d0f2861
Revert "Improve GPU caching."
bader Feb 8, 2022
231a1a3
Revert "Improved build results caching for GPU devices."
bader Feb 8, 2022
8f2d9c4
Merge remote-tracking branch 'intel/sycl' into optimize-build
bader Feb 8, 2022
d44e27f
Fix formatting.
bader Feb 8, 2022
6e310b0
Add device query for checking if device architecture is homogeneous
bader Feb 14, 2022
ce299cd
Merge remote-tracking branch 'intel/sycl' into optimize-build
bader Feb 14, 2022
e6ca4f9
Address code review feedback
bader Feb 15, 2022
bf57926
Added a FIXME comment.
bader Feb 17, 2022
d062d77
Merge remote-tracking branch 'intel/sycl' into optimize-build
bader Feb 17, 2022
0e650ea
Update sycl/source/detail/program_manager/program_manager.cpp
bader Feb 17, 2022
d1cc7aa
Move comment to Level Zero plug-in.
bader Feb 18, 2022
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
3 changes: 1 addition & 2 deletions sycl/plugins/level_zero/pi_level_zero.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2124,8 +2124,7 @@ pi_result piDeviceGetInfo(pi_device Device, pi_device_info ParamName,
}
}
case PI_DEVICE_INFO_PARENT_DEVICE:
// TODO: all Level Zero devices are parent ?
return ReturnValue(pi_device{0});
return ReturnValue(Device->RootDevice);
case PI_DEVICE_INFO_PLATFORM:
return ReturnValue(Device->Platform);
case PI_DEVICE_INFO_VENDOR_ID:
Expand Down
4 changes: 1 addition & 3 deletions sycl/source/detail/device_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,11 @@ device_impl::device_impl(pi_native_handle InteropDeviceHandle,
Plugin.call<PiApiKind::piDeviceGetInfo>(
MDevice, PI_DEVICE_INFO_TYPE, sizeof(RT::PiDeviceType), &MType, nullptr);

RT::PiDevice parent = nullptr;
// TODO catch an exception and put it to list of asynchronous exceptions
Plugin.call<PiApiKind::piDeviceGetInfo>(MDevice, PI_DEVICE_INFO_PARENT_DEVICE,
sizeof(RT::PiDevice), &parent,
sizeof(RT::PiDevice), &MRootDevice,
nullptr);

MIsRootDevice = (nullptr == parent);
if (!InteroperabilityConstructor) {
// TODO catch an exception and put it to list of asynchronous exceptions
// Interoperability Constructor already calls DeviceRetain in
Expand Down
4 changes: 3 additions & 1 deletion sycl/source/detail/device_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -225,12 +225,14 @@ class device_impl {

bool isAssertFailSupported() const;

bool isRootDevice() const { return MRootDevice == nullptr; }

private:
explicit device_impl(pi_native_handle InteropDevice, RT::PiDevice Device,
PlatformImplPtr Platform, const plugin &Plugin);
RT::PiDevice MDevice = 0;
RT::PiDeviceType MType;
bool MIsRootDevice = false;
RT::PiDevice MRootDevice = nullptr;
bool MIsHostDevice;
PlatformImplPtr MPlatform;
bool MIsAssertFailSupported = false;
Expand Down
10 changes: 8 additions & 2 deletions sycl/source/detail/persistent_device_code_cache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,13 @@ void PersistentDeviceCodeCache::putItemToDisc(
const SerializedObj &SpecConsts, const std::string &BuildOptionsString,
const RT::PiProgram &NativePrg) {

if (!isImageCached(Img))
return;

std::string DirName =
getCacheItemPath(Device, Img, SpecConsts, BuildOptionsString);
Comment thread
vladimirlaz marked this conversation as resolved.

if (!isImageCached(Img) || DirName.empty())
if (DirName.empty())
return;

auto Plugin = detail::getSyclObjImpl(Device)->getPlugin();
Expand Down Expand Up @@ -137,10 +140,13 @@ std::vector<std::vector<char>> PersistentDeviceCodeCache::getItemFromDisc(
const device &Device, const RTDeviceBinaryImage &Img,
const SerializedObj &SpecConsts, const std::string &BuildOptionsString) {

if (!isImageCached(Img))
return {};

std::string Path =
getCacheItemPath(Device, Img, SpecConsts, BuildOptionsString);

if (!isImageCached(Img) || Path.empty() || !OSUtil::isPathPresent(Path))
if (Path.empty() || !OSUtil::isPathPresent(Path))
return {};

int i = 0;
Expand Down
30 changes: 23 additions & 7 deletions sycl/source/detail/program_manager/program_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -470,10 +470,16 @@ RT::PiProgram ProgramManager::getBuiltPIProgram(
if (Prg)
Prg->stableSerializeSpecConstRegistry(SpecConsts);

auto BuildF = [this, &M, &KSId, &ContextImpl, &DeviceImpl, Prg, &CompileOpts,
// Use root device image to avoid building for the same architecture.
DeviceImplPtr RootDev = DeviceImpl;
while (!RootDev->isRootDevice())
RootDev = detail::getSyclObjImpl(
RootDev->get_info<info::device::parent_device>());

auto BuildF = [this, &M, &KSId, &ContextImpl, &RootDev, Prg, &CompileOpts,
&LinkOpts, &JITCompilationIsRequired, SpecConsts] {
auto Context = createSyclObjFromImpl<context>(ContextImpl);
auto Device = createSyclObjFromImpl<device>(DeviceImpl);
auto Device = createSyclObjFromImpl<device>(RootDev);

const RTDeviceBinaryImage &Img =
getDeviceImage(M, KSId, Context, Device, JITCompilationIsRequired);
Expand Down Expand Up @@ -523,7 +529,7 @@ RT::PiProgram ProgramManager::getBuiltPIProgram(
return BuiltProgram.release();
};

const RT::PiDevice PiDevice = DeviceImpl->getHandleRef();
const RT::PiDevice PiDevice = RootDev->getHandleRef();

auto BuildResult = getOrBuild<PiProgramT, compile_program_error>(
Cache,
Expand Down Expand Up @@ -560,16 +566,21 @@ ProgramManager::getOrCreateKernel(OSModuleHandle M,
Prg->stableSerializeSpecConstRegistry(SpecConsts);
}
applyOptionsFromEnvironment(CompileOpts, LinkOpts);
const RT::PiDevice PiDevice = DeviceImpl->getHandleRef();

// Use root device image to avoid building for the same architecture.
DeviceImplPtr D = DeviceImpl;
while (!D->isRootDevice())
D = detail::getSyclObjImpl(D->get_info<info::device::parent_device>());

const RT::PiDevice PiDevice = D->getHandleRef();

auto key = std::make_tuple(std::move(SpecConsts), M, PiDevice,
CompileOpts + LinkOpts, KernelName);
auto ret_tuple = Cache.tryToGetKernelFast(key);
if (std::get<0>(ret_tuple))
return ret_tuple;

RT::PiProgram Program =
getBuiltPIProgram(M, ContextImpl, DeviceImpl, KernelName, Prg);
RT::PiProgram Program = getBuiltPIProgram(M, ContextImpl, D, KernelName, Prg);

auto AcquireF = [](KernelProgramCache &Cache) {
return Cache.acquireKernelsPerProgramCache();
Expand Down Expand Up @@ -830,8 +841,13 @@ ProgramManager::getDeviceImage(OSModuleHandle M, KernelSetId KSId,
for (unsigned I = 0; I < Imgs.size(); I++)
RawImgs[I] = const_cast<pi_device_binary>(&Imgs[I]->getRawData());

// Use root device image to avoid building for the same architecture.
device RootDevice = Device;
while (!getSyclObjImpl(RootDevice)->isRootDevice())
RootDevice = Device.get_info<info::device::parent_device>();

Ctx->getPlugin().call<PiApiKind::piextDeviceSelectBinary>(
getSyclObjImpl(Device)->getHandleRef(), RawImgs.data(),
getSyclObjImpl(RootDevice)->getHandleRef(), RawImgs.data(),
(cl_uint)RawImgs.size(), &ImgInd);

if (JITCompilationIsRequired) {
Expand Down
6 changes: 3 additions & 3 deletions sycl/source/detail/program_manager/program_manager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@ class ProgramManager {
SerializedObj SpecConsts);
/// Builds or retrieves from cache a program defining the kernel with given
/// name.
/// \param M idenfies the OS module the kernel comes from (multiple OS modules
/// may have kernels with the same name)
/// \param M identifies the OS module the kernel comes from (multiple OS
/// modules may have kernels with the same name)
/// \param Context the context to build the program with
/// \param Device the device for which the program is built
/// \param KernelName the kernel's name
Expand Down Expand Up @@ -152,7 +152,7 @@ class ProgramManager {
/// \param NativePrg the native program, target for spec constant setting; if
/// not null then overrides the native program in Prg
/// \param Img A source of the information about which constants need
/// setting and symboling->integer spec constnant ID mapping. If not
/// setting and symboling->integer spec constant ID mapping. If not
/// null, overrides native program->binary image binding maintained by
/// the program manager.
void flushSpecConstants(const program_impl &Prg,
Expand Down
1 change: 0 additions & 1 deletion sycl/unittests/helpers/CommonRedefinitions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
//
//===----------------------------------------------------------------------===//

#include <CL/sycl.hpp>
#include <helpers/PiImage.hpp>
#include <helpers/PiMock.hpp>

Expand Down
1 change: 0 additions & 1 deletion sycl/unittests/helpers/PiImage.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

#pragma once

#include <CL/sycl.hpp>
#include <CL/sycl/detail/common.hpp>
#include <CL/sycl/detail/pi.hpp>
#include <detail/platform_impl.hpp>
Expand Down
4 changes: 3 additions & 1 deletion sycl/unittests/helpers/PiMock.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@

#pragma once

#include <CL/sycl.hpp>
#include <CL/sycl/detail/common.hpp>
#include <CL/sycl/detail/pi.hpp>
#include <CL/sycl/device_selector.hpp>
#include <CL/sycl/platform.hpp>
#include <CL/sycl/queue.hpp>
#include <detail/platform_impl.hpp>

#include <functional>
Expand Down
55 changes: 55 additions & 0 deletions sycl/unittests/helpers/TestKernel.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
//===----------------------------------------------------------------------===//
//
// 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
//
//===----------------------------------------------------------------------===//

#pragma once

#include "PiImage.hpp"

class TestKernel;

__SYCL_INLINE_NAMESPACE(cl) {
namespace sycl {
namespace detail {
template <> struct KernelInfo<TestKernel> {
static constexpr unsigned getNumParams() { return 0; }
static const kernel_param_desc_t &getParamDesc(int) {
static kernel_param_desc_t Dummy;
return Dummy;
}
static constexpr const char *getName() { return "TestKernel"; }
static constexpr bool isESIMD() { return false; }
static constexpr bool callsThisItem() { return false; }
static constexpr bool callsAnyThisFreeFunction() { return false; }
};

} // namespace detail
} // namespace sycl
} // __SYCL_INLINE_NAMESPACE(cl)

static sycl::unittest::PiImage generateDefaultImage() {
using namespace sycl::unittest;

PiPropertySet PropSet;

std::vector<unsigned char> Bin{0, 1, 2, 3, 4, 5}; // Random data

PiArray<PiOffloadEntry> Entries = makeEmptyKernels({"TestKernel"});

PiImage Img{PI_DEVICE_BINARY_TYPE_SPIRV, // Format
__SYCL_PI_DEVICE_BINARY_TARGET_SPIRV64, // DeviceTargetSpec
"", // Compile options
"", // Link options
std::move(Bin),
std::move(Entries),
std::move(PropSet)};

return Img;
}

static sycl::unittest::PiImage Img = generateDefaultImage();
static sycl::unittest::PiImageArray<1> ImgArray{&Img};
1 change: 1 addition & 0 deletions sycl/unittests/kernel-and-program/Cache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ static pi_result redefinedKernelCreate(pi_program program,
pi_kernel *ret_kernel) {
return PI_SUCCESS;
}

static pi_result redefinedKernelRelease(pi_kernel kernel) { return PI_SUCCESS; }

class KernelAndProgramCacheTest : public ::testing::Test {
Expand Down
4 changes: 3 additions & 1 deletion sycl/unittests/pi/PiMock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
//
//===----------------------------------------------------------------------===//

#include <gtest/gtest.h>
#include <helpers/PiMock.hpp>

#include <detail/queue_impl.hpp>

#include <gtest/gtest.h>

using namespace cl::sycl;

pi_result piProgramBuildRedefine(pi_program, pi_uint32, const pi_device *,
Expand Down
3 changes: 2 additions & 1 deletion sycl/unittests/pi/TestGetPlatforms.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@

#pragma once

#include <CL/sycl.hpp>
#include <CL/sycl/platform.hpp>

#include <algorithm>
#include <functional>
#include <vector>
Expand Down
1 change: 1 addition & 0 deletions sycl/unittests/program_manager/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ set(CMAKE_CXX_EXTENSIONS OFF)
add_sycl_unittest(ProgramManagerTests OBJECT
EliminatedArgMask.cpp
itt_annotations.cpp
SubDevices.cpp
)

Loading