alignment_test.cu 44 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199
  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. // alignment_test.cu
  28. //
  29. #include <nvbio-test/alignment_test_utils.h>
  30. #include <nvbio/basic/timer.h>
  31. #include <nvbio/basic/console.h>
  32. #include <nvbio/basic/cuda/ldg.h>
  33. #include <nvbio/basic/cached_iterator.h>
  34. #include <nvbio/basic/packedstream.h>
  35. #include <nvbio/basic/packedstream_loader.h>
  36. #include <nvbio/basic/vector_view.h>
  37. #include <nvbio/basic/vector.h>
  38. #include <nvbio/basic/shared_pointer.h>
  39. #include <nvbio/basic/dna.h>
  40. #include <nvbio/alignment/alignment.h>
  41. #include <nvbio/alignment/batched.h>
  42. #include <nvbio/alignment/sink.h>
  43. #include <thrust/device_vector.h>
  44. #include <stdio.h>
  45. #include <stdlib.h>
  46. #include <vector>
  47. #include <algorithm>
  48. using namespace nvbio;
  49. namespace nvbio {
  50. namespace aln {
  51. enum { CACHE_SIZE = 32 };
  52. typedef nvbio::lmem_cache_tag<CACHE_SIZE> lmem_cache_tag_type;
  53. typedef nvbio::uncached_tag uncached_tag_type;
  54. //
  55. // An alignment stream class to be used in conjunction with the BatchAlignmentScore class
  56. //
  57. template <typename t_aligner_type, uint32 M, uint32 N, typename cache_type = lmem_cache_tag_type>
  58. struct AlignmentStream
  59. {
  60. typedef t_aligner_type aligner_type;
  61. typedef nvbio::cuda::ldg_pointer<uint32> storage_iterator;
  62. typedef nvbio::PackedStringLoader<storage_iterator,4,false,cache_type> pattern_loader_type;
  63. typedef typename pattern_loader_type::input_iterator uncached_pattern_iterator;
  64. typedef typename pattern_loader_type::iterator pattern_iterator;
  65. typedef nvbio::vector_view<pattern_iterator> pattern_string;
  66. typedef nvbio::PackedStringLoader<storage_iterator,2,false,cache_type> text_loader_type;
  67. typedef typename text_loader_type::input_iterator uncached_text_iterator;
  68. typedef typename text_loader_type::iterator text_iterator;
  69. typedef nvbio::vector_view<text_iterator> text_string;
  70. // an alignment context
  71. struct context_type
  72. {
  73. int32 min_score;
  74. aln::BestSink<int32> sink;
  75. };
  76. // a container for the strings to be aligned
  77. struct strings_type
  78. {
  79. pattern_loader_type pattern_loader;
  80. text_loader_type text_loader;
  81. pattern_string pattern;
  82. trivial_quality_string quals;
  83. text_string text;
  84. };
  85. // constructor
  86. AlignmentStream(
  87. aligner_type _aligner,
  88. const uint32 _count,
  89. const uint32* _patterns,
  90. const uint32* _text,
  91. int16* _scores) :
  92. m_aligner( _aligner ), m_count(_count), m_patterns(storage_iterator(_patterns)), m_text(storage_iterator(_text)), m_scores(_scores) {}
  93. // get the aligner
  94. NVBIO_FORCEINLINE NVBIO_HOST_DEVICE
  95. const aligner_type& aligner() const { return m_aligner; };
  96. // return the maximum pattern length
  97. NVBIO_FORCEINLINE NVBIO_HOST_DEVICE
  98. uint32 max_pattern_length() const { return M; }
  99. // return the maximum text length
  100. NVBIO_FORCEINLINE NVBIO_HOST_DEVICE
  101. uint32 max_text_length() const { return N; }
  102. // return the stream size
  103. NVBIO_FORCEINLINE NVBIO_HOST_DEVICE
  104. uint32 size() const { return m_count; }
  105. // return the i-th pattern's length
  106. NVBIO_FORCEINLINE NVBIO_HOST_DEVICE
  107. uint32 pattern_length(const uint32 i, context_type* context) const { return M; }
  108. // return the i-th text's length
  109. NVBIO_FORCEINLINE NVBIO_HOST_DEVICE
  110. uint32 text_length(const uint32 i, context_type* context) const { return N; }
  111. // initialize the i-th context
  112. NVBIO_FORCEINLINE NVBIO_HOST_DEVICE
  113. bool init_context(
  114. const uint32 i,
  115. context_type* context) const
  116. {
  117. context->min_score = Field_traits<int32>::min();
  118. return true;
  119. }
  120. // initialize the i-th context
  121. NVBIO_FORCEINLINE NVBIO_HOST_DEVICE
  122. void load_strings(
  123. const uint32 i,
  124. const uint32 window_begin,
  125. const uint32 window_end,
  126. const context_type* context,
  127. strings_type* strings) const
  128. {
  129. strings->pattern = pattern_string( M,
  130. strings->pattern_loader.load(
  131. m_patterns + i * M,
  132. M,
  133. make_uint2( window_begin, window_end ),
  134. false ) );
  135. strings->text = text_string( N, strings->text_loader.load( m_text + i * N, N ) );
  136. }
  137. // handle the output
  138. NVBIO_FORCEINLINE NVBIO_HOST_DEVICE
  139. void output(
  140. const uint32 i,
  141. const context_type* context) const
  142. {
  143. // copy the output score
  144. m_scores[i] = context->sink.score;
  145. }
  146. aligner_type m_aligner;
  147. uint32 m_count;
  148. uncached_pattern_iterator m_patterns;
  149. uncached_text_iterator m_text;
  150. int16* m_scores;
  151. };
  152. // A simple kernel to test the speed of alignment without the possible overheads of the BatchAlignmentScore interface
  153. //
  154. template <uint32 BLOCKDIM, uint32 MAX_REF_LEN, typename aligner_type, typename score_type>
  155. __global__ void alignment_test_kernel(const aligner_type aligner, const uint32 N_probs, const uint32 M, const uint32 N, const uint32* strptr, const uint32* refptr, score_type* score)
  156. {
  157. const uint32 tid = blockIdx.x * BLOCKDIM + threadIdx.x;
  158. typedef lmem_cache_tag_type lmem_cache_type;
  159. typedef nvbio::cuda::ldg_pointer<uint32> storage_iterator;
  160. typedef nvbio::PackedStringLoader<storage_iterator,4,false,lmem_cache_type> pattern_loader_type;
  161. typedef typename pattern_loader_type::input_iterator uncached_pattern_iterator;
  162. typedef typename pattern_loader_type::iterator pattern_iterator;
  163. typedef nvbio::vector_view<pattern_iterator> pattern_string;
  164. typedef nvbio::PackedStringLoader<storage_iterator,2,false,lmem_cache_type> text_loader_type;
  165. typedef typename text_loader_type::input_iterator uncached_text_iterator;
  166. typedef typename text_loader_type::iterator text_iterator;
  167. typedef nvbio::vector_view<text_iterator> text_string;
  168. pattern_loader_type pattern_loader;
  169. pattern_string pattern = pattern_string( M, pattern_loader.load( uncached_pattern_iterator( strptr ) + tid * M, tid < N_probs ? M : 0u ) );
  170. text_loader_type text_loader;
  171. text_string text = text_string( N, text_loader.load( uncached_text_iterator( refptr ) + tid * N, tid < N_probs ? N : 0u ) );
  172. aln::BestSink<int32> sink;
  173. aln::alignment_score<MAX_REF_LEN>(
  174. aligner,
  175. pattern,
  176. aln::trivial_quality_string(),
  177. text,
  178. Field_traits<int32>::min(),
  179. sink );
  180. score[tid] = sink.score;
  181. }
  182. //
  183. // A class for making a single alignment test, testing both scoring and traceback
  184. //
  185. struct SingleTest
  186. {
  187. thrust::host_vector<uint8> str_hvec;
  188. thrust::host_vector<uint8> ref_hvec;
  189. thrust::device_vector<uint8> str_dvec;
  190. thrust::device_vector<uint8> ref_dvec;
  191. thrust::device_vector<float> temp_dvec;
  192. thrust::device_vector<float> score_dvec;
  193. thrust::device_vector<uint2> sink_dvec;
  194. // test full DP alignment
  195. //
  196. // \param test test name
  197. // \param aligner alignment algorithm
  198. // \param ref_alignment reference alignment string
  199. //
  200. template <uint32 BLOCKDIM, uint32 N, uint32 M, typename aligner_type>
  201. void full(const char* test, const aligner_type aligner, const char* ref_alignment)
  202. {
  203. NVBIO_VAR_UNUSED const uint32 CHECKPOINTS = 32u;
  204. typedef ScoreMatrices<N,M,typename aligner_type::aligner_tag> SWMatrices;
  205. SharedPointer<SWMatrices> mat = SharedPointer<SWMatrices>( new SWMatrices() );
  206. const uint8* str_hptr = nvbio::raw_pointer( str_hvec );
  207. const uint8* ref_hptr = nvbio::raw_pointer( ref_hvec );
  208. typename column_storage_type<aligner_type>::type column[N];
  209. const int32 ref_score = ref_sw<M,N>( str_hptr, ref_hptr, aligner, mat.get() );
  210. aln::BestSink<int32> sink;
  211. aln::alignment_score(
  212. aligner,
  213. vector_view<const uint8*>( M, str_hptr ),
  214. trivial_quality_string(),
  215. vector_view<const uint8*>( N, ref_hptr ),
  216. -1000,
  217. sink,
  218. column );
  219. const int32 cpu_score = sink.score;
  220. if (cpu_score != ref_score)
  221. {
  222. log_error(stderr, " expected %s score %d, got: %d\n", test, ref_score, cpu_score);
  223. exit(1);
  224. }
  225. TestBacktracker backtracker;
  226. backtracker.clear();
  227. const Alignment<int32> aln = aln::alignment_traceback<1024u,1024u,CHECKPOINTS>(
  228. aligner,
  229. vector_view<const uint8*>( M, str_hptr ),
  230. trivial_quality_string(),
  231. vector_view<const uint8*>( N, ref_hptr ),
  232. -1000,
  233. backtracker );
  234. const int32 aln_score = backtracker.score( aligner, aln.source.x, str_hptr, ref_hptr );
  235. const std::string aln_string = rle( backtracker.aln ).c_str();
  236. if (aln_score != ref_score)
  237. {
  238. log_error(stderr, " expected %s backtracking score %d, got %d\n", test, ref_score, aln_score);
  239. log_error(stderr, " %s - %d - [%u, %u] x [%u, %u]\n", aln_string.c_str(), aln.score, aln.source.x, aln.sink.x, aln.source.y, aln.sink.y);
  240. //mat->print();
  241. exit(1);
  242. }
  243. fprintf(stderr, " %15s : ", test);
  244. fprintf(stderr, "%d - %s - [%u:%u] x [%u:%u]\n", aln.score, aln_string.c_str(), aln.source.x, aln.sink.x, aln.source.y, aln.sink.y);
  245. if (strcmp( ref_alignment, aln_string.c_str() ) != 0)
  246. {
  247. log_error(stderr, " expected %s, got %s\n", ref_alignment, aln_string.c_str());
  248. exit(1);
  249. }
  250. }
  251. // test banded alignment
  252. //
  253. // \param test test name
  254. // \param aligner alignment algorithm
  255. // \param ref_alignment reference alignment string
  256. //
  257. template <uint32 BLOCKDIM, uint32 BAND_LEN, const uint32 N, const uint32 M, typename aligner_type>
  258. void banded(const char* test, const aligner_type aligner, const char* ref_alignment)
  259. {
  260. NVBIO_VAR_UNUSED const uint32 CHECKPOINTS = 32u;
  261. const uint8* str_hptr = nvbio::raw_pointer( str_hvec );
  262. const uint8* ref_hptr = nvbio::raw_pointer( ref_hvec );
  263. const int32 ref_score = ref_banded_sw<M,N,BAND_LEN>( str_hptr, ref_hptr, 0u, aligner );
  264. aln::BestSink<int32> sink;
  265. aln::banded_alignment_score<BAND_LEN>(
  266. aligner,
  267. vector_view<const uint8*>( M, str_hptr ),
  268. trivial_quality_string(),
  269. vector_view<const uint8*>( N, ref_hptr ),
  270. -1000,
  271. sink );
  272. const int32 cpu_score = sink.score;
  273. if (cpu_score != ref_score)
  274. {
  275. log_error(stderr, " expected %s score %d, got: %d\n", test, ref_score, cpu_score);
  276. exit(1);
  277. }
  278. TestBacktracker backtracker;
  279. backtracker.clear();
  280. const Alignment<int32> aln = aln::banded_alignment_traceback<BAND_LEN,1024u,CHECKPOINTS>(
  281. aligner,
  282. vector_view<const uint8*>( M, str_hptr ),
  283. trivial_quality_string(),
  284. vector_view<const uint8*>( N, ref_hptr ),
  285. -1000,
  286. backtracker );
  287. const int32 aln_score = backtracker.score( aligner, aln.source.x, str_hptr, ref_hptr );
  288. const std::string aln_string = rle( backtracker.aln ).c_str();
  289. if (aln_score != ref_score)
  290. {
  291. log_error(stderr, " expected %s backtracking score %d, got %d\n", ref_score, aln_score);
  292. log_error(stderr, " %s - %d - [%u, %u] x [%u, %u]\n", aln_string.c_str(), aln.score, aln.source.x, aln.sink.x, aln.source.y, aln.sink.y);
  293. exit(1);
  294. }
  295. fprintf(stderr, " %15s : ", test);
  296. fprintf(stderr, "%d - %s - [%u:%u] x [%u:%u]\n", aln.score, aln_string.c_str(), aln.source.x, aln.sink.x, aln.source.y, aln.sink.y);
  297. if (strcmp( ref_alignment, aln_string.c_str() ) != 0)
  298. {
  299. log_error(stderr, " expected %s, got %s\n", ref_alignment, aln_string.c_str());
  300. exit(1);
  301. }
  302. }
  303. };
  304. // execute a given batch alignment type on a given stream
  305. //
  306. // \tparam batch_type a \ref BatchAlignment "Batch Alignment"
  307. // \tparam stream_type a stream compatible to the given batch_type
  308. //
  309. // \return average time
  310. //
  311. template <typename batch_type, typename stream_type>
  312. float enact_batch(
  313. batch_type& batch,
  314. const stream_type& stream,
  315. const uint32 n_tests,
  316. const uint32 n_tasks)
  317. {
  318. // alloc all the needed temporary storage
  319. const uint64 temp_size = batch_type::max_temp_storage(
  320. stream.max_pattern_length(),
  321. stream.max_text_length(),
  322. stream.size() );
  323. thrust::device_vector<uint8> temp_dvec( temp_size );
  324. Timer timer;
  325. timer.start();
  326. for (uint32 i = 0; i < n_tests; ++i)
  327. {
  328. // enact the batch
  329. batch.enact( stream, temp_size, nvbio::raw_pointer( temp_dvec ) );
  330. cudaDeviceSynchronize();
  331. }
  332. timer.stop();
  333. return timer.seconds() / float(n_tests);
  334. }
  335. // execute and time a batch of full DP alignments using BatchAlignmentScore
  336. //
  337. template <bool supported, typename scheduler_type, uint32 N, uint32 M, typename stream_type>
  338. struct batch_score_profile_dispatch
  339. {
  340. static void run(
  341. const stream_type stream,
  342. const uint32 n_tests,
  343. const uint32 n_tasks)
  344. {}
  345. };
  346. // execute and time a batch of full DP alignments using BatchAlignmentScore
  347. //
  348. template <typename scheduler_type, uint32 N, uint32 M, typename stream_type>
  349. struct batch_score_profile_dispatch<true,scheduler_type,N,M,stream_type>
  350. {
  351. static void run(
  352. const stream_type stream,
  353. const uint32 n_tests,
  354. const uint32 n_tasks)
  355. {
  356. typedef aln::BatchedAlignmentScore<stream_type, scheduler_type> batch_type; // our batch type
  357. // setup a batch
  358. batch_type batch;
  359. const float time = enact_batch(
  360. batch,
  361. stream,
  362. n_tests,
  363. n_tasks );
  364. fprintf(stderr," %5.1f", 1.0e-9f * float(n_tasks*uint64(N*M))/time );
  365. }
  366. };
  367. // execute and time a batch of full DP alignments using BatchAlignmentScore
  368. //
  369. template <typename scheduler_type, uint32 N, uint32 M, typename stream_type>
  370. void batch_score_profile(
  371. const stream_type stream,
  372. const uint32 n_tests,
  373. const uint32 n_tasks)
  374. {
  375. NVBIO_VAR_UNUSED const bool is_supported = aln::supports_scheduler<typename stream_type::aligner_type,scheduler_type>::pred;
  376. batch_score_profile_dispatch<is_supported,scheduler_type,N,M,stream_type>::run(
  377. stream,
  378. n_tests,
  379. n_tasks );
  380. }
  381. // execute and time the batch_score<scheduler> algorithm for all possible schedulers
  382. //
  383. template <uint32 N, uint32 M, typename aligner_type>
  384. void batch_score_profile_all(
  385. const aligner_type aligner,
  386. const uint32 n_tests,
  387. const uint32 n_tasks,
  388. thrust::device_vector<uint32>& pattern_dvec,
  389. thrust::device_vector<uint32>& text_dvec,
  390. thrust::device_vector<int16>& score_dvec)
  391. {
  392. {
  393. typedef AlignmentStream<aligner_type,M,N> stream_type;
  394. // create a stream
  395. stream_type stream(
  396. aligner,
  397. n_tasks,
  398. nvbio::raw_pointer( pattern_dvec ),
  399. nvbio::raw_pointer( text_dvec ),
  400. nvbio::raw_pointer( score_dvec ) );
  401. // test the DeviceThreadScheduler
  402. batch_score_profile<DeviceThreadScheduler,N,M>(
  403. stream,
  404. n_tests,
  405. n_tasks );
  406. // test the DeviceStagedThreadScheduler
  407. batch_score_profile<DeviceStagedThreadScheduler,N,M>(
  408. stream,
  409. n_tests,
  410. n_tasks );
  411. }
  412. {
  413. typedef AlignmentStream<aligner_type,M,N,uncached_tag_type> stream_type;
  414. // create a stream
  415. stream_type stream(
  416. aligner,
  417. n_tasks,
  418. nvbio::raw_pointer( pattern_dvec ),
  419. nvbio::raw_pointer( text_dvec ),
  420. nvbio::raw_pointer( score_dvec ) );
  421. // test the DeviceWarpScheduler
  422. batch_score_profile<DeviceWarpScheduler,N,M>(
  423. stream,
  424. n_tests,
  425. n_tasks );
  426. }
  427. {
  428. const uint32 BLOCKDIM = 128;
  429. const uint32 N_BLOCKS = (n_tasks + BLOCKDIM-1) / BLOCKDIM;
  430. Timer timer;
  431. timer.start();
  432. for (uint32 i = 0; i < n_tests; ++i)
  433. {
  434. // enact the batch
  435. alignment_test_kernel<BLOCKDIM,N> <<<N_BLOCKS,BLOCKDIM>>>(
  436. aligner,
  437. n_tasks,
  438. M,
  439. N,
  440. nvbio::raw_pointer( pattern_dvec ),
  441. nvbio::raw_pointer( text_dvec ),
  442. nvbio::raw_pointer( score_dvec ) );
  443. cudaDeviceSynchronize();
  444. }
  445. timer.stop();
  446. const float time = timer.seconds();
  447. fprintf(stderr," %5.1f", 1.0e-9f * float(n_tasks*uint64(N*M))*(float(n_tests)/time) );
  448. }
  449. fprintf(stderr, " GCUPS\n");
  450. }
  451. // execute and time a batch of banded alignments using BatchBandedAlignmentScore
  452. //
  453. template <uint32 BAND_LEN, typename scheduler_type, uint32 N, uint32 M, typename stream_type>
  454. void batch_banded_score_profile(
  455. const stream_type stream,
  456. const uint32 n_tests,
  457. const uint32 n_tasks)
  458. {
  459. typedef aln::BatchedBandedAlignmentScore<BAND_LEN,stream_type, scheduler_type> batch_type; // our batch type
  460. // setup a batch
  461. batch_type batch;
  462. const float time = enact_batch(
  463. batch,
  464. stream,
  465. n_tests,
  466. n_tasks );
  467. fprintf(stderr," %5.1f", 1.0e-9f * float(n_tasks*uint64(BAND_LEN*M))*(float(n_tests)/time) );
  468. }
  469. // execute and time the batch_banded_score<scheduler> algorithm for all possible schedulers
  470. //
  471. template <uint32 BAND_LEN, uint32 N, uint32 M, typename aligner_type>
  472. void batch_banded_score_profile_all(
  473. const aligner_type aligner,
  474. const uint32 n_tests,
  475. const uint32 n_tasks,
  476. thrust::device_vector<uint32>& pattern_dvec,
  477. thrust::device_vector<uint32>& text_dvec,
  478. thrust::device_vector<int16>& score_dvec)
  479. {
  480. typedef AlignmentStream<aligner_type,M,N> stream_type;
  481. // create a stream
  482. stream_type stream(
  483. aligner,
  484. n_tasks,
  485. nvbio::raw_pointer( pattern_dvec ),
  486. nvbio::raw_pointer( text_dvec ),
  487. nvbio::raw_pointer( score_dvec ) );
  488. // test the DeviceThreadScheduler
  489. batch_banded_score_profile<BAND_LEN,DeviceThreadScheduler,N,M>(
  490. stream,
  491. n_tests,
  492. n_tasks );
  493. // test the DeviceStagedThreadScheduler
  494. batch_banded_score_profile<BAND_LEN,DeviceStagedThreadScheduler,N,M>(
  495. stream,
  496. n_tests,
  497. n_tasks );
  498. // TODO: test DeviceWarpScheduler
  499. fprintf(stderr, " GCUPS\n");
  500. }
  501. // a simple banded edit distance test
  502. //
  503. template <typename string_type>
  504. void banded_edit_distance_test(
  505. const uint32 test_id,
  506. const string_type pattern,
  507. const string_type text,
  508. const int32 ref_score)
  509. {
  510. const int32 ed = banded_alignment_score<5>(
  511. make_edit_distance_aligner<aln::SEMI_GLOBAL>(),
  512. pattern,
  513. text,
  514. -255 );
  515. if (ed != ref_score)
  516. {
  517. log_error(stderr, " synthetic Edit Distance test %u... failed\n", test_id);
  518. log_error(stderr, " expected %d, got: %d - pattern: %s text: %s\n", ref_score, ed, pattern.begin(), text.begin());
  519. exit(1);
  520. }
  521. else
  522. fprintf(stderr, " synthetic Edit Distance test %u... passed!\n", test_id);
  523. }
  524. void test(int argc, char* argv[])
  525. {
  526. uint32 n_tests = 1;
  527. NVBIO_VAR_UNUSED uint32 N_WARP_TASKS = 4096;
  528. uint32 N_THREAD_TASKS = 128*1024;
  529. uint32 TEST_MASK = 0xFFFFFFFFu;
  530. for (int i = 0; i < argc; ++i)
  531. {
  532. if (strcmp( argv[i], "-N-thread-tasks" ) == 0)
  533. N_THREAD_TASKS = atoi( argv[++i] );
  534. else if (strcmp( argv[i], "-N-warp-tasks" ) == 0)
  535. N_WARP_TASKS = atoi( argv[++i] );
  536. else if (strcmp( argv[i], "-N-tests" ) == 0)
  537. n_tests = atoi( argv[++i] );
  538. else if (strcmp( argv[i], "-tests" ) == 0)
  539. {
  540. const std::string tests_string( argv[++i] );
  541. char temp[256];
  542. const char* begin = tests_string.c_str();
  543. const char* end = begin;
  544. TEST_MASK = 0u;
  545. while (1)
  546. {
  547. while (*end != ':' && *end != '\0')
  548. {
  549. temp[end - begin] = *end;
  550. end++;
  551. }
  552. temp[end - begin] = '\0';
  553. if (strcmp( temp, "functional" ) == 0)
  554. TEST_MASK |= FUNCTIONAL;
  555. else if (strcmp( temp, "ed" ) == 0)
  556. TEST_MASK |= ED;
  557. else if (strcmp( temp, "ed-banded" ) == 0)
  558. TEST_MASK |= ED_BANDED;
  559. else if (strcmp( temp, "sw" ) == 0)
  560. TEST_MASK |= SW;
  561. else if (strcmp( temp, "sw-banded" ) == 0)
  562. TEST_MASK |= SW_BANDED;
  563. else if (strcmp( temp, "sw-warp" ) == 0)
  564. TEST_MASK |= SW_WARP;
  565. else if (strcmp( temp, "sw-striped" ) == 0)
  566. TEST_MASK |= SW_STRIPED;
  567. else if (strcmp( temp, "gotoh" ) == 0)
  568. TEST_MASK |= GOTOH;
  569. else if (strcmp( temp, "gotoh-banded" ) == 0)
  570. TEST_MASK |= GOTOH_BANDED;
  571. if (*end == '\0')
  572. break;
  573. ++end; begin = end;
  574. }
  575. }
  576. }
  577. fprintf(stderr,"testing alignment... started\n");
  578. if (TEST_MASK & FUNCTIONAL)
  579. {
  580. typedef vector_view<const char*> const_string;
  581. // right aligned, no gaps
  582. {
  583. const_string text = make_string("AAAAGGGTGCTCAA");
  584. const_string pattern = make_string("GGGTGCTCAA");
  585. banded_edit_distance_test(
  586. 1u, // test id
  587. pattern, // pattern
  588. text, // text
  589. 0 ); // expected score
  590. }
  591. // right aligned, 2 insertions
  592. {
  593. const_string text = make_string("AAAAGGGTGCTCAA");
  594. const_string pattern = make_string("GGGTAAGCTC");
  595. banded_edit_distance_test(
  596. 2u, // test id
  597. pattern, // pattern
  598. text, // text
  599. -2 ); // expected score
  600. }
  601. // right aligned, 2 deletions
  602. {
  603. const_string text = make_string("AAAAGGGTGCAATC");
  604. const_string pattern = make_string("AAGGGTGCTC");
  605. banded_edit_distance_test(
  606. 3u, // test id
  607. pattern, // pattern
  608. text, // text
  609. -2 ); // expected score
  610. }
  611. // left aligned, zero gaps
  612. {
  613. const_string text = make_string("AAAAGGGTGCTCAA");
  614. const_string pattern = make_string("AAAAGGGTGC");
  615. banded_edit_distance_test(
  616. 4u, // test id
  617. pattern, // pattern
  618. text, // text
  619. 0 ); // expected score
  620. }
  621. // left aligned, 2 deletions
  622. {
  623. const_string text = make_string("AAAAGGAAGTGCTC");
  624. const_string pattern = make_string("AAAAGGGTG");
  625. banded_edit_distance_test(
  626. 5u, // test id
  627. pattern, // pattern
  628. text, // text
  629. -2 ); // expected score
  630. }
  631. // centrally aligned, 2 insertions
  632. {
  633. const_string text = make_string("AACAGGGTGCTC");
  634. const_string pattern = make_string("CACCGGGT");
  635. banded_edit_distance_test(
  636. 6u, // test id
  637. pattern, // pattern
  638. text, // text
  639. -2 ); // expected score
  640. }
  641. }
  642. if (TEST_MASK & FUNCTIONAL)
  643. {
  644. NVBIO_VAR_UNUSED const uint32 BLOCKDIM = 128;
  645. const uint32 M = 7;
  646. const uint32 N = 20;
  647. thrust::host_vector<uint8> str_hvec( M );
  648. thrust::host_vector<uint8> ref_hvec( N );
  649. uint8* str_hptr = nvbio::raw_pointer( str_hvec );
  650. uint8* ref_hptr = nvbio::raw_pointer( ref_hvec );
  651. string_to_dna("ACAACTA", str_hptr);
  652. string_to_dna("AAACACCCTAACACACTAAA", ref_hptr);
  653. SingleTest test;
  654. nvbio::cuda::thrust_copy_vector(test.str_hvec, str_hvec);
  655. nvbio::cuda::thrust_copy_vector(test.ref_hvec, ref_hvec);
  656. nvbio::cuda::thrust_copy_vector(test.str_dvec, str_hvec);
  657. nvbio::cuda::thrust_copy_vector(test.ref_dvec, ref_hvec);
  658. {
  659. fprintf(stderr," testing Smith-Waterman scoring...\n");
  660. aln::SimpleSmithWatermanScheme scoring;
  661. scoring.m_match = 2;
  662. scoring.m_mismatch = -1;
  663. scoring.m_deletion = -1;
  664. scoring.m_insertion = -1;
  665. test.full<BLOCKDIM,N,M>( "global", make_smith_waterman_aligner<aln::GLOBAL>( scoring ), "1M2D3M1D3M10D" );
  666. test.full<BLOCKDIM,N,M>( "local", make_smith_waterman_aligner<aln::LOCAL>( scoring ), "4M1D3M" );
  667. test.full<BLOCKDIM,N,M>( "semi-global", make_smith_waterman_aligner<aln::SEMI_GLOBAL>( scoring ), "4M1D3M" );
  668. }
  669. {
  670. fprintf(stderr," testing Gotoh scoring...\n");
  671. aln::SimpleGotohScheme scoring;
  672. scoring.m_match = 2;
  673. scoring.m_mismatch = -1;
  674. scoring.m_gap_open = -1;
  675. scoring.m_gap_ext = -1;
  676. test.full<BLOCKDIM,N,M>( "global", make_gotoh_aligner<aln::GLOBAL>( scoring ), "1M2D3M1D3M10D" );
  677. test.full<BLOCKDIM,N,M>( "local", make_gotoh_aligner<aln::LOCAL>( scoring ), "4M1D3M" );
  678. test.full<BLOCKDIM,N,M>( "semi-global", make_gotoh_aligner<aln::SEMI_GLOBAL>( scoring ), "4M1D3M" );
  679. test.banded<BLOCKDIM, 7u, N, M>( "banded-semi-global", make_gotoh_aligner<aln::SEMI_GLOBAL>( scoring ), "4M1D3M" );
  680. }
  681. }
  682. if (TEST_MASK & FUNCTIONAL)
  683. {
  684. fprintf(stderr," testing real banded Gotoh problem...\n");
  685. NVBIO_VAR_UNUSED const uint32 BLOCKDIM = 128;
  686. NVBIO_VAR_UNUSED const uint32 BAND_LEN = 31;
  687. NVBIO_VAR_UNUSED const uint32 M = 150;
  688. NVBIO_VAR_UNUSED const uint32 N = 150 + 31;
  689. thrust::host_vector<uint8> str_hvec( M );
  690. thrust::host_vector<uint8> ref_hvec( N );
  691. uint8* str_hptr = nvbio::raw_pointer( str_hvec );
  692. uint8* ref_hptr = nvbio::raw_pointer( ref_hvec );
  693. string_to_dna("TTATGTAGGTGGTCTGGTTTTTGCCTTTTAAGCTTCTGCAAAAAACAACAACAAACTTGTGGTATTACACTGACTCTACAGATCAATTTGGGGACAACTTCCATGTGTTCCACCACCAATACTGAATCTTTCAATCGACTGACGTGGTAT", str_hptr);
  694. string_to_dna("ATCGGATTCTTTCTTACTTGTAGGTGGTCTGGTTTTTGCCTTTTAAGCTTCTGCAAAAAACAACAACAAACTTGTGGTATTACACTGACTCTACAGATCAATTTGGGGACAACTTCCATGTGTTCCACCACCAATACTGAATCTTTCAATCGACTGACGTGGTATCTCTCTCTCCATCTAT", ref_hptr);
  695. aln::SimpleGotohScheme scoring;
  696. scoring.m_match = 0;
  697. scoring.m_mismatch = -5;
  698. scoring.m_gap_open = -8;
  699. scoring.m_gap_ext = -3;
  700. SingleTest test;
  701. nvbio::cuda::thrust_copy_vector(test.str_hvec, str_hvec);
  702. nvbio::cuda::thrust_copy_vector(test.ref_hvec, ref_hvec);
  703. nvbio::cuda::thrust_copy_vector(test.str_dvec, str_hvec);
  704. nvbio::cuda::thrust_copy_vector(test.ref_dvec, ref_hvec);
  705. test.banded<BLOCKDIM, BAND_LEN, N, M>( "banded-semi-global", make_gotoh_aligner<aln::SEMI_GLOBAL>( scoring ), "147M2D3M" );
  706. }
  707. // This code is for debugging purposes, useful to plug-in and analyze real problems coming from an app
  708. if (TEST_MASK & FUNCTIONAL)
  709. {
  710. fprintf(stderr," testing real full-matrix Gotoh problem...\n");
  711. NVBIO_VAR_UNUSED const uint32 BLOCKDIM = 128;
  712. NVBIO_VAR_UNUSED const uint32 M = 144;
  713. NVBIO_VAR_UNUSED const uint32 N = 500;
  714. thrust::host_vector<uint8> str_hvec( M );
  715. thrust::host_vector<uint8> ref_hvec( N );
  716. uint8* str_hptr = nvbio::raw_pointer( str_hvec );
  717. uint8* ref_hptr = nvbio::raw_pointer( ref_hvec );
  718. const char* str_ascii =
  719. "TAGGAGGTAACATGTATGGAGCATTTACCATAGGCCAAGCACTGTTCTAAGAACTTCGGACATGTTATCTCACTTGTATAAGTACTTAGGTGCCTACAACATAAGCAGCACCTGGTAAATTAAGTATTGAAAAAATGCAGATCG";
  720. const char* ref_ascii =
  721. "CAGCACTGACCGGTGAGCATAAACCCTGGGGATGCCCAGAGCTGGTACAGCCAGGAGCTCCAGAAGCGTGGGATTCTCAGAGGGAAGTGGAGCTCACTGCTCTACAGGTCCTATTCAAGTTAGAAAGTAAGATACAATGCACACAAAGCCAAATTGTC"
  722. "ATCATTCAGCTCCTATTACAGGGGAACTAAGAGCTGCATTGAAAATTATTTGCAAAGCTTGTAAGTGGTTCTGCCACTTATTAGCCGTGTGAACCTTAGCAAATTACCTAGCGTCTCTGAGTTTCAACTTCCTCATCTACAAAATAGAAATGATAATAAT"
  723. "AACCGCATCGCAAGAGTTGTTGGAAAAATGAAAATGAGGTATCATAGGAGGTAACATGTATGGAGCATTTACCATAGGCCAAGCACTGTTCTAAGAACTTCGGACATGTTATCTCACTTGTATAAGTACTTAGGTGCCTACAACATAAACAGCACCTGGT"
  724. "AAATTAAGTATTGAAAAAATGC";
  725. string_to_dna( str_ascii, str_hptr );
  726. string_to_dna( ref_ascii, ref_hptr );
  727. aln::SimpleGotohScheme scoring;
  728. scoring.m_match = 0;
  729. scoring.m_mismatch = -5;
  730. scoring.m_gap_open = -8;
  731. scoring.m_gap_ext = -3;
  732. aln::GotohAligner<aln::SEMI_GLOBAL, aln::SimpleGotohScheme> aligner( scoring );
  733. SingleTest test;
  734. nvbio::cuda::thrust_copy_vector(test.str_hvec, str_hvec);
  735. nvbio::cuda::thrust_copy_vector(test.ref_hvec, ref_hvec);
  736. nvbio::cuda::thrust_copy_vector(test.str_dvec, str_hvec);
  737. nvbio::cuda::thrust_copy_vector(test.ref_dvec, ref_hvec);
  738. test.full<BLOCKDIM,N,M>( "semi-global", aligner, "6I138M" );
  739. }
  740. // This code is for debugging purposes, useful to plug-in and analyze real problems coming from an app
  741. if (TEST_MASK & FUNCTIONAL)
  742. {
  743. fprintf(stderr," testing real full-matrix Edit Distance problem...\n");
  744. NVBIO_VAR_UNUSED const uint32 BLOCKDIM = 128;
  745. NVBIO_VAR_UNUSED const uint32 M = 144;
  746. NVBIO_VAR_UNUSED const uint32 N = 500;
  747. thrust::host_vector<uint8> str_hvec( M );
  748. thrust::host_vector<uint8> ref_hvec( N );
  749. uint8* str_hptr = nvbio::raw_pointer( str_hvec );
  750. uint8* ref_hptr = nvbio::raw_pointer( ref_hvec );
  751. const char* str_ascii =
  752. "TAGGAGGTAACATGTATGGAGCATTTACCATAGGCCAAGCACTGTTCTAAGAACTTCGGACATGTTATCTCACTTGTATAAGTACTTAGGTGCCTACAACATAAGCAGCACCTGGTAAATTAAGTATTGAAAAAATGCAGATCG";
  753. const char* ref_ascii =
  754. "CAGCACTGACCGGTGAGCATAAACCCTGGGGATGCCCAGAGCTGGTACAGCCAGGAGCTCCAGAAGCGTGGGATTCTCAGAGGGAAGTGGAGCTCACTGCTCTACAGGTCCTATTCAAGTTAGAAAGTAAGATACAATGCACACAAAGCCAAATTGTC"
  755. "ATCATTCAGCTCCTATTACAGGGGAACTAAGAGCTGCATTGAAAATTATTTGCAAAGCTTGTAAGTGGTTCTGCCACTTATTAGCCGTGTGAACCTTAGCAAATTACCTAGCGTCTCTGAGTTTCAACTTCCTCATCTACAAAATAGAAATGATAATAAT"
  756. "AACCGCATCGCAAGAGTTGTTGGAAAAATGAAAATGAGGTATCATAGGAGGTAACATGTATGGAGCATTTACCATAGGCCAAGCACTGTTCTAAGAACTTCGGACATGTTATCTCACTTGTATAAGTACTTAGGTGCCTACAACATAAACAGCACCTGGT"
  757. "AAATTAAGTATTGAAAAAATGC";
  758. string_to_dna( str_ascii, str_hptr );
  759. string_to_dna( ref_ascii, ref_hptr );
  760. aln::EditDistanceAligner<aln::SEMI_GLOBAL> aligner;
  761. SingleTest test;
  762. nvbio::cuda::thrust_copy_vector(test.str_hvec, str_hvec);
  763. nvbio::cuda::thrust_copy_vector(test.ref_hvec, ref_hvec);
  764. nvbio::cuda::thrust_copy_vector(test.str_dvec, str_hvec);
  765. nvbio::cuda::thrust_copy_vector(test.ref_dvec, ref_hvec);
  766. test.full<BLOCKDIM,N,M>( "semi-global", aligner, "1I1M2I1M3I136M" );
  767. }
  768. // do a larger speed test of the Gotoh alignment
  769. if (TEST_MASK & (ED | SW | GOTOH))
  770. {
  771. const uint32 N_TASKS = N_THREAD_TASKS;
  772. const uint32 M = 150;
  773. const uint32 N = 500;
  774. const uint32 M_WORDS = (M + 7) >> 3;
  775. const uint32 N_WORDS = (N + 15) >> 4;
  776. thrust::host_vector<uint32> str( M_WORDS * N_TASKS );
  777. thrust::host_vector<uint32> ref( N_WORDS * N_TASKS );
  778. LCG_random rand;
  779. fill_packed_stream<4u>( rand, 4u, M * N_TASKS, nvbio::raw_pointer( str ) );
  780. fill_packed_stream<2u>( rand, 4u, N * N_TASKS, nvbio::raw_pointer( ref ) );
  781. thrust::device_vector<uint32> str_dvec( str );
  782. thrust::device_vector<uint32> ref_dvec( ref );
  783. thrust::device_vector<int16> score_dvec( N_TASKS );
  784. if (TEST_MASK & ED)
  785. {
  786. fprintf(stderr," testing Edit Distance scoring speed...\n");
  787. fprintf(stderr," %15s : ", "global");
  788. {
  789. batch_score_profile_all<N,M>(
  790. make_edit_distance_aligner<aln::GLOBAL>(),
  791. n_tests,
  792. N_TASKS,
  793. str_dvec,
  794. ref_dvec,
  795. score_dvec );
  796. }
  797. fprintf(stderr," %15s : ", "semi-global");
  798. {
  799. batch_score_profile_all<N,M>(
  800. make_edit_distance_aligner<aln::SEMI_GLOBAL>(),
  801. n_tests,
  802. N_TASKS,
  803. str_dvec,
  804. ref_dvec,
  805. score_dvec );
  806. }
  807. fprintf(stderr," %15s : ", "local");
  808. {
  809. batch_score_profile_all<N,M>(
  810. make_edit_distance_aligner<aln::LOCAL>(),
  811. n_tests,
  812. N_TASKS,
  813. str_dvec,
  814. ref_dvec,
  815. score_dvec );
  816. }
  817. }
  818. if (TEST_MASK & ED)
  819. {
  820. aln::SimpleSmithWatermanScheme scoring;
  821. scoring.m_match = 2;
  822. scoring.m_mismatch = -1;
  823. fprintf(stderr," testing Hamming Distance scoring speed...\n");
  824. fprintf(stderr," %15s : ", "semi-global");
  825. {
  826. batch_score_profile_all<N,M>(
  827. make_hamming_distance_aligner<aln::SEMI_GLOBAL>( scoring ),
  828. n_tests,
  829. N_TASKS,
  830. str_dvec,
  831. ref_dvec,
  832. score_dvec );
  833. }
  834. fprintf(stderr," %15s : ", "local");
  835. {
  836. batch_score_profile_all<N,M>(
  837. make_hamming_distance_aligner<aln::LOCAL>( scoring ),
  838. n_tests,
  839. N_TASKS,
  840. str_dvec,
  841. ref_dvec,
  842. score_dvec );
  843. }
  844. }
  845. if (TEST_MASK & SW)
  846. {
  847. aln::SimpleSmithWatermanScheme scoring;
  848. scoring.m_match = 2;
  849. scoring.m_mismatch = -1;
  850. scoring.m_deletion = -1;
  851. scoring.m_insertion = -1;
  852. fprintf(stderr," testing Smith-Waterman scoring speed...\n");
  853. fprintf(stderr," %15s : ", "global");
  854. {
  855. batch_score_profile_all<N,M>(
  856. make_smith_waterman_aligner<aln::GLOBAL>( scoring ),
  857. n_tests,
  858. N_TASKS,
  859. str_dvec,
  860. ref_dvec,
  861. score_dvec );
  862. }
  863. fprintf(stderr," %15s : ", "semi-global");
  864. {
  865. batch_score_profile_all<N,M>(
  866. make_smith_waterman_aligner<aln::SEMI_GLOBAL>( scoring ),
  867. n_tests,
  868. N_TASKS,
  869. str_dvec,
  870. ref_dvec,
  871. score_dvec );
  872. }
  873. fprintf(stderr," %15s : ", "local");
  874. {
  875. batch_score_profile_all<N,M>(
  876. make_smith_waterman_aligner<aln::LOCAL>( scoring ),
  877. n_tests,
  878. N_TASKS,
  879. str_dvec,
  880. ref_dvec,
  881. score_dvec );
  882. }
  883. }
  884. if (TEST_MASK & GOTOH)
  885. {
  886. aln::SimpleGotohScheme scoring;
  887. scoring.m_match = 2;
  888. scoring.m_mismatch = -1;
  889. scoring.m_gap_open = -1;
  890. scoring.m_gap_ext = -1;
  891. fprintf(stderr," testing Gotoh scoring speed...\n");
  892. fprintf(stderr," %15s : ", "global");
  893. {
  894. batch_score_profile_all<N,M>(
  895. make_gotoh_aligner<aln::GLOBAL>( scoring ),
  896. n_tests,
  897. N_TASKS,
  898. str_dvec,
  899. ref_dvec,
  900. score_dvec );
  901. }
  902. fprintf(stderr," %15s : ", "semi-global");
  903. {
  904. batch_score_profile_all<N,M>(
  905. make_gotoh_aligner<aln::SEMI_GLOBAL>( scoring ),
  906. n_tests,
  907. N_TASKS,
  908. str_dvec,
  909. ref_dvec,
  910. score_dvec );
  911. }
  912. fprintf(stderr," %15s : ", "local");
  913. {
  914. batch_score_profile_all<N,M>(
  915. make_gotoh_aligner<aln::LOCAL>( scoring ),
  916. n_tests,
  917. N_TASKS,
  918. str_dvec,
  919. ref_dvec,
  920. score_dvec );
  921. }
  922. }
  923. }
  924. // do a larger speed test of the banded SW alignment
  925. if (TEST_MASK & (ED_BANDED | SW_BANDED | GOTOH_BANDED))
  926. {
  927. const uint32 BAND_LEN = 15u;
  928. const uint32 N_TASKS = N_THREAD_TASKS;
  929. const uint32 M = 150;
  930. const uint32 N = M+BAND_LEN;
  931. const uint32 M_WORDS = (M + 7) >> 3;
  932. const uint32 N_WORDS = (N + 15) >> 4;
  933. thrust::host_vector<uint32> str( M_WORDS * N_TASKS );
  934. thrust::host_vector<uint32> ref( N_WORDS * N_TASKS );
  935. LCG_random rand;
  936. fill_packed_stream<4u>( rand, 4u, M * N_TASKS, nvbio::raw_pointer( str ) );
  937. fill_packed_stream<2u>( rand, 4u, N * N_TASKS, nvbio::raw_pointer( ref ) );
  938. thrust::device_vector<uint32> str_dvec( str );
  939. thrust::device_vector<uint32> ref_dvec( ref );
  940. thrust::device_vector<int16> score_dvec( N_TASKS );
  941. if (TEST_MASK & ED_BANDED)
  942. {
  943. fprintf(stderr," testing banded Edit Distance scoring speed...\n");
  944. fprintf(stderr," %15s : ", "global");
  945. {
  946. batch_banded_score_profile_all<BAND_LEN,N,M>(
  947. make_edit_distance_aligner<aln::GLOBAL>(),
  948. n_tests,
  949. N_TASKS,
  950. str_dvec,
  951. ref_dvec,
  952. score_dvec );
  953. }
  954. fprintf(stderr," %15s : ", "semi-global");
  955. {
  956. batch_banded_score_profile_all<BAND_LEN,N,M>(
  957. make_edit_distance_aligner<aln::SEMI_GLOBAL>(),
  958. n_tests,
  959. N_TASKS,
  960. str_dvec,
  961. ref_dvec,
  962. score_dvec );
  963. }
  964. fprintf(stderr," %15s : ", "local");
  965. {
  966. batch_banded_score_profile_all<BAND_LEN,N,M>(
  967. make_edit_distance_aligner<aln::LOCAL>(),
  968. n_tests,
  969. N_TASKS,
  970. str_dvec,
  971. ref_dvec,
  972. score_dvec );
  973. }
  974. }
  975. if (TEST_MASK & SW_BANDED)
  976. {
  977. fprintf(stderr," testing banded Smith-Waterman scoring speed...\n");
  978. fprintf(stderr," %15s : ", "global");
  979. {
  980. batch_banded_score_profile_all<BAND_LEN,N,M>(
  981. make_smith_waterman_aligner<aln::GLOBAL>( aln::SimpleSmithWatermanScheme(2,-1,-1,-1) ),
  982. n_tests,
  983. N_TASKS,
  984. str_dvec,
  985. ref_dvec,
  986. score_dvec );
  987. }
  988. fprintf(stderr," %15s : ", "semi-global");
  989. {
  990. batch_banded_score_profile_all<BAND_LEN,N,M>(
  991. make_smith_waterman_aligner<aln::SEMI_GLOBAL>( aln::SimpleSmithWatermanScheme(2,-1,-1,-1) ),
  992. n_tests,
  993. N_TASKS,
  994. str_dvec,
  995. ref_dvec,
  996. score_dvec );
  997. }
  998. fprintf(stderr," %15s : ", "local");
  999. {
  1000. batch_banded_score_profile_all<BAND_LEN,N,M>(
  1001. make_smith_waterman_aligner<aln::LOCAL>( aln::SimpleSmithWatermanScheme(2,-1,-1,-1) ),
  1002. n_tests,
  1003. N_TASKS,
  1004. str_dvec,
  1005. ref_dvec,
  1006. score_dvec );
  1007. }
  1008. }
  1009. if (TEST_MASK & GOTOH_BANDED)
  1010. {
  1011. fprintf(stderr," testing banded Gotoh scoring speed...\n");
  1012. fprintf(stderr," %15s : ", "global");
  1013. {
  1014. batch_banded_score_profile_all<BAND_LEN,N,M>(
  1015. make_gotoh_aligner<aln::GLOBAL>( aln::SimpleGotohScheme(2,-1,-1,-1) ),
  1016. n_tests,
  1017. N_TASKS,
  1018. str_dvec,
  1019. ref_dvec,
  1020. score_dvec );
  1021. }
  1022. fprintf(stderr," %15s : ", "semi-global");
  1023. {
  1024. batch_banded_score_profile_all<BAND_LEN,N,M>(
  1025. make_gotoh_aligner<aln::SEMI_GLOBAL>( aln::SimpleGotohScheme(2,-1,-1,-1) ),
  1026. n_tests,
  1027. N_TASKS,
  1028. str_dvec,
  1029. ref_dvec,
  1030. score_dvec );
  1031. }
  1032. fprintf(stderr," %15s : ", "local");
  1033. {
  1034. batch_banded_score_profile_all<BAND_LEN,N,M>(
  1035. make_gotoh_aligner<aln::LOCAL>( aln::SimpleGotohScheme(2,-1,-1,-1) ),
  1036. n_tests,
  1037. N_TASKS,
  1038. str_dvec,
  1039. ref_dvec,
  1040. score_dvec );
  1041. }
  1042. }
  1043. }
  1044. fprintf(stderr,"testing alignment... done\n");
  1045. }
  1046. } // namespace sw
  1047. } // namespace nvbio