From 3768cabb9fdd3a6e23c9cf7035342a2a87604d8f Mon Sep 17 00:00:00 2001 From: Salman Ul Haq Date: Sun, 22 Mar 2015 01:40:48 +0500 Subject: [PATCH 1/2] added clear_persistent_cache and minor update to persistent caching --- include/boost/compute/program.hpp | 3 ++- .../boost/compute/utility/program_cache.hpp | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/include/boost/compute/program.hpp b/include/boost/compute/program.hpp index 0daf5e2ab..40b18e1ca 100644 --- a/include/boost/compute/program.hpp +++ b/include/boost/compute/program.hpp @@ -516,7 +516,8 @@ class program << "// " << options << "\n\n" << source; - hash = detail::sha1(src.str()); + // Gets rebuilt if either source, or device (indicated by name) or compile options change + hash = detail::sha1(src.str() + context.device.name().str() + options.str()); } // Try to get cached program binaries: diff --git a/include/boost/compute/utility/program_cache.hpp b/include/boost/compute/utility/program_cache.hpp index ce29f1fa2..5a219ce43 100644 --- a/include/boost/compute/utility/program_cache.hpp +++ b/include/boost/compute/utility/program_cache.hpp @@ -82,6 +82,25 @@ class program_cache : boost::noncopyable m_cache.clear(); } + /// Clears persistent cache by deleting the boost_compute folder + void clear_persistent_cache() + { +#ifdef BOOST_COMPUTE_USE_OFFLINE_CACHE + // Path delimiter symbol for the current OS. + static const std::string delim = boost::filesystem::path("/").make_preferred().string(); + + // Path to appdata folder. +#ifdef WIN32 + static const std::string appdata = detail::getenv("APPDATA") + + delim + "boost_compute"; +#else + static const std::string appdata = detail::getenv("HOME") + + delim + ".boost_compute"; +#endif + boost::filesystem::remove_all(appdata); +#endif + } + /// Returns the program object with \p key. Returns a null optional if no /// program with \p key exists in the cache. boost::optional get(const std::string &key) From ea7a775eb9da706424e47361d8e5d67921cc00e6 Mon Sep 17 00:00:00 2001 From: Salman Ul Haq Date: Sun, 22 Mar 2015 11:43:32 +0500 Subject: [PATCH 2/2] clear_persistent_cache now static function and changed hash following @ddemidov suggestion --- include/boost/compute/program.hpp | 32 +++++++++++-------- .../boost/compute/utility/program_cache.hpp | 14 ++++++-- 2 files changed, 30 insertions(+), 16 deletions(-) diff --git a/include/boost/compute/program.hpp b/include/boost/compute/program.hpp index 40b18e1ca..61f3594c0 100644 --- a/include/boost/compute/program.hpp +++ b/include/boost/compute/program.hpp @@ -505,20 +505,24 @@ class program { #ifdef BOOST_COMPUTE_USE_OFFLINE_CACHE // Get hash string for the kernel. - std::string hash; - { - device d(context.get_device()); - platform p = d.platform(); - - std::ostringstream src; - src << "// " << p.name() << " v" << p.version() << "\n" - << "// " << context.get_device().name() << "\n" - << "// " << options << "\n\n" - << source; - - // Gets rebuilt if either source, or device (indicated by name) or compile options change - hash = detail::sha1(src.str() + context.device.name().str() + options.str()); - } + // std::string hash; + // { + // device d(context.get_device()); + // platform p = d.platform(); + + // std::ostringstream src; + // src << "// " << p.name() << " v" << p.version() << "\n" + // << "// " << context.get_device().name() << "\n" + // << "// " << options << "\n\n" + // << source; + // } + + boost::detail::sha1 hash; + hash(p.name()); + hash(p.version()); + hash(context.get_device().name()); + hash(options); + hash(source); // Try to get cached program binaries: try { diff --git a/include/boost/compute/utility/program_cache.hpp b/include/boost/compute/utility/program_cache.hpp index 5a219ce43..b9a2be54a 100644 --- a/include/boost/compute/utility/program_cache.hpp +++ b/include/boost/compute/utility/program_cache.hpp @@ -83,7 +83,7 @@ class program_cache : boost::noncopyable } /// Clears persistent cache by deleting the boost_compute folder - void clear_persistent_cache() + static void clear_persistent_cache() { #ifdef BOOST_COMPUTE_USE_OFFLINE_CACHE // Path delimiter symbol for the current OS. @@ -97,7 +97,17 @@ class program_cache : boost::noncopyable static const std::string appdata = detail::getenv("HOME") + delim + ".boost_compute"; #endif - boost::filesystem::remove_all(appdata); + try + { + if(boost::filesystem::exists(appdata)) + { + boost::filesystem::remove_all(appdata); + } + } + catch(boost::filesystem::filesystem_error const & err) + { + std::cout<