Browse Source

fix(fastrun/persistent_cache): fix fastrun crash

GitOrigin-RevId: b3f7bdf7dc
tags/v1.0.0-rc1
Megvii Engine Team 4 years ago
parent
commit
2dc9190055
2 changed files with 5 additions and 4 deletions
  1. +3
    -3
      src/core/impl/utils/persistent_cache.cpp
  2. +2
    -1
      src/core/include/megbrain/utils/persistent_cache.h

+ 3
- 3
src/core/impl/utils/persistent_cache.cpp View File

@@ -176,11 +176,9 @@ AlgoChooserProfileCache::get(const Key &key) {

auto entry_len = read_uint32();
mgb_assert(buf + entry_len <= buf_end);
int rep;
auto nr = sscanf(reinterpret_cast<const char*>(buf), ENTRY_FMT,
&rep, &i.time, &i.workspace);
&i.reproducible, &i.time, &i.workspace);
mgb_assert(nr == 3);
i.reproducible = rep;
buf += entry_len;
}
mgb_assert(buf == buf_end);
@@ -228,6 +226,8 @@ void AlgoChooserProfileCache::put(const Key &key, Result &result) {
val.resize(pos + SPR_SIZE);
uint32_t nr = snprintf(&val[pos], SPR_SIZE,
ENTRY_FMT, i.reproducible, i.time, i.workspace);
//! for memory boundary failed, snprintf ret do not contain \0
nr += 1;
mgb_assert(nr < SPR_SIZE);
memcpy(&val[pos - sizeof(uint32_t)], &nr, sizeof(nr));
val.resize(pos + nr);


+ 2
- 1
src/core/include/megbrain/utils/persistent_cache.h View File

@@ -100,7 +100,8 @@ namespace mgb {

struct ResultEntry {
std::string algo; //! identifier of the algorithm
bool reproducible; //! whether algorithm is reproducible
//! sscanf will up bool as int
int reproducible; //! whether algorithm is reproducible
double time; //! execution time in seconds
size_t workspace; //! workspace in bytes
};


Loading…
Cancel
Save