Commit 39465dd7 authored by Youyun Wang's avatar Youyun Wang
Browse files

rename files

parent c398dcc8
......@@ -45,7 +45,7 @@ set(JEMALLOC_DIR "/usr/lib/x86_64-linux-gnu")
## Build and Run
We use CMake to build XIndex.
We use CMake to build SIndex.
```shell
$ cmake . -DCMAKE_BUILD_TYPE=Release # or -DCMAKE_BUILD_TYPE=Debug for more debug information
......@@ -58,7 +58,7 @@ To run the microbenchmark:
$ ./microbench
```
The [microbench](microbench.cpp) has several parameters you can pass, such as `read/write ratio`, `table size` and configurations of XIndex.
The [microbench](microbench.cpp) has several parameters you can pass, such as `read/write ratio`, `table size` and configurations of SIndex.
```shell
$ ./microbench --read 0.9 --insert 0.05 --remove 0.05 --table-size 100000
......
......@@ -31,8 +31,8 @@
#include <vector>
#include "helper.h"
#include "xindex.h"
#include "xindex_impl.h"
#include "sindex.h"
#include "sindex_impl.h"
struct alignas(CACHELINE_SIZE) FGParam;
template <size_t len>
......@@ -40,11 +40,11 @@ class StrKey;
typedef FGParam fg_param_t;
typedef StrKey<64> index_key_t;
typedef xindex::XIndex<index_key_t, uint64_t> xindex_t;
typedef sindex::SIndex<index_key_t, uint64_t> sindex_t;
inline void prepare_xindex(xindex_t *&table);
inline void prepare_sindex(sindex_t *&table);
void run_benchmark(xindex_t *table, size_t sec);
void run_benchmark(sindex_t *table, size_t sec);
void *run_fg(void *param);
......@@ -67,7 +67,7 @@ std::vector<index_key_t> exist_keys;
std::vector<index_key_t> non_exist_keys;
struct alignas(CACHELINE_SIZE) FGParam {
xindex_t *table;
sindex_t *table;
uint64_t throughput;
uint32_t thread_id;
};
......@@ -153,13 +153,13 @@ class StrKey {
int main(int argc, char **argv) {
parse_args(argc, argv);
xindex_t *tab_xi;
prepare_xindex(tab_xi);
sindex_t *tab_xi;
prepare_sindex(tab_xi);
run_benchmark(tab_xi, runtime);
if (tab_xi != nullptr) delete tab_xi;
}
inline void prepare_xindex(xindex_t *&table) {
inline void prepare_sindex(sindex_t *&table) {
// prepare data
std::random_device rd;
std::mt19937 gen(rd());
......@@ -189,16 +189,16 @@ inline void prepare_xindex(xindex_t *&table) {
COUT_VAR(exist_keys.size());
COUT_VAR(non_exist_keys.size());
// initilize XIndex (sort keys first)
// initilize SIndex (sort keys first)
std::sort(exist_keys.begin(), exist_keys.end());
std::vector<uint64_t> vals(exist_keys.size(), 1);
table = new xindex_t(exist_keys, vals, fg_n, bg_n);
table = new sindex_t(exist_keys, vals, fg_n, bg_n);
}
void *run_fg(void *param) {
fg_param_t &thread_param = *(fg_param_t *)param;
uint32_t thread_id = thread_param.thread_id;
xindex_t *table = thread_param.table;
sindex_t *table = thread_param.table;
std::random_device rd;
std::mt19937 gen(rd());
......@@ -273,7 +273,7 @@ void *run_fg(void *param) {
pthread_exit(nullptr);
}
void run_benchmark(xindex_t *table, size_t sec) {
void run_benchmark(sindex_t *table, size_t sec) {
pthread_t threads[fg_n];
fg_param_t fg_params[fg_n];
// check if parameters are cacheline aligned
......@@ -339,17 +339,17 @@ inline void parse_args(int argc, char **argv) {
{"runtime", required_argument, 0, 'g'},
{"fg", required_argument, 0, 'h'},
{"bg", required_argument, 0, 'i'},
{"xindex-root-err-bound", required_argument, 0, 'j'},
{"xindex-root-memory", required_argument, 0, 'k'},
{"xindex-group-err-bound", required_argument, 0, 'l'},
{"xindex-group-err-tolerance", required_argument, 0, 'm'},
{"xindex-buf-size-bound", required_argument, 0, 'n'},
{"xindex-buf-compact-threshold", required_argument, 0, 'o'},
{"xindex-partial-len", required_argument, 0, 'p'},
{"xindex-forward-step", required_argument, 0, 'q'},
{"xindex-backward-step", required_argument, 0, 'r'},
{"sindex-root-err-bound", required_argument, 0, 'j'},
{"sindex-root-memory", required_argument, 0, 'k'},
{"sindex-group-err-bound", required_argument, 0, 'l'},
{"sindex-group-err-tolerance", required_argument, 0, 'm'},
{"sindex-buf-size-bound", required_argument, 0, 'n'},
{"sindex-buf-compact-threshold", required_argument, 0, 'o'},
{"sindex-partial-len", required_argument, 0, 'p'},
{"sindex-forward-step", required_argument, 0, 'q'},
{"sindex-backward-step", required_argument, 0, 'r'},
{0, 0, 0, 0}};
std::string ops = "a:b:c:d:e:f:g:h:i:j:k:l:m:n:o:";
std::string ops = "a:b:c:d:e:f:g:h:i:j:k:l:m:n:o:p:q:r:";
int option_index = 0;
while (1) {
......@@ -397,41 +397,41 @@ inline void parse_args(int argc, char **argv) {
bg_n = strtoul(optarg, NULL, 10);
break;
case 'j':
xindex::config.root_error_bound = strtol(optarg, NULL, 10);
INVARIANT(xindex::config.root_error_bound > 0);
sindex::config.root_error_bound = strtol(optarg, NULL, 10);
INVARIANT(sindex::config.root_error_bound > 0);
break;
case 'k':
xindex::config.root_memory_constraint =
sindex::config.root_memory_constraint =
strtol(optarg, NULL, 10) * 1024 * 1024;
INVARIANT(xindex::config.root_memory_constraint > 0);
INVARIANT(sindex::config.root_memory_constraint > 0);
break;
case 'l':
xindex::config.group_error_bound = strtol(optarg, NULL, 10);
INVARIANT(xindex::config.group_error_bound > 0);
sindex::config.group_error_bound = strtol(optarg, NULL, 10);
INVARIANT(sindex::config.group_error_bound > 0);
break;
case 'm':
xindex::config.group_error_tolerance = strtol(optarg, NULL, 10);
INVARIANT(xindex::config.group_error_tolerance > 0);
sindex::config.group_error_tolerance = strtol(optarg, NULL, 10);
INVARIANT(sindex::config.group_error_tolerance > 0);
break;
case 'n':
xindex::config.buffer_size_bound = strtol(optarg, NULL, 10);
INVARIANT(xindex::config.buffer_size_bound > 0);
sindex::config.buffer_size_bound = strtol(optarg, NULL, 10);
INVARIANT(sindex::config.buffer_size_bound > 0);
break;
case 'o':
xindex::config.buffer_compact_threshold = strtol(optarg, NULL, 10);
INVARIANT(xindex::config.buffer_compact_threshold > 0);
sindex::config.buffer_compact_threshold = strtol(optarg, NULL, 10);
INVARIANT(sindex::config.buffer_compact_threshold > 0);
break;
case 'p':
xindex::config.partial_len_bound = strtol(optarg, NULL, 10);
INVARIANT(xindex::config.partial_len_bound > 0);
sindex::config.partial_len_bound = strtol(optarg, NULL, 10);
INVARIANT(sindex::config.partial_len_bound > 0);
break;
case 'q':
xindex::config.forward_step = strtol(optarg, NULL, 10);
INVARIANT(xindex::config.forward_step > 0);
sindex::config.forward_step = strtol(optarg, NULL, 10);
INVARIANT(sindex::config.forward_step > 0);
break;
case 'r':
xindex::config.backward_step = strtol(optarg, NULL, 10);
INVARIANT(xindex::config.backward_step > 0);
sindex::config.backward_step = strtol(optarg, NULL, 10);
INVARIANT(sindex::config.backward_step > 0);
break;
default:
......@@ -448,14 +448,14 @@ inline void parse_args(int argc, char **argv) {
COUT_VAR(runtime);
COUT_VAR(fg_n);
COUT_VAR(bg_n);
COUT_VAR(xindex::config.root_error_bound);
COUT_VAR(xindex::config.root_memory_constraint);
COUT_VAR(xindex::config.group_error_bound);
COUT_VAR(xindex::config.group_error_tolerance);
COUT_VAR(xindex::config.buffer_size_bound);
COUT_VAR(xindex::config.buffer_size_tolerance);
COUT_VAR(xindex::config.buffer_compact_threshold);
COUT_VAR(xindex::config.partial_len_bound);
COUT_VAR(xindex::config.forward_step);
COUT_VAR(xindex::config.backward_step);
COUT_VAR(sindex::config.root_error_bound);
COUT_VAR(sindex::config.root_memory_constraint);
COUT_VAR(sindex::config.group_error_bound);
COUT_VAR(sindex::config.group_error_tolerance);
COUT_VAR(sindex::config.buffer_size_bound);
COUT_VAR(sindex::config.buffer_size_tolerance);
COUT_VAR(sindex::config.buffer_compact_threshold);
COUT_VAR(sindex::config.partial_len_bound);
COUT_VAR(sindex::config.forward_step);
COUT_VAR(sindex::config.backward_step);
}
......@@ -19,27 +19,27 @@
*/
#include "helper.h"
#include "xindex_buffer.h"
#include "xindex_group.h"
#include "xindex_model.h"
#include "xindex_root.h"
#include "xindex_util.h"
#include "sindex_buffer.h"
#include "sindex_group.h"
#include "sindex_model.h"
#include "sindex_root.h"
#include "sindex_util.h"
#if !defined(XINDEX_H)
#define XINDEX_H
#if !defined(SINDEX_H)
#define SINDEX_H
namespace xindex {
namespace sindex {
template <class key_t, class val_t, bool seq = false>
class XIndex {
class SIndex {
typedef Group<key_t, val_t, seq> group_t;
typedef Root<key_t, val_t, seq> root_t;
typedef void iterator_t;
public:
XIndex(const std::vector<key_t> &keys, const std::vector<val_t> &vals,
SIndex(const std::vector<key_t> &keys, const std::vector<val_t> &vals,
size_t worker_num, size_t bg_n);
~XIndex();
~SIndex();
inline bool get(const key_t &key, val_t &val, const uint32_t worker_id);
inline bool put(const key_t &key, const val_t &val, const uint32_t worker_id);
......@@ -63,6 +63,6 @@ class XIndex {
volatile bool bg_running = true;
};
} // namespace xindex
} // namespace sindex
#endif // XINDEX_H
#endif // SINDEX_H
......@@ -18,12 +18,12 @@
*
*/
#include "xindex_util.h"
#include "sindex_util.h"
#if !defined(XINDEX_BUFFER_H)
#define XINDEX_BUFFER_H
#if !defined(SINDEX_BUFFER_H)
#define SINDEX_BUFFER_H
namespace xindex {
namespace sindex {
const uint8_t alt_buf_fanout = 16;
const uint8_t node_capacity = alt_buf_fanout - 1;
......@@ -169,6 +169,6 @@ class AltBtreeBuffer {
static const size_t node_size = std::max(sizeof(leaf_t), sizeof(internal_t));
};
} // namespace xindex
} // namespace sindex
#endif // XINDEX_BUFFER_H
#endif // SINDEX_BUFFER_H
......@@ -22,12 +22,12 @@
#include <mutex>
#include <vector>
#include "xindex_buffer.h"
#include "sindex_buffer.h"
#if !defined(XINDEX_BUFFER_ALT_IMPL_H)
#define XINDEX_BUFFER_ALT_IMPL_H
#if !defined(SINDEX_BUFFER_ALT_IMPL_H)
#define SINDEX_BUFFER_ALT_IMPL_H
namespace xindex {
namespace sindex {
template <class key_t, class val_t>
AltBtreeBuffer<key_t, val_t>::AltBtreeBuffer() {
......@@ -848,6 +848,6 @@ AltBtreeBuffer<key_t, val_t>::RefSource::get_val() {
return *(val_ptrs[pos]);
}
} // namespace xindex
} // namespace sindex
#endif // XINDEX_BUFFER_IMPL_H
#endif // SINDEX_BUFFER_IMPL_H
......@@ -16,18 +16,16 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more about XIndex, visit:
* https://ppopp20.sigplan.org/details/PPoPP-2020-papers/13/XIndex-A-Scalable-Learned-Index-for-Multicore-Data-Storage
*/
#include "xindex_buffer.h"
#include "xindex_model.h"
#include "xindex_util.h"
#include "sindex_buffer.h"
#include "sindex_model.h"
#include "sindex_util.h"
#if !defined(XINDEX_GROUP_H)
#define XINDEX_GROUP_H
#if !defined(SINDEX_GROUP_H)
#define SINDEX_GROUP_H
namespace xindex {
namespace sindex {
template <class key_t, class val_t, bool seq, size_t max_model_n = 4>
class alignas(CACHELINE_SIZE) Group {
......@@ -38,7 +36,7 @@ class alignas(CACHELINE_SIZE) Group {
typedef std::pair<key_t, wrapped_val_t> record_t;
template <class key_tt, class val_tt, bool sequential>
friend class XIndex;
friend class SIndex;
template <class key_tt, class val_tt, bool sequential>
friend class Root;
......@@ -193,6 +191,6 @@ class alignas(CACHELINE_SIZE) Group {
model_info;
};
} // namespace xindex
} // namespace sindex
#endif // XINDEX_GROUP_H
#endif // SINDEX_GROUP_H
......@@ -18,13 +18,13 @@
*
*/
#include "xindex_group.h"
#include "sindex_group.h"
#include <climits>
#if !defined(XINDEX_GROUP_IMPL_H)
#define XINDEX_GROUP_IMPL_H
#if !defined(SINDEX_GROUP_IMPL_H)
#define SINDEX_GROUP_IMPL_H
namespace xindex {
namespace sindex {
template <class key_t, class val_t, bool seq, size_t max_model_n>
Group<key_t, val_t, seq, max_model_n>::Group() {}
......@@ -1313,6 +1313,6 @@ Group<key_t, val_t, seq, max_model_n>::ArrayRefSource::get_val() {
return *next_val_ptr;
}
} // namespace xindex
} // namespace sindex
#endif // XINDEX_GROUP_IMPL_H
#endif // SINDEX_GROUP_IMPL_H
......@@ -18,19 +18,19 @@
*
*/
#include "xindex.h"
#include "xindex_buffer_impl.h"
#include "xindex_group_impl.h"
#include "xindex_model.h"
#include "xindex_root_impl.h"
#include "sindex.h"
#include "sindex_buffer_impl.h"
#include "sindex_group_impl.h"
#include "sindex_model.h"
#include "sindex_root_impl.h"
#if !defined(XINDEX_IMPL_H)
#define XINDEX_IMPL_H
#if !defined(SINDEX_IMPL_H)
#define SINDEX_IMPL_H
namespace xindex {
namespace sindex {
template <class key_t, class val_t, bool seq>
XIndex<key_t, val_t, seq>::XIndex(const std::vector<key_t> &keys,
SIndex<key_t, val_t, seq>::SIndex(const std::vector<key_t> &keys,
const std::vector<val_t> &vals,
size_t worker_num, size_t bg_n)
: bg_num(bg_n) {
......@@ -57,19 +57,19 @@ XIndex<key_t, val_t, seq>::XIndex(const std::vector<key_t> &keys,
}
template <class key_t, class val_t, bool seq>
XIndex<key_t, val_t, seq>::~XIndex() {
SIndex<key_t, val_t, seq>::~SIndex() {
terminate_bg();
}
template <class key_t, class val_t, bool seq>
inline bool XIndex<key_t, val_t, seq>::get(const key_t &key, val_t &val,
inline bool SIndex<key_t, val_t, seq>::get(const key_t &key, val_t &val,
const uint32_t worker_id) {
rcu_progress(worker_id);
return root->get(key, val) == result_t::ok;
}
template <class key_t, class val_t, bool seq>
inline bool XIndex<key_t, val_t, seq>::put(const key_t &key, const val_t &val,
inline bool SIndex<key_t, val_t, seq>::put(const key_t &key, const val_t &val,
const uint32_t worker_id) {
result_t res;
rcu_progress(worker_id);
......@@ -80,14 +80,14 @@ inline bool XIndex<key_t, val_t, seq>::put(const key_t &key, const val_t &val,
}
template <class key_t, class val_t, bool seq>
inline bool XIndex<key_t, val_t, seq>::remove(const key_t &key,
inline bool SIndex<key_t, val_t, seq>::remove(const key_t &key,
const uint32_t worker_id) {
rcu_progress(worker_id);
return root->remove(key) == result_t::ok;
}
template <class key_t, class val_t, bool seq>
inline size_t XIndex<key_t, val_t, seq>::scan(
inline size_t SIndex<key_t, val_t, seq>::scan(
const key_t &begin, const size_t n,
std::vector<std::pair<key_t, val_t>> &result, const uint32_t worker_id) {
rcu_progress(worker_id);
......@@ -95,7 +95,7 @@ inline size_t XIndex<key_t, val_t, seq>::scan(
}
template <class key_t, class val_t, bool seq>
size_t XIndex<key_t, val_t, seq>::range_scan(
size_t SIndex<key_t, val_t, seq>::range_scan(
const key_t &begin, const key_t &end,
std::vector<std::pair<key_t, val_t>> &result, const uint32_t worker_id) {
rcu_progress(worker_id);
......@@ -103,8 +103,8 @@ size_t XIndex<key_t, val_t, seq>::range_scan(
}
template <class key_t, class val_t, bool seq>
void *XIndex<key_t, val_t, seq>::background(void *this_) {
volatile XIndex &index = *(XIndex *)this_;
void *SIndex<key_t, val_t, seq>::background(void *this_) {
volatile SIndex &index = *(SIndex *)this_;
if (index.bg_num == 0) return nullptr;
size_t bg_num = index.bg_num;
......@@ -204,7 +204,7 @@ void *XIndex<key_t, val_t, seq>::background(void *this_) {
}
template <class key_t, class val_t, bool seq>
void XIndex<key_t, val_t, seq>::start_bg() {
void SIndex<key_t, val_t, seq>::start_bg() {
bg_running = true;
int ret = pthread_create(&bg_master, nullptr, background, this);
if (ret) {
......@@ -213,11 +213,11 @@ void XIndex<key_t, val_t, seq>::start_bg() {
}
template <class key_t, class val_t, bool seq>
void XIndex<key_t, val_t, seq>::terminate_bg() {
void SIndex<key_t, val_t, seq>::terminate_bg() {
config.exited = true;
bg_running = false;
}
} // namespace xindex
} // namespace sindex
#endif // XINDEX_IMPL_H
#endif // SINDEX_IMPL_H
......@@ -21,10 +21,10 @@
#include "mkl.h"
#include "mkl_lapacke.h"
#if !defined(XINDEX_MODEL_H)
#define XINDEX_MODEL_H
#if !defined(SINDEX_MODEL_H)
#define SINDEX_MODEL_H
namespace xindex {
namespace sindex {
static const size_t DESIRED_TRAINING_KEY_N = 10000000;
......@@ -128,6 +128,6 @@ inline size_t model_predict(double *weights, const double *model_key,
}
}
} // namespace xindex
} // namespace sindex
#endif // XINDEX_MODEL_H
#endif // SINDEX_MODEL_H
......@@ -18,13 +18,13 @@
*
*/
#include "xindex_group.h"
#include "sindex_group.h"
#include <unordered_map>
#if !defined(XINDEX_ROOT_H)
#define XINDEX_ROOT_H
#if !defined(SINDEX_ROOT_H)
#define SINDEX_ROOT_H
namespace xindex {
namespace sindex {
template <class key_t, class val_t, bool seq>
class Root {
......@@ -33,7 +33,7 @@ class Root {
typedef PartialModelMeta model_meta_t;
template <class key_tt, class val_tt, bool sequential>
friend class XIndex;
friend class SIndex;
struct PartialModelMeta {
uint32_t p_len;
......@@ -99,6 +99,6 @@ class Root {
std::array<model_meta_t, max_root_model_n> models;
};
} // namespace xindex
} // namespace sindex
#endif // XINDEX_ROOT_H
#endif // SINDEX_ROOT_H
......@@ -19,12 +19,12 @@
*/
#include <unordered_map>
#include "xindex_root.h"
#include "sindex_root.h"
#if !defined(XINDEX_ROOT_IMPL_H)
#define XINDEX_ROOT_IMPL_H
#if !defined(SINDEX_ROOT_IMPL_H)
#define SINDEX_ROOT_IMPL_H
namespace xindex {
namespace sindex {
template <class key_t, class val_t, bool seq>
Root<key_t, val_t, seq>::~Root() {}
......@@ -75,16 +75,16 @@ void Root<key_t, val_t, seq>::init(const std::vector<key_t> &keys,
// then decide # of 2nd stage model of root RMI
adjust_root_model();
DEBUG_THIS("------ Final XIndex Paramater: group_n="
DEBUG_THIS("------ Final SIndex Paramater: group_n="
<< group_n << ", avg_group_size=" << keys.size() / group_n
<< ", feature_begin_i=" << feature_begin_i
<< ", max_feature_len=" << max_feature_len);
DEBUG_THIS("------ Final XIndex Errors: max_error="
DEBUG_THIS("------ Final SIndex Errors: max_error="
<< max_group_error
<< ", avg_group_error=" << avg_group_error / group_n
<< ", avg_prefix_len=" << avg_prefix_len / group_n
<< ", avg_feature_len=" << avg_feature_len / group_n);
DEBUG_THIS("------ Final XIndex Memory: sizeof(root)="
DEBUG_THIS("------ Final SIndex Memory: sizeof(root)="
<< sizeof(*this) << ", sizeof(group_t)=" << sizeof(group_t)
<< ", sizeof(group_t::record_t)="
<< sizeof(typename group_t::record_t)
......@@ -411,7 +411,7 @@ void Root<key_t, val_t, seq>::adjust_root_model() {
double mean_error =
std::accumulate(errors.begin(), errors.end(), 0.0) / errors.size();
DEBUG_THIS("------ Final XIndex Root Piecewise Model: model_n="
DEBUG_THIS("------ Final SIndex Root Piecewise Model: model_n="
<< this->root_model_n << ", error=" << mean_error);
}
......@@ -467,7 +467,7 @@ inline void Root<key_t, val_t, seq>::train_piecewise_model() {
model_pivots[m_i] = get_group_ptr(b_i)->pivot;
partial_key_len_of_pivots(b_i, e_i, p_len, f_len);
size_t m_size = e_i - b_i;
DEBUG_THIS("------ XIndex Root Model(" << m_i << "): size=" << m_size
DEBUG_THIS("------ SIndex Root Model(" << m_i << "): size=" << m_size
<< ", p_len=" << p_len
<< ", f_len=" << f_len);
std::vector<double> m_keys(m_size * f_len);
......@@ -787,6 +787,6 @@ inline double Root<key_t, val_t, seq>::train_and_get_err(
return errors / key_n;
}
} // namespace xindex
} // namespace sindex
#endif // XINDEX_ROOT_IMPL_H
#endif // SINDEX_ROOT_IMPL_H
......@@ -24,10 +24,10 @@
#include <memory>
#include <mutex>
#if !defined(XINDEX_UTIL_H)
#define XINDEX_UTIL_H
#if !defined(SINDEX_UTIL_H)
#define SINDEX_UTIL_H
namespace xindex {