Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Profiling tests for Hagen #859

Merged
merged 59 commits into from
Oct 13, 2021
Merged
Show file tree
Hide file tree
Changes from 56 commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
9e5b6dd
start profiling
reinago Jul 29, 2021
b8de2cc
Call: profiling data getters
reinago Jul 29, 2021
75f2299
gpu profile queries
reinago Jul 29, 2021
c7b8b63
pipe profiling values to gui
braunms Jul 29, 2021
38dec04
weird stuff for gl perf, but cannot work like this
reinago Jul 29, 2021
6df368f
Merge remote-tracking branch 'reinago/profiling' into profiling
reinago Jul 29, 2021
6a8edc1
hiding GPU info since it's no use anyway ATM
reinago Jul 29, 2021
46a7637
moved profiling values from tooltip to context menu of calls
braunms Jul 29, 2021
85d1c26
Merge remote-tracking branch 'guido/profiling' into profiling
braunms Jul 29, 2021
9fe7c76
moved profiling info into call label
braunms Jul 30, 2021
86585f2
Merge remote-tracking branch 'origin/master' into profiling
reinago Jul 30, 2021
5fa5e47
operator precedence...
reinago Jul 30, 2021
106ae26
profiling info fine tuning
braunms Jul 30, 2021
5528b69
cheaper and less weird at runtime
reinago Aug 3, 2021
79f46cd
minor changes in gui call for profiling
braunms Aug 3, 2021
23eded0
fixed program flow a bit
reinago Aug 3, 2021
5278a6a
compile fix for disabled profiling
braunms Aug 4, 2021
d1c7844
moved implementation to PerformanceQueryManager
reinago Aug 4, 2021
c5b3408
merge, fixed ifdefs
reinago Aug 4, 2021
db97927
performance queries work
reinago Aug 4, 2021
f4b23c3
only remove gl calls
reinago Aug 4, 2021
a947b88
cleanup
reinago Aug 4, 2021
e6d7579
use HPET instead
reinago Aug 4, 2021
4f0bee1
Merge remote-tracking branch 'upstream/master' into profiling
braunms Aug 4, 2021
fe7bee2
Merge remote-tracking branch 'guido/profiling' into profiling
braunms Aug 4, 2021
8e47bf0
lazy init guard
reinago Aug 4, 2021
b7dd4cd
Merge remote-tracking branch 'origin/master' into profiling
reinago Aug 5, 2021
e7e4bc3
Merge branch 'master' into profiling
reinago Aug 31, 2021
f480853
performance averages and buffer refactored
reinago Aug 31, 2021
367d1c1
history also for GPU
reinago Sep 1, 2021
28dd755
cleanup / off-by-one
reinago Sep 1, 2021
e0ebe8a
prototype perf history graph
reinago Sep 2, 2021
0167667
even smaller footprint in code
reinago Sep 2, 2021
c2cd370
Merge remote-tracking branch 'reinago/profiling' into profiling
braunms Sep 2, 2021
c88e7ca
added implot as external dep
braunms Sep 2, 2021
20ce877
using implot fancyness
braunms Sep 2, 2021
c6af587
use current version (v0.11) of implot to have some bugs fixed
braunms Sep 3, 2021
9e16137
implot tweaking
reinago Sep 3, 2021
872d633
ContextToGL event callback fix for context outslot
reinago Sep 8, 2021
0a89b42
Merge branch 'master' into profiling
reinago Sep 8, 2021
b542e7c
cleanup
reinago Sep 8, 2021
06e2718
Profiling can be compiled out actually
reinago Sep 9, 2021
2198a98
I propose CallCapabilities
reinago Sep 9, 2021
b75874d
bug fixes
reinago Sep 9, 2021
cea528f
downgrade
reinago Sep 9, 2021
4a84100
cleanup
reinago Sep 9, 2021
f77c22a
another cleanup
reinago Sep 9, 2021
7894ace
Merge remote-tracking branch 'upstream/master' into profiling
braunms Sep 17, 2021
112af8f
fix merge
braunms Sep 17, 2021
0e51270
callrenderviewgl caps
reinago Sep 17, 2021
5547379
Merge branch 'master' into profiling
reinago Sep 23, 2021
4f9b23d
move GPU performance collection to its own service.
reinago Sep 23, 2021
4a55d08
cleanup
reinago Sep 23, 2021
7640f09
GL caps restored
reinago Sep 23, 2021
16a73a1
includes and ifdefs---
reinago Sep 24, 2021
c2b5cb2
cleanup
reinago Sep 29, 2021
eac3795
sneak in smaller screenies...?
reinago Sep 30, 2021
e2a3e93
dangling deps tripping ninja
reinago Oct 1, 2021
ca80e1a
adapted ospray plugin readme to reflect TBB changes
reinago Oct 4, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions cmake/megamol_options.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ if(ENABLE_CUDA)
set(CMAKE_CUDA_ARCHITECTURES FALSE)
endif()

option(ENABLE_PROFILING "Enable profiling code" OFF)
if (ENABLE_PROFILING)
add_compile_definitions(PROFILING)
endif()

# CUE
if (WIN32)
option(ENABLE_CUESDK "Enable CUE for highlighting hotkeys on Corsair Keyboards" OFF)
Expand Down
36 changes: 34 additions & 2 deletions core/include/mmcore/Call.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,16 @@
#endif /* (defined(_MSC_VER) && (_MSC_VER > 1000)) */

#include <memory>
#include <string>
#include <utility>
#include <vector>
#include "CallCapabilities.h"
#ifdef PROFILING
#include "CallProfiling.h"
#endif

#include "mmcore/api/MegaMolCore.std.h"


namespace megamol {
namespace core {

Expand Down Expand Up @@ -96,8 +102,23 @@ namespace core {
return this->className;
}

private:
const CallCapabilities& GetCapabilities() const {
return caps;
}

void SetCallbackNames(std::vector<std::string> names);

const std::string& GetCallbackName(uint32_t idx) const;

uint32_t GetCallbackCount() const {
return static_cast<uint32_t>(callback_names.size());
}

#ifdef PROFILING
const CallProfiling& GetProfiling() const { return profiling; }
#endif

private:
/** The callee connected by this call */
CalleeSlot *callee;

Expand All @@ -109,6 +130,17 @@ namespace core {
/** The function id mapping */
unsigned int *funcMap;

std::vector<std::string> callback_names;

inline static std::string err_out_of_bounds = "index out of bounds";

#ifdef PROFILING
friend class PerformanceQueryManager;

CallProfiling profiling;
#endif // PROFILING
protected:
CallCapabilities caps;
};


Expand Down
44 changes: 44 additions & 0 deletions core/include/mmcore/CallCapabilities.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Call.h
*
* Copyright (C) 2021 by Universitaet Stuttgart (VIS).
* Alle Rechte vorbehalten.
*/

#pragma once
#include <cstdint>

namespace megamol {
namespace core {

class CallCapabilities {
public:
enum caps {
REQUIRES_OPENGL = 1 << 0,
REQUIRES_CUDA = 1 << 1,
REQUIRES_OPENCL = 1 << 2,
REQUIRES_OPTIX = 1 << 3,
REQUIRES_OSPRAY = 1 << 4,
REQUIRES_VULKAN = 1 << 5
};

void RequireOpenGL();
void RequireCUDA();
void RequireOpenCL();
void RequireOptiX();
void RequireOSPRay();
void RequireVulkan();

bool OpenGLRequired() const;
bool CUDARequired() const;
bool OpenCLRequired() const;
bool OptiXRequired() const;
bool OSPRayRequired() const;
bool VulkanRequired() const;

private:
uint64_t cap_bits = 0;
};

}
}
54 changes: 54 additions & 0 deletions core/include/mmcore/CallProfiling.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#pragma once

#include <vector>
#include <array>
#include <map>
#include <string>

#include "PerformanceQueryManager.h"
#include "PerformanceHistory.h"

namespace megamol {
namespace core {

class Call;

class CallProfiling {
public:

CallProfiling();
~CallProfiling();

static uint32_t GetSampleHistoryLength();

double GetLastCPUTime(uint32_t func) const;
double GetAverageCPUTime(uint32_t func) const;
uint32_t GetNumCPUSamples(uint32_t func) const;
std::array<double, PerformanceHistory::buffer_length> GetCPUHistory(uint32_t func) const;

double GetLastGPUTime(uint32_t func) const;
double GetAverageGPUTime(uint32_t func) const;
uint32_t GetNumGPUSamples(uint32_t func) const;
std::array<double, PerformanceHistory::buffer_length> GetGPUHistory(uint32_t func) const;

void SetParent(Call *parent);

void ShutdownProfiling() const;

static void InitializeQueryManager();
static void CollectGPUPerformance();

private:
friend class Call;
friend class PerformanceQueryManager;

std::vector<PerformanceHistory> cpu_history;
std::vector<PerformanceHistory> gpu_history;
Call *parent_call = nullptr;
// this only works since the MegaMol build is static, otherwise a global round-robin could be a problem...
inline static PerformanceQueryManager *qm = nullptr;
inline const static std::string err_oob = "out of bounds";
};

}
}
66 changes: 66 additions & 0 deletions core/include/mmcore/PerformanceHistory.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#pragma once

#include <array>
#include <algorithm>

namespace megamol {
namespace core {

class PerformanceHistory {
public:
static const uint32_t buffer_length = 100;

PerformanceHistory();

void push_value(double val);

void reset();

double operator[](int index) const;

double last_value() const {
return time_buffer[offset(next_index, buffer_length - 1)];
}

double average() const {
return avg_time;
}

double buffer_average() const {
return window_avg;
}

uint32_t samples() const {
return num_samples;
}

std::array<double, buffer_length> copyHistory() const {
std::array<double, buffer_length> ret{};
std::copy(time_buffer.begin() + next_index, time_buffer.end(), ret.begin());
if (next_index > 0) {
std::copy_n(time_buffer.begin(), next_index, ret.begin() + (buffer_length - next_index));
}
return ret;
}

private:
static int offset(const int index, const int offset);

static int next_wrap(const int index) {
return offset(index, 1);
}
static int prev_wrap(const int index) {
return offset(index, -1);
}

std::array<double, buffer_length> time_buffer{};
int next_index = 0;
//int last_index = 0;
double avg_time = 0;
double window_total = 0;
double window_avg = 0;
uint32_t num_samples = 0;
};

}
}
45 changes: 45 additions & 0 deletions core/include/mmcore/PerformanceQueryManager.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#pragma once

#include <array>
#include <vector>

namespace megamol {
namespace core {
class Call;

class PerformanceQueryManager {
public:
PerformanceQueryManager();
~PerformanceQueryManager();
PerformanceQueryManager(const PerformanceQueryManager&);

bool Start(megamol::core::Call *c, uint32_t frameId, int32_t funcIdx);
void Stop(uint32_t frameId);
void Collect();

void AddCall(megamol::core::Call *c);
void RemoveCall(megamol::core::Call *c);

void ResetGLProfiling();
void AdvanceGLProfiling();

private:
struct query_info {
uint32_t id = 0;
bool started = false;
int32_t call_idx = -1;
int32_t func_idx = -1;

};
std::array<query_info, 2> query_infos;
std::vector<megamol::core::Call*> all_calls;
int32_t starting_call = -1, starting_func = -1;

int32_t next_query = 0;
int32_t running_query = -1;
};


} // namespace core
} // namespace megamol

8 changes: 8 additions & 0 deletions core/include/mmcore/factories/CallAutoDescription.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@

#include "CallDescription.h"

#include <string>
#include <vector>

namespace megamol::core::factories {

/**
Expand Down Expand Up @@ -50,6 +53,11 @@ namespace megamol::core::factories {
Call* CreateCall() const override {
T* c = new T();
c->SetClassName(this->ClassName());
std::vector<std::string> callbacks(this->FunctionCount());
for (uint32_t x = 0; x < this->FunctionCount(); ++x) {
callbacks[x] = this->FunctionName(x);
}
c->SetCallbackNames(callbacks);
return this->describeCall(c);
}

Expand Down
4 changes: 3 additions & 1 deletion core/include/mmcore/view/CallRender2DGL.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ namespace view {
class CallRender2DGL : public BaseCallRender<glowl::FramebufferObject, callrender2dgl_name, callrender2dgl_desc> {
public:
/** Ctor. */
CallRender2DGL(void) = default;
CallRender2DGL(void) : BaseCallRender<glowl::FramebufferObject, callrender2dgl_name, callrender2dgl_desc>() {
this->caps.RequireOpenGL();
}

/** Dtor. */
virtual ~CallRender2DGL(void) = default;
Expand Down
4 changes: 3 additions & 1 deletion core/include/mmcore/view/CallRender3DGL.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ namespace view {
: public BaseCallRender<glowl::FramebufferObject, callrender3dgl_name, callrender3dgl_desc> {
public:
/** Ctor. */
CallRender3DGL(void) = default;
CallRender3DGL(void) : BaseCallRender<glowl::FramebufferObject, callrender3dgl_name, callrender3dgl_desc>() {
this->caps.RequireOpenGL();
}

/** Dtor. */
virtual ~CallRender3DGL(void) = default;
Expand Down
18 changes: 14 additions & 4 deletions core/include/mmcore/view/CallRenderViewGL.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,23 @@ namespace view {

/**
* Call for rendering visual elements (from separate sources) into a single target, i.e.,
* FBO-based compositing and cluster display.
* FBO-based compositing and cluster display.
*/
using CallRenderViewGL = AbstractCallRenderView<glowl::FramebufferObject, callrenderviewgl_name, callrenderviewgl_desc>;
class CallRenderViewGL
: public AbstractCallRenderView<glowl::FramebufferObject, callrenderviewgl_name, callrenderviewgl_desc> {
public:
/** Ctor. */
CallRenderViewGL(void)
: AbstractCallRenderView<glowl::FramebufferObject, callrenderviewgl_name, callrenderviewgl_desc>() {
this->caps.RequireOpenGL();
}

/** Dtor. */
virtual ~CallRenderViewGL(void) = default;
};

/** Description class typedef */
typedef factories::CallAutoDescription<CallRenderViewGL>
CallRenderViewGLDescription;
typedef factories::CallAutoDescription<CallRenderViewGL> CallRenderViewGLDescription;


} /* end namespace view */
Expand Down
Loading