File tree 3 files changed +37
-28
lines changed
3 files changed +37
-28
lines changed Original file line number Diff line number Diff line change @@ -335,7 +335,8 @@ class meta_kernel
335
335
std::string source = this ->source ();
336
336
337
337
// 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));
339
340
340
341
// load program cache
341
342
boost::shared_ptr<program_cache> cache =
Original file line number Diff line number Diff line change @@ -19,20 +19,31 @@ namespace boost {
19
19
namespace compute {
20
20
namespace detail {
21
21
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
+ };
36
47
37
48
} // end detail namespace
38
49
} // end compute namespace
Original file line number Diff line number Diff line change @@ -505,19 +505,16 @@ class program
505
505
{
506
506
#ifdef BOOST_COMPUTE_USE_OFFLINE_CACHE
507
507
// 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
+ ;
521
518
522
519
// Try to get cached program binaries:
523
520
try {
You can’t perform that action at this time.
0 commit comments