Permalink
Browse files

blech

  • Loading branch information...
1 parent c50d381 commit deaff0ae50f001d76f7f5ab196759976d91bfd20 @anirudhr anirudhr committed Apr 21, 2011
Showing with 264 additions and 7 deletions.
  1. BIN bin/bwt_timing.out
  2. +56 −0 bin/input2
  3. +84 −0 bin/input3
  4. BIN bin/mtf_timing.out
  5. +1 −1 {lib → src}/bwt.cu
  6. +110 −0 src/bwt_timing.cu
  7. +13 −6 src/mtf_timing.cu
View
Binary file not shown.
View

Large diffs are not rendered by default.

Oops, something went wrong.
View

Large diffs are not rendered by default.

Oops, something went wrong.
View
Binary file not shown.
@@ -13,7 +13,7 @@
#include <cstring>
#include <iterator>
-#include "device_string.cu"
+#include "../lib/device_string.cu"
#define POOL_SZ (10*1024*1024)
View
@@ -0,0 +1,110 @@
+#ifndef BWT_CU
+#define BWT_CU
+#include <thrust/host_vector.h>
+#include <thrust/device_vector.h>
+#include <thrust/device_ptr.h>
+#include <thrust/copy.h>
+#include <thrust/sequence.h>
+#include <thrust/sort.h>
+#include <thrust/fill.h>
+
+#include <cstdio>
+#include <iostream>
+#include <cstring>
+#include <iterator>
+#include <time.h>
+
+#include "../lib/device_string.cu"
+
+#define POOL_SZ (10*1024*1024)
+
+using namespace std;
+
+void rotate(int N, char *word, vector<string> *h_vec)
+{
+ char *str, *rot;
+ cudaMalloc((void**)&str, /*sizeof(char) * */(N + 1));
+ cudaMalloc((void**)&rot, /*sizeof(char) * */((N + 1) * (N + 1)));
+
+ thrust::device_ptr<char> strD(str);
+ thrust::device_ptr<char> rotD(rot);
+ thrust::copy(word, word + N, strD);
+
+ for (int i = 0; i < N; i++) //Rotations happen in this loop
+ {
+ thrust::copy(strD + i, strD + N, rotD + (i * N));
+ thrust::copy(strD, strD + i, rotD + (i * N) + (N - i));
+ }
+
+ for (int i = 0; i < N; i++) //We extract data back from the GPU
+ {
+ cudaMemcpy(word, rot + (i * N), N, cudaMemcpyDeviceToHost);
+ h_vec->push_back(word);
+ }
+
+ cudaFree(str);
+ cudaFree(rot);
+}
+
+void sort(vector<string> *h_vec, char *result)
+{
+ thrust::device_vector<device_string> d_vec;
+ d_vec.reserve(h_vec->size());
+
+ for(vector<std::string>::iterator iter = h_vec->begin(); iter!=h_vec->end(); ++iter)
+ {
+ device_string d_str(*iter);
+ d_vec.push_back(d_str);
+ }
+
+ thrust::sort(d_vec.begin(), d_vec.end() );
+
+ for(int i = 0; i < d_vec.size(); i++)
+ {
+ device_string d_str(d_vec[i]);
+ h_vec->at(i) = d_str;
+ result[i] = (h_vec->at(i)).at(h_vec->at(i).length() - 1);
+ }
+}
+
+void bwt( char *word)
+{
+ int N = strlen(word);
+
+ vector<string> h_vec;
+
+ rotate(N, word, &h_vec);
+
+ char *result = new char(N);
+ sort(&h_vec, result);
+// return result;
+}
+
+int main(int argc, char *argv[])
+{
+ if (argc != 2)
+ {
+ cout << "Usage: bwt.out STRING_INPUT" << endl;
+ exit(1);
+ }
+
+// char word[256];
+// strcpy(word, argv[1]);
+ int N = strlen(argv[1]);
+
+ struct timespec t0, t1;
+ struct timespec *pt0, *pt1;
+ pt0 = &t0;
+ pt1 = &t1;
+
+ clock_gettime(0, pt0);
+ bwt(argv[1]);
+ clock_gettime(0, pt1);
+
+ cout << t1.tv_nsec - t0.tv_nsec << endl;
+// cout << result << endl;
+
+ return 0;
+}
+
+#endif
View
@@ -11,6 +11,8 @@
#include <cstring>
#include <vector>
+#include<time.h>
+
using namespace std;
__global__ void fnSearch(char *str, char *key, int *res)
@@ -84,11 +86,16 @@ int main(int argc, char *argv[])
int len = strlen(argv[1]);
vector<char> word(argv[1], argv[1] + len);
- time_t begin, end;
- begin = time(NULL);
- for (int i = 0; i < 100; i++)
- mtf(word);
- end = time(NULL);
- cout <<"Time taken : " << difftime(end, begin) <<endl;
+
+ struct timespec t0, t1;
+ struct timespec *pt0, *pt1;
+ pt0 = &t0;
+ pt1 = &t1;
+
+ clock_gettime(0, pt0);
+ mtf(word);
+ clock_gettime(0, pt1);
+
+ cout << t1.tv_nsec - t0.tv_nsec << endl;
return 0;
}

0 comments on commit deaff0a

Please sign in to comment.