summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKunoiSayami <[email protected]>2023-05-28 16:06:33 +0800
committerKunoiSayami <[email protected]>2023-05-28 16:06:33 +0800
commit91ba3a5cc7703ae3ba37be3ad43692556177a0a7 (patch)
tree85cf1836ef7477b1b486cac89dd2cbe0809be976
parent8d98c61aa03969d064e0081a40a5c22c8e29eadf (diff)
fix(exp): Fix sample not sort
Signed-off-by: KunoiSayami <[email protected]>
-rw-r--r--expt_0525.cu33
-rw-r--r--read_helper.h9
-rw-r--r--sortlib.cuh4
3 files changed, 15 insertions, 31 deletions
diff --git a/expt_0525.cu b/expt_0525.cu
index c780c37..3c5e5c2 100644
--- a/expt_0525.cu
+++ b/expt_0525.cu
@@ -307,6 +307,7 @@ public:
__device__ bool Add(LL);
__device__ bool Delete(LL);
__device__ bool Search(LL);
+ //~LockFreeSkipList(){cudaFree()}
__device__ size_t searchIndex(key_type key) {
auto result = customSort.binary_search(this->sample, key);
@@ -314,7 +315,7 @@ public:
return index;
}
- __device__ unsigned trailing_zeroes(size_t index) {
+ static __device__ unsigned trailing_zeroes(size_t index) {
constexpr auto block_size = 2;
unsigned bits = 0;
LL x = index / block_size;
@@ -655,8 +656,7 @@ inline size_t calcBlocks(size_t input) {
int main(int argc, char **argv) {
if (argc != 4) {
- printf("Need two arguments: percent add ops and percent delete ops (e.g., "
- "30 50 for 30%% add and 50%% delete).\nAborting...\n");
+ printf("Usage %s [sample] [insertion] [search]\n", argv[0]);
exit(1);
}
@@ -673,6 +673,7 @@ int main(int argc, char **argv) {
readHelper.split_into(_sample, _population);
/*printf("%lu, Create search vector: %ld\n", _population.size(),
_population.end() - (_population.begin() + insertion_length));*/
+ rebuild(_sample);
std::vector<key_type> _search(_population.begin() + insertion_length,
_population.end());
_population.resize(insertion_length);
@@ -762,33 +763,13 @@ int main(int argc, char **argv) {
// Print kernel execution time in milliseconds
- printf("%lu: %lf", NUM_ITEMS, time);
-
- // LL *Cop2;
- // cudaMalloc((void **)&Cop2, sizeof(LL) * NUM_ITEMS);
- // cudaMemcpy(Cop2, op, sizeof(LL) * NUM_ITEMS, cudaMemcpyHostToDevice);
-
- cudaEventCreate(&start);
- cudaEventCreate(&stop);
- cudaEventRecord(start, nullptr);
- kernel<<<blocks, NUM_THREADS>>>(cudaOperatorItems, search_length, Cresult);
- CudaCheckError();
- cudaDeviceSynchronize();
- cudaEventRecord(stop, nullptr);
- cudaEventSynchronize(stop);
- cudaEventElapsedTime(&time, start, stop);
- cudaEventDestroy(start);
- cudaEventDestroy(stop);
-
- // Print kernel execution time in milliseconds
-
- printf(" %lf\n", time);
-
+ printf("%lu: %lf", search_length, time);
// Check for errors
// Move results back to host memory
- cudaMemcpy(result, Cresult, sizeof(LL) * NUM_ITEMS, cudaMemcpyDeviceToHost);
+ cudaMemcpy(result, Cresult, sizeof(LL) * search_length,
+ cudaMemcpyDeviceToHost);
// Uncomment the following for debugging
// print<<<1,32>>>();
diff --git a/read_helper.h b/read_helper.h
index 54ca77a..f12f4d9 100644
--- a/read_helper.h
+++ b/read_helper.h
@@ -14,9 +14,12 @@
#endif
#endif
+// template <typename key_type>
class ReadHelper {
typedef unsigned long long key_type;
- key_type max_value = 0, min_value = 0x7fffffffff;
+
+ key_type max_value = std::numeric_limits<key_type>::min(),
+ min_value = std::numeric_limits<key_type>::max();
char const *filename;
static constexpr size_t REVERSED_BLOCK = 256;
@@ -29,8 +32,8 @@ public:
needed_read_length(insertion_length + sample_length) {
// printf("%zu %zu\n", sample_length, needed_read_length);
}
- unsigned long long maxValue() const { return max_value; }
- unsigned long long minValue() const { return min_value; }
+ key_type maxValue() const { return max_value; }
+ key_type minValue() const { return min_value; }
std::vector<key_type> population_vector;
inline void store_into_vector(key_type value) {
diff --git a/sortlib.cuh b/sortlib.cuh
index 4c339ca..6b19d3e 100644
--- a/sortlib.cuh
+++ b/sortlib.cuh
@@ -182,9 +182,9 @@ public:
__host__ __device__ size_t length() const { return this->LENGTH; }
};
-template <typename T> void static rebuild(std::vector<T> original) {
+template <typename T> void rebuild(std::vector<T> original) {
auto sample_length = original.size();
- auto sorter = CustomSort(sample_length);
+ auto sorter = CustomSort(sample_length, sizeof(T) * 8);
auto tmp = new T[sample_length];
for (size_t i = 0; i < sample_length; i++) {