Skip to content

Commit e7cadeb

Browse files
[SYCL] Fix devicelib handling when linking multiple images (#15655)
Handle devicelib requirements of image dependecies, not just the main image.
1 parent a78cf31 commit e7cadeb

File tree

2 files changed

+33
-3
lines changed

2 files changed

+33
-3
lines changed

sycl/source/detail/program_manager/program_manager.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -816,16 +816,19 @@ ur_program_handle_t ProgramManager::getBuiltURProgram(
816816
// If device image is not SPIR-V, DeviceLibReqMask will be 0 which means
817817
// no fallback device library will be linked.
818818
uint32_t DeviceLibReqMask = 0;
819-
if (!DeviceCodeWasInCache &&
820-
Img.getFormat() == SYCL_DEVICE_BINARY_TYPE_SPIRV &&
821-
!SYCLConfig<SYCL_DEVICELIB_NO_FALLBACK>::get())
819+
bool UseDeviceLibs = !DeviceCodeWasInCache &&
820+
Img.getFormat() == SYCL_DEVICE_BINARY_TYPE_SPIRV &&
821+
!SYCLConfig<SYCL_DEVICELIB_NO_FALLBACK>::get();
822+
if (UseDeviceLibs)
822823
DeviceLibReqMask = getDeviceLibReqMask(Img);
823824

824825
std::vector<ur_program_handle_t> ProgramsToLink;
825826
// If we had a program in cache, then it should have been the fully linked
826827
// program already.
827828
if (!DeviceCodeWasInCache) {
828829
for (RTDeviceBinaryImage *BinImg : DeviceImagesToLink) {
830+
if (UseDeviceLibs)
831+
DeviceLibReqMask |= getDeviceLibReqMask(*BinImg);
829832
device_image_plain DevImagePlain =
830833
getDeviceImageFromBinaryImage(BinImg, Context, Device);
831834
const std::shared_ptr<detail::device_image_impl> &DeviceImageImpl =
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// REQUIRES: aspect-fp64
2+
// UNSUPPORTED: hip || cuda
3+
4+
// DEFINE: %{mathflags} = %if cl_options %{/clang:-fno-fast-math%} %else %{-fno-fast-math%}
5+
6+
// RUN: %{build} -fsycl-allow-device-image-dependencies -fsycl-device-lib-jit-link %{mathflags} -o %t.out
7+
// RUN: %{run} %t.out
8+
9+
#include <cmath>
10+
#include <sycl/detail/core.hpp>
11+
12+
using namespace sycl;
13+
14+
// Check that device lib dependencies are resolved with
15+
// -fsycl-allow-device-image-dependencies.
16+
// TODO this test will become redundant once
17+
// -fsycl-allow-device-image-dependencies is enabled by default.
18+
int main() {
19+
range<1> Range{1};
20+
queue q;
21+
buffer<double, 1> buffer1(Range);
22+
q.submit([&](sycl::handler &cgh) {
23+
auto Acc = buffer1.get_access<access::mode::write>(cgh);
24+
cgh.single_task<class DeviceMathTest>([=]() { Acc[0] = std::acosh(1.0); });
25+
});
26+
return 0;
27+
}

0 commit comments

Comments
 (0)