input_thread.cu 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. // input_thread.cu
  28. //
  29. #include "input_thread.h"
  30. #include <nvbio/basic/pipeline_context.h>
  31. #include <nvbio/basic/console.h>
  32. #include <nvbio/basic/timer.h>
  33. #include <nvbio/basic/threads.h>
  34. #include <nvbio/io/sequence/sequence.h>
  35. #include <stdio.h>
  36. #include <stdlib.h>
  37. using namespace nvbio;
  38. // fill the next batch
  39. //
  40. bool InputStage::process(nvbio::PipelineContext& context)
  41. {
  42. m_data->m_mutex.lock();
  43. nvbio::Timer timer;
  44. timer.start();
  45. // fetch the output
  46. nvbio::io::SequenceDataHost* h_read_data = context.output<nvbio::io::SequenceDataHost>();
  47. const int ret = nvbio::io::next( DNA_N, h_read_data, m_data->m_file, m_data->m_max_strings, m_data->m_max_bps );
  48. timer.stop();
  49. m_data->m_time += timer.seconds();
  50. m_data->m_reads += h_read_data->size();
  51. m_data->m_bps += h_read_data->bps();
  52. if (h_read_data->max_sequence_len() > MAX_READ_LENGTH)
  53. {
  54. log_error(stderr, " maximum read length exceeded: %u > %u\n", h_read_data->max_sequence_len(), MAX_READ_LENGTH);
  55. return false;
  56. }
  57. log_verbose(stderr, "\r loaded reads [%llu, %llu] (%.1fM / %.2fG bps, %.1fK reads/s, %.1fM bps/s) ",
  58. m_data->m_reads,
  59. m_data->m_reads + h_read_data->size(),
  60. 1.0e-6f * (h_read_data->bps()),
  61. 1.0e-9f * (m_data->m_bps + h_read_data->bps()),
  62. m_data->m_time ? (1.0e-3f * (m_data->m_reads + h_read_data->size())) / m_data->m_time : 0.0f,
  63. m_data->m_time ? (1.0e-6f * (m_data->m_bps + h_read_data->bps() )) / m_data->m_time : 0.0f );
  64. log_debug_cont(stderr, "\n");
  65. m_data->m_mutex.unlock();
  66. return ret;
  67. }