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

added clear_persistent_cache and minor update to persistent caching #440

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 2 additions & 1 deletion include/boost/compute/program.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As Denis commented, this additional information should already be stored inside the program source and therefore I don't think we need to store it here.

}

// Try to get cached program binaries:
Expand Down
19 changes: 19 additions & 0 deletions include/boost/compute/utility/program_cache.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this could be a static method (so users can just call program_cache::clear_persistent_cache() directly without having to get/create a program_cache object).

{
#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.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of copying these lines, could you just call detail::appdata_path() directly?

#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);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't remember, but will this through an exception if the offline cache directory hasn't been created yet? If so we should catch/ignore that.

#endif
}

/// Returns the program object with \p key. Returns a null optional if no
/// program with \p key exists in the cache.
boost::optional<program> get(const std::string &key)
Expand Down