Skip to content

[SYCL][NFC] Format program_manager.cpp #1788

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 1 commit into from
Jun 7, 2020
Merged
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
52 changes: 27 additions & 25 deletions sycl/source/detail/program_manager/program_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,15 @@ static RT::PiProgram createBinaryProgram(const ContextImplPtr Context,
if (Backend == backend::cuda) {
// TODO: Reemplace CreateWithSource with CreateWithBinary in CUDA backend
const char *SignedData = reinterpret_cast<const char *>(Data);
Plugin.call<PiApiKind::piclProgramCreateWithSource>(Context->getHandleRef(), 1 /*one binary*/, &SignedData,
&DataLen, &Program);
Plugin.call<PiApiKind::piclProgramCreateWithSource>(
Context->getHandleRef(), 1 /*one binary*/, &SignedData, &DataLen,
&Program);
} else {
RT::PiDevice Device = getFirstDevice(Context);
pi_int32 BinaryStatus = CL_SUCCESS;
Plugin.call<PiApiKind::piclProgramCreateWithBinary>(Context->getHandleRef(), 1 /*one binary*/, &Device,
&DataLen, &Data, &BinaryStatus,
&Program);
Plugin.call<PiApiKind::piclProgramCreateWithBinary>(
Context->getHandleRef(), 1 /*one binary*/, &Device, &DataLen, &Data,
&BinaryStatus, &Program);
}

return Program;
Expand Down Expand Up @@ -189,7 +190,7 @@ RetT *getOrBuild(KernelProgramCache &KPCache, KeyT &&CacheKey,
RetT *Result = waitUntilBuilt<ExceptionT>(KPCache, BuildResult);

if (Result)
return Result;
return Result;

// Previous build is failed. There was no SYCL exception though.
// We might try to build once more.
Expand Down Expand Up @@ -360,7 +361,7 @@ RT::PiProgram ProgramManager::getBuiltPIProgram(OSModuleHandle M,
auto AcquireF = [](KernelProgramCache &Cache) {
return Cache.acquireCachedPrograms();
};
auto GetF = [](const Locked<ProgramCacheT> &LockedCache) -> ProgramCacheT& {
auto GetF = [](const Locked<ProgramCacheT> &LockedCache) -> ProgramCacheT & {
return LockedCache.get();
};
auto BuildF = [this, &M, &KSId, &Context, Prg] {
Expand All @@ -381,9 +382,10 @@ RT::PiProgram ProgramManager::getBuiltPIProgram(OSModuleHandle M,

const std::vector<device> &Devices = ContextImpl->getDevices();
std::vector<RT::PiDevice> PiDevices(Devices.size());
std::transform(
Devices.begin(), Devices.end(), PiDevices.begin(),
[](const device Dev) { return getRawSyclObjImpl(Dev)->getHandleRef(); });
std::transform(Devices.begin(), Devices.end(), PiDevices.begin(),
[](const device Dev) {
return getRawSyclObjImpl(Dev)->getHandleRef();
});

ProgramPtr BuiltProgram =
build(std::move(ProgramManaged), ContextImpl, Img.getCompileOptions(),
Expand Down Expand Up @@ -420,10 +422,11 @@ RT::PiKernel ProgramManager::getOrCreateKernel(OSModuleHandle M,

KernelProgramCache &Cache = Ctx->getKernelProgramCache();

auto AcquireF = [] (KernelProgramCache &Cache) {
auto AcquireF = [](KernelProgramCache &Cache) {
return Cache.acquireKernelsPerProgramCache();
};
auto GetF = [&Program] (const Locked<KernelCacheT> &LockedCache) -> KernelByNameT& {
auto GetF =
[&Program](const Locked<KernelCacheT> &LockedCache) -> KernelByNameT & {
return LockedCache.get()[Program];
};
auto BuildF = [this, &Program, &KernelName, &Ctx] {
Expand All @@ -438,8 +441,8 @@ RT::PiKernel ProgramManager::getOrCreateKernel(OSModuleHandle M,
return Result;
};

return getOrBuild<PiKernelT, invalid_object_error>(
Cache, KernelName, AcquireF, GetF, BuildF);
return getOrBuild<PiKernelT, invalid_object_error>(Cache, KernelName,
AcquireF, GetF, BuildF);
}

RT::PiProgram
Expand Down Expand Up @@ -506,7 +509,7 @@ static bool loadDeviceLib(const ContextImplPtr Context, const char *Name,
return Prog != nullptr;
}

static const char* getDeviceLibFilename(DeviceLibExt Extension) {
static const char *getDeviceLibFilename(DeviceLibExt Extension) {
switch (Extension) {
case cl_intel_devicelib_assert:
return "libsycl-fallback-cassert.spv";
Expand All @@ -523,7 +526,7 @@ static const char* getDeviceLibFilename(DeviceLibExt Extension) {
PI_INVALID_OPERATION);
}

static const char* getDeviceLibExtensionStr(DeviceLibExt Extension) {
static const char *getDeviceLibExtensionStr(DeviceLibExt Extension) {
switch (Extension) {
case cl_intel_devicelib_assert:
return "cl_intel_devicelib_assert";
Expand Down Expand Up @@ -673,18 +676,17 @@ getDeviceLibPrograms(const ContextImplPtr Context,
{cl_intel_devicelib_math, false},
{cl_intel_devicelib_math_fp64, false},
{cl_intel_devicelib_complex, false},
{cl_intel_devicelib_complex_fp64, false}
};
{cl_intel_devicelib_complex_fp64, false}};

// Disable all devicelib extensions requiring fp64 support if at least
// one underlying device doesn't support cl_khr_fp64.
bool fp64Support = true;
for (RT::PiDevice Dev : Devices) {
std::string DevExtList =
get_device_info<std::string, info::device::extensions>::get(
get_device_info<std::string, info::device::extensions>::get(
Dev, Context->getPlugin());
fp64Support = fp64Support &&
(DevExtList.npos != DevExtList.find("cl_khr_fp64"));
fp64Support =
fp64Support && (DevExtList.npos != DevExtList.find("cl_khr_fp64"));
}

// Load a fallback library for an extension if at least one device does not
Expand All @@ -702,11 +704,12 @@ getDeviceLibPrograms(const ContextImplPtr Context,
}

if ((Ext == cl_intel_devicelib_math_fp64 ||
Ext == cl_intel_devicelib_complex_fp64) && !fp64Support) {
Ext == cl_intel_devicelib_complex_fp64) &&
!fp64Support) {
continue;
}

const char* ExtStr = getDeviceLibExtensionStr(Ext);
const char *ExtStr = getDeviceLibExtensionStr(Ext);

bool InhibitNativeImpl = false;
if (const char *Env = getenv("SYCL_DEVICELIB_INHIBIT_NATIVE")) {
Expand Down Expand Up @@ -823,8 +826,7 @@ void ProgramManager::addImages(pi_device_binaries DeviceBinary) {
KernelSetId KSId = getNextKernelSetId();
for (_pi_offload_entry EntriesIt = EntriesB; EntriesIt != EntriesE;
++EntriesIt) {
auto Result =
KSIdMap.insert(std::make_pair(EntriesIt->name, KSId));
auto Result = KSIdMap.insert(std::make_pair(EntriesIt->name, KSId));
(void)Result;
assert(Result.second && "Kernel sets are not disjoint");
}
Expand Down