output_thread.cu 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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. // output_thread.cu
  28. //
  29. #include "output_thread.h"
  30. #include "utils.h"
  31. #include <nvbio/basic/pipeline_context.h>
  32. #include <nvbio/basic/console.h>
  33. #include <nvbio/basic/timer.h>
  34. #include <nvbio/basic/threads.h>
  35. #include <nvbio/io/sequence/sequence.h>
  36. #include <zlib/zlib.h>
  37. #include <stdio.h>
  38. #include <stdlib.h>
  39. using namespace nvbio;
  40. // fill the next batch
  41. //
  42. bool OutputStage::process(PipelineContext& context)
  43. {
  44. try
  45. {
  46. // fetch the h_read_data
  47. io::SequenceDataHost* h_read_data = context.input<io::SequenceDataHost>( 0 );
  48. log_debug(stderr, " writing... started (%u, %u)\n", h_read_data->size(), h_read_data->bps() );
  49. Timer timer;
  50. timer.start();
  51. data->m_mutex.lock();
  52. data->m_file->next( *h_read_data );
  53. if (data->m_file->is_ok() == false)
  54. {
  55. log_error(stderr, "[OutputStage] failed writing output\n");
  56. exit(1);
  57. }
  58. timer.stop();
  59. data->m_time += timer.seconds();
  60. log_verbose(stderr, "\r written reads [%u, %u] (%.1fM / %.2fG bps, %.1fK reads/s, %.1fM bps/s) ",
  61. data->m_reads,
  62. data->m_reads + h_read_data->size(),
  63. 1.0e-6f * (h_read_data->bps()),
  64. 1.0e-9f * (data->m_bps + h_read_data->bps()),
  65. data->m_time ? (1.0e-3f * (data->m_reads + h_read_data->size())) / data->m_time : 0.0f,
  66. data->m_time ? (1.0e-6f * (data->m_bps + h_read_data->bps() )) / data->m_time : 0.0f );
  67. log_debug_cont(stderr, "\n");
  68. data->m_reads += h_read_data->size();
  69. data->m_bps += h_read_data->bps();
  70. data->m_mutex.unlock();
  71. log_debug(stderr, " writing... done (%.1f Mbps/s)\n", data->m_time ? (1.0e-6f * float(data->m_bps)) / data->m_time : 0.0f);
  72. }
  73. catch (nvbio::cuda_error e)
  74. {
  75. log_error(stderr, "[OutputStage] caught a nvbio::cuda_error exception:\n");
  76. log_error(stderr, " %s\n", e.what());
  77. exit(1);
  78. }
  79. catch (nvbio::bad_alloc e)
  80. {
  81. log_error(stderr, "[OutputStage] caught a nvbio::bad_alloc exception:\n");
  82. log_error(stderr, " %s\n", e.what());
  83. exit(1);
  84. }
  85. catch (nvbio::logic_error e)
  86. {
  87. log_error(stderr, "[OutputStage] caught a nvbio::logic_error exception:\n");
  88. log_error(stderr, " %s\n", e.what());
  89. exit(1);
  90. }
  91. catch (nvbio::runtime_error e)
  92. {
  93. log_error(stderr, "[OutputStage] caught a nvbio::runtime_error exception:\n");
  94. log_error(stderr, " %s\n", e.what());
  95. exit(1);
  96. }
  97. catch (thrust::system::system_error e)
  98. {
  99. log_error(stderr, "[OutputStage] caught a thrust::system_error exception:\n");
  100. log_error(stderr, " %s\n", e.what());
  101. exit(1);
  102. }
  103. catch (std::bad_alloc e)
  104. {
  105. log_error(stderr, "[OutputStage] caught a std::bad_alloc exception:\n");
  106. log_error(stderr, " %s\n", e.what());
  107. exit(1);
  108. }
  109. catch (std::logic_error e)
  110. {
  111. log_error(stderr, "[OutputStage] caught a std::logic_error exception:\n");
  112. log_error(stderr, " %s\n", e.what());
  113. exit(1);
  114. }
  115. catch (std::runtime_error e)
  116. {
  117. log_error(stderr, "[OutputStage] caught a std::runtime_error exception:\n");
  118. log_error(stderr, " %s\n", e.what());
  119. exit(1);
  120. }
  121. catch (...)
  122. {
  123. log_error(stderr, "[OutputStage] caught an unknown exception!\n");
  124. exit(1);
  125. }
  126. return true;
  127. }