RISA
main.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of the RISA-library.
3  *
4  * Copyright (C) 2016 Helmholtz-Zentrum Dresden-Rossendorf
5  *
6  * RISA is free software: You can redistribute it and/or modify
7  * it under the terms of the GNU Lesser General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * RISA is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public License
17  * along with RISA. If not, see <http://www.gnu.org/licenses/>.
18  *
19  * Date: 30 November 2016
20  * Authors: Tobias Frust <t.frust@hzdr.de>
21  */
22 
23 
24 #include <risa/Filter/Filter.h>
27 #include <risa/Copy/D2H.h>
28 #include <risa/Copy/H2D.h>
29 #include <risa/Fan2Para/Fan2Para.h>
30 #include <risa/Masking/Masking.h>
34 #include <risa/Receiver/Receiver.h>
36 
37 #include <glados/Image.h>
38 #include <glados/ImageLoader.h>
39 #include <glados/ImageSaver.h>
42 
46 #include <glados/pipeline/Stage.h>
47 
49 
50 #include <boost/log/core.hpp>
51 #include <boost/log/trivial.hpp>
52 #include <boost/log/expressions.hpp>
53 
54 #include <iostream>
55 #include <cstdlib>
56 #include <exception>
57 #include <string>
58 #include <thread>
59 
60 #include <cuda_profiler_api.h>
61 
62 void initLog() {
63 #ifndef NDEBUG
64  boost::log::core::get()->set_filter(boost::log::trivial::severity >= boost::log::trivial::debug);
65 #else
66  boost::log::core::get()->set_filter(boost::log::trivial::severity >= boost::log::trivial::info);
67 #endif
68 }
69 
70 int main(int argc, char *argv[]) {
71 
72  //nvtxNameOsThreadA(pthread_self(), "Main");
73 
74  initLog();
75 
76  if(argc < 2){
77  BOOST_LOG_TRIVIAL(error) << "Call the program like this: ./example <path_to_config_file>";
78  return EXIT_FAILURE;
79  }
80  std::string configFile = argv[1];
81 
82  //TODO: read output path from config
83  auto outputPath = std::string { "Reco" };
84  auto inputPath = std::string { "Sino" };
85  auto prefix = std::string { "IMG" };
86  //auto configFile = std::string { "config.cfg" };
87  auto address = std::string { "10.0.0.10" };
88 
89  //using tiffLoader = glados::ImageLoader<glados::loaders::TIFF<glados::cuda::HostMemoryManager<unsigned short, glados::cuda::async_copy_policy>>>;
90  using offlineLoader = glados::ImageLoader<risa::OfflineLoader>;
91  using onlineReceiver = glados::ImageLoader<risa::Receiver>;
92  //using tiffSaver = glados::ImageSaver<glados::savers::TIFF<glados::cuda::HostMemoryManager<float, glados::cuda::async_copy_policy>>>;
93  using offlineSaver = glados::ImageSaver<risa::OfflineSaver>;
94 
96  using copyStageH2D = glados::pipeline::Stage<risa::cuda::H2D>;
98  using attenuationStage = glados::pipeline::Stage<risa::cuda::Attenuation>;
101  using backProjectionStage = glados::pipeline::Stage<risa::cuda::Backprojection>;
103  using copyStageD2H = glados::pipeline::Stage<risa::cuda::D2H>;
105 
106  int numberofDevices;
107  CHECK(cudaGetDeviceCount(&numberofDevices));
108 
109  try {
110  //set up pipeline
111  auto pipeline = glados::pipeline::Pipeline { };
112 
113  auto h2d = pipeline.create<copyStageH2D>(configFile);
114  auto reordering = pipeline.create<reorderingStage>(configFile);
115  auto attenuation = pipeline.create<attenuationStage>(configFile);
116  auto fan2Para = pipeline.create<fan2ParaStage>(configFile);
117  auto filter = pipeline.create<filterStage>(configFile);
118  auto backProjection = pipeline.create<backProjectionStage>(configFile);
119  //auto masking = pipeline.create<maskingStage>(configFile);
120  auto d2h = pipeline.create<copyStageD2H>(configFile);
121  auto sink = pipeline.create<sinkStage>(outputPath, prefix, configFile);
122  auto source = pipeline.create<sourceStage>(address, configFile);
123 
124  pipeline.connect(source, h2d);
125  pipeline.connect(h2d, reordering);
126  pipeline.connect(reordering, attenuation);
127  pipeline.connect(attenuation, fan2Para);
128  pipeline.connect(fan2Para, filter);
129  pipeline.connect(filter, backProjection);
130  //pipeline.connect(backProjection, masking);
131  pipeline.connect(backProjection, d2h);
132  pipeline.connect(d2h, sink);
133 
134  pipeline.run(source, h2d, reordering, attenuation, fan2Para, filter, backProjection, d2h, sink);
135  BOOST_LOG_TRIVIAL(info) << "Initialization finished.";
136 
137  for (auto i = 0; i < numberofDevices; i++){
138  CHECK(cudaSetDevice(i));
139  CHECK(cudaProfilerStart());
140  }
141 
142  pipeline.wait();
143 
144  for (auto i = 0; i < numberofDevices; i++){
145  CHECK(cudaSetDevice(i));
146  CHECK(cudaProfilerStop());
147  }
148 
149  } catch (const std::runtime_error& err) {
150  std::cerr << "=========================" << std::endl;
151  std::cerr << "A runtime error occurred: " << std::endl;
152  std::cerr << err.what() << std::endl;
153  std::cerr << "=========================" << std::endl;
154  }
155 
156  for(auto i = 0; i < numberofDevices; i++){
157  CHECK(cudaSetDevice(i));
158  CHECK(cudaDeviceSynchronize());
159  CHECK(cudaDeviceReset());
160  }
161  return 0;
162 }
void initLog()
Definition: main.cpp:62
#define CHECK(x)
Definition: Check.h:35
auto create(Args &&...args) -> std::shared_ptr< PipelineStage >
Definition: Pipeline.h:51
int main(int argc, char *argv[])
Definition: main.cpp:70