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

Compiler::isCachedFileUpToDate() doesn't take the actual content of the file into account, only the file modification time #9

Open
TomClabault opened this issue Apr 18, 2024 · 1 comment

Comments

@TomClabault
Copy link

Here's the implementation of Compiler::isCachedFilUpToDate() (repo file link):

bool Compiler::isCachedFileUpToDate( const std::filesystem::path& cachedFile, const std::filesystem::path& moduleName )
{
	if ( !std::filesystem::exists( cachedFile ) ) return false;
	if ( !std::filesystem::exists( moduleName ) ) return true;
	return std::filesystem::last_write_time( moduleName ) < std::filesystem::last_write_time( cachedFile );
}

The return statement returns true if the kernel file being checked against the cache hasn't been modified since it was cached.
If the content of the kernel file indirectly changed (modification of a header included by the kernel for example), which means that the kernel needs to be recompiled, the cache will not detect this change (since the actual kernel file wasn't modified per se), the kernel file won't be recompiled and the execution will proceed with the outdated version of the kernel picked up from the cache.

@meistdan
Copy link
Collaborator

Thank you for reporting this. We are ware of this issue. Unfortunately, I do not see any straightforward/elegant solution for this.

This caching is used either for source files and also for the user bitcode binary. For bitcode, I was thinking about computing the hash directly from the binary data, but unfortunately the compiler inserts some meta-data different each time the bitcode is compiled.

For the source code compilation, this is a recursive problem. To detect the modification, we need to check not just headers included in the module, but also headers included in the headers included in the module and so on. What would help is to have a fast way to get the output of preprocessor and use it to compute the hash. Unfortunately, as far as I know, hiprtc/nvrtc does not support such option.

We added the option to disable caching, which might useful for debugging/development when source files changes frequently:
https://github.com/GPUOpen-LibrariesAndSDKs/HIPRT/blob/main/hiprt/hiprt.h.in#L558
https://github.com/GPUOpen-LibrariesAndSDKs/HIPRT/blob/main/hiprt/hiprt.h.in#L584

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

No branches or pull requests

2 participants