Skip to content
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

[SYCL] Remove dependency on libdevice binary for sycl-device-lib test #3639

Merged
merged 5 commits into from
May 19, 2021

Conversation

jinge90
Copy link
Contributor

@jinge90 jinge90 commented Apr 28, 2021

Signed-off-by: gejin [email protected]

@jinge90 jinge90 requested a review from bader April 28, 2021 02:36
@jinge90
Copy link
Contributor Author

jinge90 commented Apr 28, 2021

Hi, @bader
This patch aims to fix #3630
Thanks very much.

bader
bader previously requested changes Apr 28, 2021
Comment on lines 4168 to 4169
if (llvm::sys::fs::exists(LibName) ||
C.getArgs().hasArg(options::OPT__HASH_HASH_HASH)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think customizing Driver's behavior for the test is a good solution to the problem.
The common approach in clang LIT infrastructure is to create an "input files", so you we test all scenarios (see https://github.com/intel/llvm/tree/sycl/clang/test/Driver/Inputs).
Please, create corresponding files and test Driver's behavior when no/part/all libraries are found.

Copy link
Contributor Author

@jinge90 jinge90 Apr 28, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, @bader and @mdtoguchi
Current implementation for adding SYCL device libraries in driver doesn't support such "input files". The reason is we have assumption for SYCL device library binaries, in https://github.com/intel/llvm/blob/sycl/clang/lib/Driver/Driver.cpp#L4141
we get the real path of compiler(suppose it is ${compiler_bin_path}) and assume SYCL device binaries are located in ${compiler_bin_path}/../lib/. In other targets including CUDA, compiler driver supports configuring the libdevice binary path based on sys_root env var.
If we want to use the "input file" mechanism in lit test for SYCL device library, can we consider to provide a way to configure SYCL device library path? For example,

  1. adding an option for sycl device library path to override the default path
  2. Use an env var for the sycl device library path
    Thanks very much.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This sounds like a bug. Why can't we distribute these libraries in SYSTEM paths, which are configured through standard command line options (or SYCL specific)?

Here is a couple of examples how it's done for:

  • CUDA: clang/test/Driver/cuda-detect-path.cu, clang/test/Driver/cuda-detect.cu
  • ROCM: clang/test/Driver/hip-device-libs.hip clang/test/Driver/rocm-detect.cl clang/test/Driver/rocm-device-libs.cl

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, @bader
SYCL device library binaries are shipped together with all sycl runtime libraries such as libsycl.so, libze_loader.so....
Do we have any mechanism to configure path of those libraries through any command line option?
It seems that other targets have such mechanism. For CUDA, "-cuda-path=XX" is used: https://github.com/intel/llvm/blob/sycl/clang/lib/Driver/ToolChains/Cuda.cpp#L137
Thanks very much.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Possibly introduce a similar option for us: -fsycl-devicelib-path=<arg> which will point to the desired location for the device libraries. Currently we rely on expected locations and the known directory structure to find and pick these up. Is there a build target we can set a REQUIRES to for the test?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding the libsycldevice as dependency for sycl-device-lib makes sense for fixing this issue. I agree that we can consider adding a driver option like "-fsycl-devicelib-path=XXX" as a separate issue.
Hi, @bader and @andykaylor
Do you have any concern if we follow this approach?
Thanks very much.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it's a good solution. The dependency on libsycldevice is not needed to test clang's driver functionality. Having mock files in test Inputs and configuring search path through existing options like -system should be enough.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, @bader @vzakhari @mdtoguchi @andykaylor
It seems that we have 2 options here:

  1. Adding libsycldevice as dependency for sycl-device-lib test.
  2. Having mock input files and providing some way to configure the search patch for device library binaries in driver.

For 1,
Pros: No change needed in clang driver.
Cons: This approach doesn't align with other targets like CUDA.

For 2,
Pros: align with other targets' approach and this clang driver lit test won't have any dependency other than OS.
Cons: we need support configuring sycl device library search path in driver, either via any existing options like -isystem, -isysroot or sycl specific option like "-fsycl-device-lib-path".

It seems that we can consider another question firstly, do we need to support configuring sycl device library search path in driver? If we have strong reasons to support, I think approach 2 is better since it aligns with other targets and libsycldevice dependency will be unnecessary at that time.
Thanks very much.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, @bader @vzakhari @mdtoguchi @andykaylor
Do you have any preference for option 1 and option 2 mentioned above?
If no objection, I plan to follow Alexey's suggestion to support searching sycl device libraries through existing option "--sysroot".
Thanks very much.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having the test be compartmentalized (driver specific) is a good thing. I'm OK with #2.

@bader
Copy link
Contributor

bader commented Apr 28, 2021

Hi, @bader
This patch aims to fix #3630
Thanks very much.

Please, link the issue, so it's closed when pull request is merged.

Copy link
Contributor

@mdtoguchi mdtoguchi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall, this looks OK. For practical purposes, would there be any expectation that the device libraries will ever be located in which we require usage of --sysroot?

@bader bader dismissed their stale review May 12, 2021 17:42

No objections for new approach from my side. Thanks!

@jinge90
Copy link
Contributor Author

jinge90 commented May 13, 2021

Overall, this looks OK. For practical purposes, would there be any expectation that the device libraries will ever be located in which we require usage of --sysroot?

Hi, @mdtoguchi
Currently, we don't have such expectation. This patch only follows other targets' solution.
Thanks very much.

@jinge90 jinge90 requested a review from mdtoguchi May 13, 2021 02:24
llvm::sys::path::append(LibLoc, "/../lib");
SmallVector<SmallString<128>, 4> LibLocCandidates;
LibLocCandidates.emplace_back(TC->getDriver().Dir + "/../lib");
LibLocCandidates.emplace_back(TC->getDriver().SysRoot + "/lib");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to my understanding SysRoot default value matches Dir/../, so probably we can simplify the code and use only one candidate. Right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, @bader
I just checked that if we don't specify "--sysroot=..." in command line, the "TC->getDriver().SysRoot" will be empty string.
So, we have to keep 2 candidates here.
Thanks very much.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay. I just noticed that similar logic for HIP/ROCM is implemented in toolchain specific file.
See RocmInstallationDetector in https://github.com/intel/llvm/blob/sycl/clang/lib/Driver/ToolChains/AMDGPU.cpp#L171 .
@mdtoguchi, should we move this code to https://github.com/intel/llvm/blob/sycl/clang/lib/Driver/ToolChains/SYCL.cpp?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure - maybe add a dir vector that holds the known locations in which the libs can be searched for.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, @bader and @mdtoguchi
So, do you mean we need to add a "SyclInstallationDectector" in SYCL.cpp and use it to record search paths for libs, bins, include?
Thanks very much.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jinge90, I don't think we need to add a full installation detector as everything is provided with the compiler. I think just add the lib search directories when the SYCLToolChain is created.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, @mdtoguchi
I suggest to add a very simple "SyclInstallationDectector" which only provide APIs to query lib search path for now. If we have new request, we can extend the simple "SyclInstallDetector", is it OK?
Thanks very much.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, @mdtoguchi and @bader
I added a very simple SYCLInstallationDetector, there is no much to do in this function since we don't have many requirements for detecting installation structure currently. If we have some requirements in the future such as adding some option like "-fsycl-installation=...", it is easy to extend this class.
Thanks very much.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think just add the lib search directories when the SYCLToolChain is created.

I thought that Mike suggestion is that we move addSYCLDeviceLibs to SYCLToolChain.

@jinge90
Copy link
Contributor Author

jinge90 commented May 17, 2021

/summary:run

Copy link
Contributor

@mdtoguchi mdtoguchi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks reasonable to me. We could use this framework for setting up the search location for the headers too.

@bader bader merged commit 1307a22 into intel:sycl May 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Driver] Clang :: Driver/sycl-device-lib.cpp fails if libdevice project is not pre-built
4 participants