IPSDK  4_1_0_2
IPSDK : Image Processing Software Development Kit
CudaAlgorithmSrcMacros.h
Go to the documentation of this file.
1 // CudaAlgorithmSrcMacros.h:
3 // ------------------------------------
4 //
15 
16 #ifndef __IPSDKIMAGEPROCESSING_CUDAALGORITHMSRCMACROS_H__
17 #define __IPSDKIMAGEPROCESSING_CUDAALGORITHMSRCMACROS_H__
18 
19 //#include <IPSDKBaseProcessing/Algorithm/ProcessingAlgorithmSrcMacros.h>
20 //#include <IPSDKImageProcessing/Algorithm/Function/AlgorithmFunctionEfficiency.h>
22 
25 // Macro for GPU processing
26 // ===========================================================================//
27 
28 // ---- Test if a set of images is stored on GPU
31 #define IPSDKCUDA_CHECK_IMAGE_ON_GPU(image) \
32  if (!image->getImagePtr()->isGpuImage())\
33  return RetrievalResult(eRetrievalResultType::eRRT_Failed, image->getImagePtr()->getName() + " is not a GPU image");
34 
37 #define IPSDKCUDA_APPLY_CHECK_IMAGES_ON_GPU(r, data, IMAGE) IPSDKCUDA_CHECK_IMAGE_ON_GPU(IMAGE)
38 
39 
42 #define IPSDKGPU_CHECK_IMAGES_ON_GPU(IMAGES) BOOST_PP_SEQ_FOR_EACH(IPSDKCUDA_APPLY_CHECK_IMAGES_ON_GPU, _, IMAGES)
43 
44 //=========================================
45 //=========================================
52 #define IPSDKCUDA_TRY_TO_LAUNCH_PROCESS_ON_GPU() \
53  RetrievalResult res = tryToLaunchGpuProcess(priority, pProvider); \
54  if (res.getResult() != eRetrievalResultType::eRRT_NoMore) \
55  return res; \
56 // IPSDKBASEPROCESSING_LOG_WARN([eIPSDKBaseProcessingMessage::eErrorCouldNotLaunchGpuProcess] % getClassName())
57 
60 #define IPSDKCUDA_CHECK_PROCESS_CAN_BE_LAUNCHED_ON_GPU() \
61  ipBool bGpuCalculation = ipsdk::core::isGpuSupportActivated(); \
62  if (bGpuCalculation) { \
63  const std::vector<std::string>& vAttributeNames = getAttributeNameColl(); \
64  for (const std::string& attributeName : vAttributeNames) { \
65  const BaseAttribute& curAttribute = getAttribute(attributeName); \
66  if (curAttribute.isInit() && curAttribute.getAttributeType() == eAttributeType::eAT_ImageProcessing) { \
67  const BaseImageAttribute* pImageAttribute = static_cast<const ipsdk::imaproc::BaseImageAttribute*>(&curAttribute); \
68  if (pImageAttribute->getImageProcessingAttributeType() == eImageProcessingAttributeType::eIPAT_Image) { \
69  const ipsdk::image::BaseImage& gpuImage = static_cast<const ipsdk::image::BaseImage&>(pImageAttribute->getImage()); \
70  bGpuCalculation = bGpuCalculation && gpuImage.isGpuImage(); \
71  } \
72  } \
73  } \
74  } \
75 
76 
88 #define IPSDKCUDA_START_IMPLEMENT_LAUNCH_GPU_PROCESS(AlgoName) \
89  IPSDKCUDA_CHECK_PROCESS_CAN_BE_LAUNCHED_ON_GPU() \
90  if (bGpuCalculation) { \
91  typedef StaticProcessorDispatcher<AlgoName> ProcessorDispatcher; \
92  boost::shared_ptr<ProcessorDispatcher> pProcessorDispatcher(boost::make_shared<ProcessorDispatcher>());
93 
102 #define IPSDKCUDA_END_IMPLEMENT_LAUNCH_GPU_PROCESS() \
103  if (bInitRes.getResult() == true) { \
104  pProvider = pProcessorDispatcher; \
105  return RetrievalResult(eRetrievalResultType::eRRT_Successful); \
106  } \
107  else \
108  return RetrievalResult(eRetrievalResultType::eRRT_Failed, bInitRes.getMsg()); \
109  } \
110  return RetrievalResult(eRetrievalResultType::eRRT_NoMore);
111 
112 // ---- Test if a set of images is stored on GPU
113 
116 #define IPSDKCUDA_APPLY_CHECK_IMAGES_ON_GPU(r, data, IMAGE) IPSDKCUDA_CHECK_IMAGE_ON_GPU(IMAGE)
117 
118 
121 #define IPSDKCUDA_CHECK_IMAGES_ON_GPU(IMAGES) BOOST_PP_SEQ_FOR_EACH(IPSDKCUDA_APPLY_CHECK_IMAGES_ON_GPU, _, IMAGES)
122 
125 
126 
127 #endif // __IPSDKIMAGEPROCESSING_CUDAALGORITHMSRCMACROS_H__
Source part of macros set for image processing algorithm class implementation.