Skip to content

Commit 4d36162

Browse files
committed
updating uda cache
1 parent 69050d8 commit 4d36162

File tree

5 files changed

+56
-33
lines changed

5 files changed

+56
-33
lines changed

.gitignore

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
# Build & Install
2-
build*/*
3-
install/*
2+
build*
3+
install
44
cmake-build-*
5-
Testing/*
5+
Testing
6+
venv
7+
.ropeproject
68

79
# Machine dependent compile commands
810
compile_commands.json

mapping_plugin/src/uda_data_source.cpp

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -79,16 +79,6 @@ std::string json_plugin::UDADataSource::get_request_str(const libtokamap::DataSo
7979
return request;
8080
}
8181

82-
bool json_plugin::UDADataSource::copy_from_cache(libtokamap::RamCache* ram_cache, DATA_BLOCK* data_block,
83-
const libtokamap::MapArguments& /*arguments*/,
84-
const std::string& request_str) const
85-
{
86-
if (!m_cache_enabled) {
87-
return false;
88-
}
89-
return json_plugin::copy_from_cache(*ram_cache, request_str, data_block);
90-
}
91-
9282
int json_plugin::UDADataSource::call_plugins(DATA_BLOCK* data_block, const libtokamap::DataSourceArgs& data_source_args,
9383
const libtokamap::MapArguments& arguments,
9484
libtokamap::RamCache* ram_cache) const
@@ -129,7 +119,10 @@ int json_plugin::UDADataSource::call_plugins(DATA_BLOCK* data_block, const libto
129119
// ram_cache->log(libtokamap::LogLevel::DEBUG, "caching disabled");
130120
// }
131121

132-
bool cache_hit = copy_from_cache(ram_cache, data_block, arguments, request_str);
122+
bool cache_hit = false;
123+
if (m_cache_enabled) {
124+
cache_hit = json_plugin::copy_from_cache(*ram_cache, request_str, data_block);
125+
}
133126
if (cache_hit) {
134127
// ram_cache->log(libtokamap:LogLevel::INFO, "Adding cached datablock onto plugin_interface");
135128
// ram_cache->log(libtokamap:LogLevel::INFO,
@@ -165,9 +158,9 @@ int json_plugin::UDADataSource::call_plugins(DATA_BLOCK* data_block, const libto
165158

166159
// Add retrieved datablock to cache. data is copied from datablock into a new libtokamap:data_entry. original
167160
// data remains on block (on plugin_interface structure) for return.
168-
// if (m_cache_enabled) {
169-
// ram_cache->add(request_str, data_block);
170-
// }
161+
if (m_cache_enabled) {
162+
json_plugin::copy_to_cache(*ram_cache, request_str, data_block);
163+
}
171164
}
172165

173166
return err;

mapping_plugin/src/uda_data_source.hpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,6 @@ class UDADataSource : public libtokamap::DataSource
3535

3636
[[nodiscard]] std::string get_request_str(const libtokamap::DataSourceArgs& data_source_args,
3737
const libtokamap::MapArguments& arguments) const;
38-
[[nodiscard]] bool copy_from_cache(libtokamap::RamCache* ram_cache, DATA_BLOCK* data_block,
39-
const libtokamap::MapArguments& arguments, const std::string& request_str) const;
4038
[[nodiscard]] int call_plugins(DATA_BLOCK* data_block, const libtokamap::DataSourceArgs& data_source_args,
4139
const libtokamap::MapArguments& arguments, libtokamap::RamCache* ram_cache) const;
4240
};

mapping_plugin/src/uda_ram_cache.cpp

Lines changed: 43 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include <string>
1515
#include <string_view>
1616
#include <vector>
17+
#include <utility>
1718

1819
// LibTokaMap includes
1920
#include <utils/ram_cache.hpp>
@@ -350,6 +351,33 @@ bool json_plugin::copy_dim_from_cache(const libtokamap::RamCache& cache, const s
350351
return true;
351352
}
352353

354+
void json_plugin::copy_to_cache(libtokamap::RamCache& ram_cache, const std::string& key, const DATA_BLOCK* data_block) {
355+
auto entry = std::make_unique<UDACacheEntry>();
356+
357+
size_t data_size = data_block->data_n * size_of_uda_type(data_block->data_type);
358+
entry->data.resize(data_size);
359+
std::copy(data_block->data, data_block->data + data_size, entry->data.begin());
360+
361+
entry->error_high = {};
362+
entry->error_low = {};
363+
364+
entry->dims.resize(data_block->rank);
365+
entry->dim_types.resize(data_block->rank);
366+
for (int i = 0; i < data_block->rank; i++) {
367+
const DIMS* dim = &data_block->dims[i];
368+
size_t dim_size = dim->dim_n * size_of_uda_type(dim->data_type);
369+
entry->dims[i].resize(dim_size);
370+
std::copy(dim->dim, dim->dim + dim_size, entry->dims[i].begin());
371+
entry->dim_types[i] = dim->data_type;
372+
}
373+
374+
entry->order = data_block->order;
375+
entry->data_type = data_block->data_type;
376+
entry->error_type = data_block->error_type;
377+
378+
ram_cache.add(key, std::move(entry));
379+
}
380+
353381
bool json_plugin::copy_from_cache(const libtokamap::RamCache& cache, const std::string& key, DATA_BLOCK* data_block)
354382
{
355383
auto entry = cache.get(key);
@@ -366,38 +394,39 @@ bool json_plugin::copy_from_cache(const libtokamap::RamCache& cache, const std::
366394
// DATA_BLOCK* data_block = (DATA_BLOCK*) malloc(sizeof(DATA_BLOCK));
367395
initDataBlock(data_block);
368396
data_block->data_type = data_entry->data_type;
369-
data_block->data_n = data_entry->data.size() / size_of_uda_type(data_entry->data_type);
397+
data_block->data_n = static_cast<int>(data_entry->data.size()) / size_of_uda_type(data_entry->data_type);
370398

371399
log(LogLevel::INFO, "data size is: " + std::to_string(data_block->data_n));
372400

373401
data_block->data = (char*)malloc(data_entry->data.size());
374-
std::copy(data_entry->data.data(), data_entry->data.data() + data_entry->data.size(), data_block->data);
402+
std::copy(data_entry->data.begin(), data_entry->data.end(), data_block->data);
403+
375404
if (!data_entry->error_high.empty()) {
376405
data_block->errhi = (char*)malloc(data_entry->error_high.size());
377-
std::copy(data_entry->error_high.data(), data_entry->error_high.data() + data_entry->error_high.size(),
378-
data_block->errhi);
406+
std::copy(data_entry->error_high.begin(), data_entry->error_high.end(), data_block->errhi);
379407
}
380408
if (!data_entry->error_low.empty()) {
381409
data_block->errlo = (char*)malloc(data_entry->error_low.size());
382-
std::copy(data_entry->error_low.data(), data_entry->error_low.data() + data_entry->error_low.size(),
383-
data_block->errlo);
410+
std::copy(data_entry->error_low.begin(), data_entry->error_low.end(), data_block->errlo);
384411
}
412+
385413
data_block->rank = data_entry->dims.size();
386414
log(LogLevel::INFO, "data rank is: " + std::to_string(data_block->rank));
387415

388-
DIMS* dims = (DIMS*)malloc(data_block->rank * sizeof(DIMS));
416+
data_block->dims = (DIMS*)malloc(data_block->rank * sizeof(DIMS));
389417
for (unsigned int i = 0; i < data_block->rank; ++i) {
390-
initDimBlock(&dims[i]);
418+
DIMS* dim = &data_block->dims[i];
419+
initDimBlock(dim);
391420

392-
dims[i].data_type = data_entry->dim_types[i];
393-
dims[i].dim_n = data_entry->dims[i].size() / size_of_uda_type(dims[i].data_type);
421+
dim->data_type = data_entry->dim_types[i];
422+
dim->dim_n = data_entry->dims[i].size() / size_of_uda_type(dim->data_type);
394423

395-
log(LogLevel::INFO, "dim " + std::to_string(i) + " length: " + std::to_string(dims[i].dim_n));
424+
log(LogLevel::INFO, "dim " + std::to_string(i) + " length: " + std::to_string(dim->dim_n));
396425

397-
dims[i].dim = (char*)malloc(data_entry->dims[i].size());
398-
std::copy(data_entry->dims[i].data(), data_entry->dims[i].data() + data_entry->dims[i].size(), dims[i].dim);
426+
dim->dim = (char*)malloc(data_entry->dims[i].size());
427+
std::copy(data_entry->dims[i].begin(), data_entry->dims[i].end(), dim->dim);
399428
}
400-
data_block->dims = dims;
429+
401430
data_block->order = data_entry->order;
402431

403432
log_datablock_status(data_block, "data_block from cache");

mapping_plugin/src/uda_ram_cache.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ class UDACacheEntry : public libtokamap::CacheEntry
3737
int error_type = UDA_TYPE_UNKNOWN;
3838
};
3939

40+
void copy_to_cache(libtokamap::RamCache& ram_cache, const std::string& key, const DATA_BLOCK* data_block);
4041
bool copy_from_cache(const libtokamap::RamCache& cache, const std::string& key, DATA_BLOCK* data_block);
4142
bool copy_data_from_cache(const libtokamap::RamCache& cache, const std::string& key, DATA_BLOCK* data_block);
4243
bool copy_error_high_from_cache(const libtokamap::RamCache& cache, const std::string& key, DATA_BLOCK* data_block);

0 commit comments

Comments
 (0)