#include "scratchpad_debug.hpp"
#include "engine.hpp"
#include "memory_debug.hpp"
#include "memory_tracking.hpp"
namespace dnnl {
namespace impl {
namespace scratchpad_debug {
void protect_scratchpad_buffer(void *scratchpad_ptr, engine_kind_t engine_kind,
const memory_tracking::registry_t ®istry) {
if (scratchpad_ptr == nullptr) return;
auto end = registry.end(scratchpad_ptr);
auto curr = registry.begin(scratchpad_ptr);
for (; curr != end; curr++) {
std::pair<void *, size_t> data_range = *curr;
memory_debug::protect_buffer(
data_range.first, data_range.second, engine_kind);
}
}
void unprotect_scratchpad_buffer(const void *scratchpad_ptr,
engine_kind_t engine_kind,
const memory_tracking::registry_t ®istry) {
if (scratchpad_ptr == nullptr) return;
auto end = registry.cend(scratchpad_ptr);
auto curr = registry.cbegin(scratchpad_ptr);
for (; curr != end; curr++) {
std::pair<const void *, size_t> data_range = *curr;
memory_debug::unprotect_buffer(
data_range.first, data_range.second, engine_kind);
}
}
void protect_scratchpad_buffer(const memory_storage_t *storage,
const memory_tracking::registry_t ®istry) {
if (storage != nullptr)
protect_scratchpad_buffer(
storage->data_handle(), storage->engine()->kind(), registry);
}
void unprotect_scratchpad_buffer(const memory_storage_t *storage,
const memory_tracking::registry_t ®istry) {
if (storage != nullptr)
unprotect_scratchpad_buffer(
storage->data_handle(), storage->engine()->kind(), registry);
}
} } }