Skip to content

Commit 71f6416

Browse files
authored
[Fix]: Compiling LRB, GL and 3L Cache on macOS (#280)
* Fix the compilation of LRB on macOS * Fix the compilation of GLCache on macOS * Fix the compilation of 3L Cache * Clean up * Revert README
1 parent 2868881 commit 71f6416

9 files changed

Lines changed: 37 additions & 34 deletions

File tree

libCacheSim/cache/eviction/3LCache/ThreeLCache.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -382,14 +382,13 @@ pair<uint64_t, int32_t> ThreeLCacheCache::evict_predobj() {
382382

383383
void ThreeLCacheCache::prediction(vector<int32_t> sampled_objects) {
384384
int32_t sample_nums = sampled_objects.size();
385-
int32_t indptr[sample_nums + 1];
386-
indptr[0] = 0;
387-
int32_t indices[sample_nums * n_feature];
388-
double data[sample_nums * n_feature];
389-
int32_t past_timestamps[sample_nums];
390-
int32_t sizes[sample_nums];
391-
uint64_t keys[sample_nums];
392-
int32_t poses[sample_nums];
385+
std::vector<int32_t> indptr(sample_nums + 1, 0);
386+
std::vector<int32_t> indices(sample_nums * n_feature);
387+
std::vector<double> data(sample_nums * n_feature);
388+
std::vector<int32_t> past_timestamps(sample_nums);
389+
std::vector<int32_t> sizes(sample_nums);
390+
std::vector<uint64_t> keys(sample_nums);
391+
std::vector<int32_t> poses(sample_nums);
393392
unsigned int idx_feature = 0;
394393
int32_t pos;
395394
unsigned int idx_row = 0;
@@ -430,18 +429,19 @@ void ThreeLCacheCache::prediction(vector<int32_t> sampled_objects) {
430429
indptr[idx_row + 1] = idx_feature;
431430
}
432431
int64_t len = 0;
433-
double scores[sample_nums];
432+
std::vector<double> scores(sample_nums);
434433
std::string inference_params_str;
435434
for (const auto &param : inference_params) {
436435
inference_params_str += param.first + "=" + param.second + " ";
437436
}
438437
inference_params_str.pop_back(); // Remove trailing space
439438
const char *inference_params_cstr = inference_params_str.c_str();
440439
LGBM_BoosterPredictForCSR(
441-
booster, static_cast<void *>(indptr), C_API_DTYPE_INT32, indices,
442-
static_cast<void *>(data), C_API_DTYPE_FLOAT64, idx_row + 1, idx_feature,
440+
booster, static_cast<void *>(indptr.data()), C_API_DTYPE_INT32,
441+
indices.data(), static_cast<void *>(data.data()), C_API_DTYPE_FLOAT64,
442+
idx_row + 1, idx_feature,
443443
n_feature, // remove future t
444-
C_API_PREDICT_NORMAL, 0, 0, inference_params_cstr, &len, scores);
444+
C_API_PREDICT_NORMAL, 0, 0, inference_params_cstr, &len, scores.data());
445445
float _distance;
446446
if (objective == byte_miss_ratio) {
447447
for (int i = 0; i < sample_nums; ++i) {

libCacheSim/cache/eviction/3LCache/ThreeLCache.hpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -388,9 +388,11 @@ class ThreeLCacheCache : public webcachesim::Cache {
388388

389389
void update_stat_periodic() override;
390390

391-
void setSize(const uint64_t &cs) { _cacheSize = cs; }
391+
void setSize(const uint64_t &cs) override { _cacheSize = cs; }
392392

393-
bool exist(const int64_t &key) { return key_map.find(key) != key_map.end(); }
393+
bool exist(const int64_t &key) override {
394+
return key_map.find(key) != key_map.end();
395+
}
394396

395397
pair<uint64_t, int32_t> evict_predobj();
396398

libCacheSim/cache/eviction/3LCache/cache.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ class Cache {
6969
std::cerr << "unknown cacheType" << std::endl;
7070
return nullptr;
7171
}
72-
Cache_instance = std::move(get_factory_instance()[name]->create_unique());
72+
Cache_instance = get_factory_instance()[name]->create_unique();
7373
return Cache_instance;
7474
}
7575

libCacheSim/cache/eviction/GLCache/GLCache.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -446,9 +446,10 @@ static void GLCache_evict(cache_t *cache, const request_t *req) {
446446
if (params->curr_rtime - last_print_time > 3600 * 6) {
447447
last_print_time = params->curr_rtime;
448448
WARN(
449-
"%.2lf hour, cache size %lu MB, %d segs, evicting and cannot merge\n",
450-
(double)params->curr_rtime / 3600.0, cache->cache_size / 1024 / 1024,
451-
params->n_in_use_segs);
449+
"%.2lf hour, cache size %lld MB, %d segs, evicting and cannot "
450+
"merge\n",
451+
(double)params->curr_rtime / 3600.0,
452+
(long long)(cache->cache_size / 1024 / 1024), params->n_in_use_segs);
452453
}
453454

454455
evict_one_seg(cache, params->obj_sel.segs_to_evict[0]);

libCacheSim/cache/eviction/GLCache/README

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,3 @@ to evict/write `cache_size`' bytes.
5858

5959

6060

61-

libCacheSim/cache/eviction/GLCache/train.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88

99
static void debug_print_feature_matrix(const DMatrixHandle handle,
1010
int print_n_row) {
11-
unsigned long out_len;
11+
bst_ulong out_len;
1212
const float *out_data;
1313
XGDMatrixGetFloatInfo(handle, "label", &out_len, &out_data);
1414

15-
printf("out_len: %lu\n", out_len);
15+
printf("out_len: %llu\n", (unsigned long long)out_len);
1616
for (int i = 0; i < print_n_row; i++) {
1717
printf("%.4f, ", out_data[i]);
1818
}

libCacheSim/cache/eviction/LRB/cache.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ class Cache {
6969
std::cerr << "unknown cacheType" << std::endl;
7070
return nullptr;
7171
}
72-
Cache_instance = std::move(get_factory_instance()[name]->create_unique());
72+
Cache_instance = get_factory_instance()[name]->create_unique();
7373
return Cache_instance;
7474
}
7575

libCacheSim/cache/eviction/LRB/lrb.cpp

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -284,16 +284,16 @@ pair<uint64_t, uint32_t> LRBCache::rank() {
284284
}
285285
}
286286

287-
int32_t indptr[sample_rate + 1];
287+
std::vector<int32_t> indptr(sample_rate + 1);
288288
indptr[0] = 0;
289-
int32_t indices[sample_rate * n_feature];
290-
double data[sample_rate * n_feature];
291-
int32_t past_timestamps[sample_rate];
292-
uint64_t sizes[sample_rate];
289+
std::vector<int32_t> indices(sample_rate * n_feature);
290+
std::vector<double> data(sample_rate * n_feature);
291+
std::vector<int32_t> past_timestamps(sample_rate);
292+
std::vector<uint64_t> sizes(sample_rate);
293293

294294
unordered_set<uint64_t> key_set;
295-
uint64_t keys[sample_rate];
296-
uint32_t poses[sample_rate];
295+
std::vector<uint64_t> keys(sample_rate);
296+
std::vector<uint32_t> poses(sample_rate);
297297
// next_past_timestamp, next_size = next_indptr - 1
298298

299299
unsigned int idx_feature = 0;
@@ -365,16 +365,17 @@ pair<uint64_t, uint32_t> LRBCache::rank() {
365365
}
366366

367367
int64_t len;
368-
double scores[sample_rate];
368+
std::vector<double> scores(sample_rate);
369369
system_clock::time_point timeBegin;
370370
// sample to measure inference time
371371
if (!(current_seq % 10000)) timeBegin = chrono::system_clock::now();
372372
LGBM_BoosterPredictForCSR(
373-
booster, static_cast<void *>(indptr), C_API_DTYPE_INT32, indices,
374-
static_cast<void *>(data), C_API_DTYPE_FLOAT64, idx_row + 1, idx_feature,
373+
booster, static_cast<void *>(indptr.data()), C_API_DTYPE_INT32,
374+
indices.data(), static_cast<void *>(data.data()), C_API_DTYPE_FLOAT64,
375+
idx_row + 1, idx_feature,
375376
n_feature, // remove future t
376377
C_API_PREDICT_NORMAL, 0, atoi(training_params["num_iterations"].c_str()),
377-
map_to_string(inference_params).c_str(), &len, scores);
378+
map_to_string(inference_params).c_str(), &len, scores.data());
378379
if (!(current_seq % 10000))
379380
inference_time = 0.95 * inference_time +
380381
0.05 * chrono::duration_cast<chrono::microseconds>(

libCacheSim/cache/eviction/LRB/lrb.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@ class LRBCache : public Cache {
433433
void remove_from_outcache_metas(Meta &meta, unsigned int &pos,
434434
const uint64_t &key);
435435

436-
bool has(const uint64_t &id) {
436+
bool has(const uint64_t &id) override {
437437
auto it = key_map.find(id);
438438
if (it == key_map.end()) return false;
439439
return !it->second.list_idx;

0 commit comments

Comments
 (0)