GGEMS  1.1
GPU GEant4-based Monte Carlo Simulations
GGEMSProfiler.cc
Go to the documentation of this file.
1 // ************************************************************************
2 // * This file is part of GGEMS. *
3 // * *
4 // * GGEMS is free software: you can redistribute it and/or modify *
5 // * it under the terms of the GNU General Public License as published by *
6 // * the Free Software Foundation, either version 3 of the License, or *
7 // * (at your option) any later version. *
8 // * *
9 // * GGEMS is distributed in the hope that it will be useful, *
10 // * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 // * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 // * GNU General Public License for more details. *
13 // * *
14 // * You should have received a copy of the GNU General Public License *
15 // * along with GGEMS. If not, see <https://www.gnu.org/licenses/>. *
16 // * *
17 // ************************************************************************
18 
33 
37 
39 : profiler_item_(nullptr)
40 {
41  ;
42 }
43 
47 
49 {
50  if (profiler_item_) {
51  delete profiler_item_;
52  profiler_item_ = nullptr;
53  }
54 }
55 
59 
60 void GGEMSProfiler::CallBackFunction(cl_event event, GGint event_command_exec_status, void* user_data)
61 {
62  if (event_command_exec_status == CL_COMPLETE) {
63  GGEMSProfiler* p = reinterpret_cast<GGEMSProfiler*>(user_data);
64  // Call back Function has to be thread safe!!!
65  mutex.lock();
66  p->AddProfilerItem(event);
67  mutex.unlock();
68  clReleaseEvent(event);
69  }
70 }
71 
75 
76 void GGEMSProfiler::AddProfilerItem(cl_event event)
77 {
78  if (!profiler_item_) {
79  profiler_item_ = new GGEMSProfilerItem(event);
80  }
81  else {
83  }
84 }
85 
89 
90 void GGEMSProfiler::HandleEvent(cl::Event event)
91 {
92  clRetainEvent(event());
93  event.setCallback(CL_COMPLETE, reinterpret_cast<void (CL_CALLBACK*)(cl_event, GGint, void*)>(GGEMSProfiler::CallBackFunction), this);
94 }
GGEMSProfiler::AddProfilerItem
void AddProfilerItem(cl_event event)
add new profiler item in profile
Definition: GGEMSProfiler.cc:76
GGEMSProfiler::profiler_item_
GGEMSProfilerItem * profiler_item_
Definition: GGEMSProfiler.hh:85
GGEMSProfiler
GGEMS class handling a specific profiler type.
Definition: GGEMSProfiler.hh:41
GGEMSProfiler::GGEMSProfiler
GGEMSProfiler(void)
GGEMSProfiler constructor.
Definition: GGEMSProfiler.cc:38
GGEMSProfiler::CallBackFunction
static void CallBackFunction(cl_event event, GGint event_command_exec_status, void *user_data)
call back function analyzing event
Definition: GGEMSProfiler.cc:60
GGint
#define GGint
Definition: GGEMSTypes.hh:224
GGEMSProfiler::HandleEvent
void HandleEvent(cl::Event event)
handle an OpenCL event in profile_name type
Definition: GGEMSProfiler.cc:90
GGEMSProfilerItem::UpdateEvent
void UpdateEvent(cl_event event)
Update elapsed time in OpenCL command.
Definition: GGEMSProfilerItem.cc:53
GGEMSProfilerItem
GGEMS handling a specific item profiler_item.
Definition: GGEMSProfilerItem.hh:53
GGEMSPrint.hh
Print a custom std::cout end std::cerr handling verbosity.
anonymous_namespace{GGEMSPrint.hh}::mutex
std::mutex mutex
Definition: GGEMSPrint.hh:43
GGEMSProfiler::~GGEMSProfiler
~GGEMSProfiler(void)
GGEMSProfiler destructor.
Definition: GGEMSProfiler.cc:48
GGEMSProfiler.hh
GGEMS class handling a specific profiler type.