Skip to content

[SYCL] Persistent program cache #3391

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 35 commits into from
Apr 9, 2021
Merged

Conversation

vladimirlaz
Copy link
Contributor

@vladimirlaz vladimirlaz commented Mar 22, 2021

First part of implementation for persistent cache of device programs following sycl/doc/KernelProgramCache.md:

Programs built for target device are stored in on-disk cache and used next time when the same application is executed.
What is done:

  • storing and loading files when built program is not found in in-memory cache;
  • file system concurrent access management (lock file is created per cache item while data is being written, read operation does not lock the cache item);
  • thread safety for persistent device code cache is not needed as soon as build/in-memory cache part is managed by program_manager and persisten_device_code_cache does not store data shared between threads.
  • Implement support for environment variables affecting cache:
    SYCL_CACHE_DIR
    SYCL_CACHE_TRACE
    SYCL_CACHE_DISABLE_PERSISTENT
    SYCL_CACHE_MIN_DEVICE_IMAGE_SIZE
    SYCL_CACHE_MAX_DEVICE_IMAGE_SIZE
    SYCL_CACHE_MIN_DEVICE_IMAGE_SIZE
  • Errors happening during filesystem operation cause corresponding cache operation silently ends:
    • for read operation, cache miss happens (without SYCL error), message is send to std::cerr if SYCL_CACHE_TRACE is set;
    • for write operation, no cache item stored (without SYCL error), message is send to std::cerr if SYCL_CACHE_TRACE is set;
  • Added on-device tests for basic cache functionality and unit tests for concurrent access to FS and error management.

To be done in next patches:

  • implement rest of environment variables and extend them to both in-memory and persistent cache;
  • implement kernel eviction mechanism for on-device and in-memory caches.

After 86b0e8d patch extra operations with device images happen before
check if it is present in in-memory cache. For applications with small
kernels which are executed multiple times noticeable performance
degradation is seen for host code. That was done to get build options
stored in the kernel image and use them as in-memory cache key. At the
same time kernel image (where these options are taken from) is used in
cache key so it is reasonable to use only build options which are
specified in SYCL API and/or environment variables as separate cache
key.

Getting build options from kernel image is moved back to build
operation which happens only if built program is missed in in-memory
cache.
@vladimirlaz
Copy link
Contributor Author

/summary:run

@vladimirlaz
Copy link
Contributor Author

/summary:run

@vladimirlaz vladimirlaz marked this pull request as ready for review March 24, 2021 19:39
@vladimirlaz vladimirlaz requested review from kbobrovs, pvchupin and a team as code owners March 24, 2021 19:39
@vladimirlaz vladimirlaz requested a review from rbegam March 24, 2021 19:39
@vladimirlaz vladimirlaz requested a review from pvchupin March 25, 2021 15:56
@vladimirlaz
Copy link
Contributor Author

/summary:run

@vladimirlaz vladimirlaz requested a review from kbobrovs April 2, 2021 15:28
@vladimirlaz
Copy link
Contributor Author

/summary:run

@vladimirlaz
Copy link
Contributor Author

/summary:run

@vladimirlaz vladimirlaz requested review from kbobrovs and s-kanaev April 7, 2021 19:03
@vladimirlaz
Copy link
Contributor Author

/summary:run

@vladimirlaz
Copy link
Contributor Author

/summary:run

@vladimirlaz vladimirlaz requested review from s-kanaev and kbobrovs April 8, 2021 12:01
Copy link
Contributor

@s-kanaev s-kanaev left a comment

Choose a reason for hiding this comment

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

LGTM

@pvchupin
Copy link
Contributor

pvchupin commented Apr 8, 2021

@kbobrovs to approve

Copy link
Contributor

@kbobrovs kbobrovs left a comment

Choose a reason for hiding this comment

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

Thanks Vladimir, LGTM.

@vladimirlaz vladimirlaz merged commit ec97165 into intel:sycl Apr 9, 2021
std::vector<std::vector<char>> PersistentDeviceCodeCache::getItemFromDisc(
const device &Device, const RTDeviceBinaryImage &Img,
const SerializedObj &SpecConsts, const std::string &BuildOptionsString,
RT::PiProgram &NativePrg) {
Copy link
Contributor

Choose a reason for hiding this comment

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

@vladimirlaz, post-commit build fails with

/home/runner/work/llvm/llvm/src/sycl/source/detail/persistent_device_code_cache.cpp:130:20: error: unused parameter 'NativePrg' [-Werror,-Wunused-parameter]
    RT::PiProgram &NativePrg) {

Please, fix ASAP.

@vladimirlaz vladimirlaz deleted the jit_cache_2 branch April 23, 2021 06:26
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.

5 participants