GPUOpen-LibrariesAndSDKs/HIPRT

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

TomClabault opened this issue · 1 comments

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.

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