NVBIO
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
nvbio-test.cpp
Go to the documentation of this file.
1 /*
2  * nvbio
3  * Copyright (c) 2011-2014, NVIDIA CORPORATION. All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  * * Redistributions of source code must retain the above copyright
8  * notice, this list of conditions and the following disclaimer.
9  * * Redistributions in binary form must reproduce the above copyright
10  * notice, this list of conditions and the following disclaimer in the
11  * documentation and/or other materials provided with the distribution.
12  * * Neither the name of the NVIDIA CORPORATION nor the
13  * names of its contributors may be used to endorse or promote products
14  * derived from this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19  * DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE FOR ANY
20  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  */
27 
28 // nvbio-test.cpp
29 //
30 
31 #include <stdio.h>
32 #include <stdlib.h>
33 #include <string.h>
34 #include <nvbio/basic/types.h>
35 #include <nvbio/basic/console.h>
36 #include <cuda_runtime_api.h>
37 
38 int cache_test();
39 int packedstream_test();
40 int bwt_test();
41 int fmindex_test(int argc, char* argv[]);
42 int fastq_test(const char* filename);
43 
44 void crcInit();
45 
46 namespace nvbio {
47 
48 int alloc_test();
49 int syncblocks_test();
50 int condition_test();
51 int rank_test(int argc, char* argv[]);
52 int work_queue_test(int argc, char* argv[]);
53 int string_set_test(int argc, char* argv[]);
54 int sum_tree_test();
55 int qgram_test(int argc, char* argv[]);
56 int sequence_test(int argc, char* argv[]);
57 int wavelet_test(int argc, char* argv[]);
58 int bloom_filter_test(int argc, char* argv[]);
59 
60 namespace cuda { void scan_test(); }
61 namespace aln { void test(int argc, char* argv[]); }
62 namespace html { void test(); }
63 
64 } // namespace nvbio
65 
66 using namespace nvbio;
67 
68 enum Tests {
69  kStringSet = 1u,
70  kScan = 2u,
71  kSumTree = 16u,
72  kHTML = 32u,
73  kCache = 64u,
74  kPackedStream = 128u,
75  kBWT = 256u,
76  kFMIndex = 512u,
77  kAlloc = 1024u,
78  kSyncblocks = 2048u,
79  kCondition = 4096u,
80  kWorkQueue = 8192u,
81  kAlignment = 16384u,
82  kRank = 32768u,
83  kQGram = 65536u,
84  kSequence = 131072u,
85  kWaveletTree = 262144u,
86  kBloomFilter = 524288u,
87  kALL = 0xFFFFFFFFu
88 };
89 
90 int main(int argc, char* argv[])
91 {
92  crcInit();
93 
94  int cuda_device = -1;
95  int device_count;
96  cudaGetDeviceCount(&device_count);
97  log_verbose(stderr, " cuda devices : %d\n", device_count);
98 
99  uint32 tests = kALL;
100 
101  int arg = 1;
102  if (argc > 1)
103  {
104  if (strcmp( argv[arg], "-device" ) == 0)
105  {
106  cuda_device = atoi(argv[++arg]);
107  ++arg;
108  }
109 
110  if (arg < argc)
111  {
112  if (strcmp( argv[arg], "-string-set" ) == 0)
113  tests = kStringSet;
114  else if (strcmp( argv[arg], "-scan" ) == 0)
115  tests = kScan;
116  else if (strcmp( argv[arg], "-sum-tree" ) == 0)
117  tests = kSumTree;
118  else if (strcmp( argv[arg], "-aln" ) == 0)
119  tests = kAlignment;
120  else if (strcmp( argv[arg], "-html" ) == 0)
121  tests = kHTML;
122  else if (strcmp( argv[arg], "-cache" ) == 0)
123  tests = kCache;
124  else if (strcmp( argv[arg], "-packed-stream" ) == 0)
125  tests = kPackedStream;
126  else if (strcmp( argv[arg], "-bwt" ) == 0)
127  tests = kBWT;
128  else if (strcmp( argv[arg], "-rank" ) == 0)
129  tests = kRank;
130  else if (strcmp( argv[arg], "-fm-index" ) == 0)
131  tests = kFMIndex;
132  else if (strcmp( argv[arg], "-qgram" ) == 0)
133  tests = kQGram;
134  else if (strcmp( argv[arg], "-alloc" ) == 0)
135  tests = kAlloc;
136  else if (strcmp( argv[arg], "-syncblocks" ) == 0)
137  tests = kSyncblocks;
138  else if (strcmp( argv[arg], "-condition" ) == 0)
139  tests = kCondition;
140  else if (strcmp( argv[arg], "-work-queue" ) == 0)
141  tests = kWorkQueue;
142  else if (strcmp( argv[arg], "-sequence" ) == 0)
143  tests = kSequence;
144  else if (strcmp( argv[arg], "-wavelet" ) == 0)
145  tests = kWaveletTree;
146  else if (strcmp( argv[arg], "-bloom-filter" ) == 0)
147  tests = kBloomFilter;
148 
149  ++arg;
150  }
151  }
152 
153  // inspect and select cuda devices
154  if (device_count)
155  {
156  if (cuda_device == -1)
157  {
158  int best_device = 0;
159  cudaDeviceProp best_device_prop;
160  cudaGetDeviceProperties( &best_device_prop, best_device );
161 
162  for (int device = 0; device < device_count; ++device)
163  {
164  cudaDeviceProp device_prop;
165  cudaGetDeviceProperties( &device_prop, device );
166  log_verbose(stderr, " device %d has compute capability %d.%d\n", device, device_prop.major, device_prop.minor);
167  log_verbose(stderr, " SM count : %u\n", device_prop.multiProcessorCount);
168  log_verbose(stderr, " SM clock rate : %u Mhz\n", device_prop.clockRate / 1000);
169  log_verbose(stderr, " memory clock rate : %.1f Ghz\n", float(device_prop.memoryClockRate) * 1.0e-6f);
170 
171  if (device_prop.major >= best_device_prop.major &&
172  device_prop.minor >= best_device_prop.minor)
173  {
174  best_device_prop = device_prop;
175  best_device = device;
176  }
177  }
178  cuda_device = best_device;
179  }
180  log_verbose(stderr, " chosen device %d\n", cuda_device);
181  {
182  cudaDeviceProp device_prop;
183  cudaGetDeviceProperties( &device_prop, cuda_device );
184  log_verbose(stderr, " device name : %s\n", device_prop.name);
185  log_verbose(stderr, " compute capability : %d.%d\n", device_prop.major, device_prop.minor);
186  }
187  cudaSetDevice( cuda_device );
188  }
189 
190  // allocate some heap
191  cudaDeviceSetLimit( cudaLimitMallocHeapSize, 128*1024*1024 );
192 
193  argc = argc >= arg ? argc-arg : 0;
194 
195  if (tests & kAlloc) alloc_test();
196  if (tests & kSyncblocks) syncblocks_test();
197  if (tests & kCondition) condition_test();
198  if (tests & kWorkQueue) work_queue_test( argc, argv+arg );
199  if (tests & kStringSet) string_set_test( argc, argv+arg );
200  if (tests & kScan) cuda::scan_test();
201  if (tests & kAlignment) aln::test( argc, argv+arg );
202  if (tests & kSumTree) sum_tree_test();
203  if (tests & kHTML) html::test();
204  if (tests & kCache) cache_test();
205  if (tests & kPackedStream) packedstream_test();
206  if (tests & kBWT) bwt_test();
207  if (tests & kRank) rank_test( argc, argv+arg );
208  if (tests & kFMIndex) fmindex_test( argc, argv+arg );
209  if (tests & kQGram) qgram_test( argc, argv+arg );
210  if (tests & kSequence) sequence_test( argc, argv+arg );
211  if (tests & kWaveletTree) wavelet_test( argc, argv+arg );
212  if (tests & kBloomFilter) bloom_filter_test( argc, argv+arg );
213 
214  cudaDeviceReset();
215  return 0;
216 }
217