Skip to content

Commit

Permalink
Better interface for sha1 hasher
Browse files Browse the repository at this point in the history
  • Loading branch information
ddemidov committed Apr 8, 2015
1 parent 052f52b commit 3482d1d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 15 deletions.
5 changes: 3 additions & 2 deletions vexcl/backend/common.hpp
Expand Up @@ -186,11 +186,12 @@ inline std::string program_binaries_path(const std::string &hash, bool create =
class sha1_hasher {
public:
sha1_hasher(const std::string &s = "") {
if (!s.empty()) (*this)(s);
if (!s.empty()) this->process(s);
}

void operator()(const std::string &s) {
sha1_hasher& process(const std::string &s) {
h.process_bytes(s.c_str(), s.size());
return *this;
}

operator std::string() {
Expand Down
13 changes: 7 additions & 6 deletions vexcl/backend/cuda/compiler.hpp
Expand Up @@ -63,15 +63,16 @@ inline CUmodule build_sources(

queue.context().set_current();

sha1_hasher sha1(source);

sha1(queue.device().name());
sha1(options);

auto cc = queue.device().compute_capability();
std::ostringstream ccstr;
ccstr << std::get<0>(cc) << std::get<1>(cc);
sha1(ccstr.str());

sha1_hasher sha1;
sha1.process(source)
.process(queue.device().name())
.process(options)
.process(ccstr.str())
;

std::string hash = static_cast<std::string>(sha1);

Expand Down
15 changes: 8 additions & 7 deletions vexcl/backend/opencl/compiler.hpp
Expand Up @@ -134,12 +134,6 @@ inline cl::Program build_sources(

#ifdef VEXCL_CACHE_KERNELS
// Get unique (hopefully) hash string for the kernel.
sha1_hasher sha1(source);

sha1(cl::Platform(device[0].getInfo<CL_DEVICE_PLATFORM>()).getInfo<CL_PLATFORM_NAME>());
sha1(device[0].getInfo<CL_DEVICE_NAME>());
sha1(compile_options);

std::ostringstream compiler_tag;
compiler_tag
#if defined(_MSC_VER)
Expand All @@ -152,7 +146,14 @@ inline cl::Program build_sources(
<< "unknown"
#endif
;
sha1(compiler_tag.str());

sha1_hasher sha1;
sha1.process(source)
.process(cl::Platform(device[0].getInfo<CL_DEVICE_PLATFORM>()).getInfo<CL_PLATFORM_NAME>())
.process(device[0].getInfo<CL_DEVICE_NAME>())
.process(compile_options)
.process(compiler_tag.str())
;

std::string hash = static_cast<std::string>(sha1);

Expand Down

0 comments on commit 3482d1d

Please sign in to comment.