File tree Expand file tree Collapse file tree 3 files changed +37
-28
lines changed Expand file tree Collapse file tree 3 files changed +37
-28
lines changed Original file line number Diff line number Diff line change @@ -335,7 +335,8 @@ class meta_kernel
335335 std::string source = this ->source ();
336336
337337 // generate cache key
338- std::string cache_key = " __boost_meta_kernel_" + detail::sha1 (source);
338+ std::string cache_key = " __boost_meta_kernel_" +
339+ static_cast <std::string>(detail::sha1 (source));
339340
340341 // load program cache
341342 boost::shared_ptr<program_cache> cache =
Original file line number Diff line number Diff line change @@ -19,20 +19,31 @@ namespace boost {
1919namespace compute {
2020namespace detail {
2121
22- // Returns SHA1 hash of the string parameter.
23- inline std::string sha1 (const std::string &src) {
24- boost::uuids::detail::sha1 sha1;
25- sha1.process_bytes (src.c_str (), src.size ());
26-
27- unsigned int hash[5 ];
28- sha1.get_digest (hash);
29-
30- std::ostringstream buf;
31- for (int i = 0 ; i < 5 ; ++i)
32- buf << std::hex << std::setfill (' 0' ) << std::setw (8 ) << hash[i];
33-
34- return buf.str ();
35- }
22+ // Accumulates SHA1 hash of the passed strings.
23+ class sha1 {
24+ public:
25+ sha1 (const std::string &s = " " ) {
26+ if (!s.empty ()) this ->process (s);
27+ }
28+
29+ sha1& process (const std::string &s) {
30+ h.process_bytes (s.c_str (), s.size ());
31+ return *this ;
32+ }
33+
34+ operator std::string () {
35+ unsigned int digest[5 ];
36+ h.get_digest (digest);
37+
38+ std::ostringstream buf;
39+ for (int i = 0 ; i < 5 ; ++i)
40+ buf << std::hex << std::setfill (' 0' ) << std::setw (8 ) << digest[i];
41+
42+ return buf.str ();
43+ }
44+ private:
45+ boost::uuids::detail::sha1 h;
46+ };
3647
3748} // end detail namespace
3849} // end compute namespace
Original file line number Diff line number Diff line change @@ -505,19 +505,16 @@ class program
505505 {
506506#ifdef BOOST_COMPUTE_USE_OFFLINE_CACHE
507507 // Get hash string for the kernel.
508- std::string hash;
509- {
510- device d (context.get_device ());
511- platform p = d.platform ();
512-
513- std::ostringstream src;
514- src << " // " << p.name () << " v" << p.version () << " \n "
515- << " // " << context.get_device ().name () << " \n "
516- << " // " << options << " \n\n "
517- << source;
518-
519- hash = detail::sha1 (src.str ());
520- }
508+ device d = context.get_device ();
509+ platform p = d.platform ();
510+
511+ detail::sha1 hash;
512+ hash.process ( p.name () )
513+ .process ( p.version () )
514+ .process ( d.name () )
515+ .process ( options )
516+ .process ( source )
517+ ;
521518
522519 // Try to get cached program binaries:
523520 try {
You can’t perform that action at this time.
0 commit comments