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

Computes a SHA256 hash per device compilation unit and uses for hashing #72

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions lib/CompilerInterfaceDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

#include "CompilerInterfaceDevice.h"
#include "JitEngineDevice.hpp"
#include <llvm/ADT/StringExtras.h>
#include <llvm/ADT/StringRef.h>

using namespace proteus;

Expand Down Expand Up @@ -46,8 +48,10 @@ __jit_register_linked_binary(void *FatbinWrapper, const char *ModuleId) {
}

extern "C" __attribute((used)) void
__jit_register_function(void *Handle, void *Kernel, char *KernelName,
int32_t *RCIndices, int32_t *RCTypes, int32_t NumRCs) {
__jit_register_function(void *Handle, const char *ModuleSHA256, void *Kernel,
char *KernelName, int32_t *RCIndices, int32_t *RCTypes,
int32_t NumRCs) {
auto &Jit = JitDeviceImplT::instance();
Jit.registerFunction(Handle, Kernel, KernelName, RCIndices, RCTypes, NumRCs);
Jit.registerFunction(Handle, ModuleSHA256, Kernel, KernelName, RCIndices,
RCTypes, NumRCs);
}
17 changes: 13 additions & 4 deletions lib/JitCache.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,21 @@ inline hash_code hash_value(const proteus::RuntimeConstant &RC) {

template <typename Function_t> class JitCache {
public:
template <typename T>
uint64_t hash(StringRef ModuleUniqueId, StringRef KernelHash,
StringRef KernelName, const T &GridDim, const T &BlockDim,
const RuntimeConstant *RC, int NumRuntimeConstants) const {
ArrayRef<RuntimeConstant> Data(RC, NumRuntimeConstants);
auto HashValue = hash_combine(ModuleUniqueId, KernelHash, KernelName,
GridDim.x, GridDim.y, GridDim.z, BlockDim.x,
BlockDim.y, BlockDim.z, Data);
return HashValue;
}

uint64_t hash(StringRef ModuleUniqueId, StringRef FnName,
const RuntimeConstant *RC, int NumRuntimeConstants) const {
ArrayRef<RuntimeConstant> Data(RC, NumRuntimeConstants);
auto HashValue = hash_combine(ExePath, ModuleUniqueId, FnName, Data);
auto HashValue = hash_combine(ModuleUniqueId, FnName, Data);
return HashValue;
}

Expand Down Expand Up @@ -98,7 +109,6 @@ template <typename Function_t> class JitCache {

JitCache() {
// NOTE: Linux-specific.
ExePath = std::filesystem::canonical("/proc/self/exe");
}

private:
Expand All @@ -115,11 +125,10 @@ template <typename Function_t> class JitCache {
DenseMap<uint64_t, JitCacheEntry> CacheMap;
// Use the executable binary path when hashing to differentiate between
// same-named kernels generated by other executables.
std::filesystem::path ExePath;
uint64_t Hits = 0;
uint64_t Accesses = 0;
};

} // namespace proteus

#endif
#endif
Loading
Loading