nvidia/cuda: Log extra information when built for Debug

This commit is contained in:
Michael Fabian 'Xaymar' Dirks 2020-11-07 09:00:12 +01:00
parent 9332d9377c
commit 7b38114469
5 changed files with 80 additions and 5 deletions

View file

@ -19,6 +19,21 @@
#include "nvidia-cuda-context.hpp"
#include <stdexcept>
#include "util/util-logging.hpp"
#ifdef _DEBUG
#define ST_PREFIX "<%s> "
#define D_LOG_ERROR(x, ...) P_LOG_ERROR(ST_PREFIX##x, __FUNCTION_SIG__, __VA_ARGS__)
#define D_LOG_WARNING(x, ...) P_LOG_WARN(ST_PREFIX##x, __FUNCTION_SIG__, __VA_ARGS__)
#define D_LOG_INFO(x, ...) P_LOG_INFO(ST_PREFIX##x, __FUNCTION_SIG__, __VA_ARGS__)
#define D_LOG_DEBUG(x, ...) P_LOG_DEBUG(ST_PREFIX##x, __FUNCTION_SIG__, __VA_ARGS__)
#else
#define ST_PREFIX "<nvidia::cuda::context> "
#define D_LOG_ERROR(...) P_LOG_ERROR(ST_PREFIX __VA_ARGS__)
#define D_LOG_WARNING(...) P_LOG_WARN(ST_PREFIX __VA_ARGS__)
#define D_LOG_INFO(...) P_LOG_INFO(ST_PREFIX __VA_ARGS__)
#define D_LOG_DEBUG(...) P_LOG_DEBUG(ST_PREFIX __VA_ARGS__)
#endif
#ifdef WIN32
#ifdef _MSC_VER
@ -31,9 +46,14 @@
#endif
#endif
nvidia::cuda::context::context() : _cuda(::nvidia::cuda::cuda::get()), _ctx(), _has_device(false), _device() {}
nvidia::cuda::context::context() : _cuda(::nvidia::cuda::cuda::get()), _ctx(), _has_device(false), _device()
{
D_LOG_DEBUG("Initializating... (Addr: 0x%" PRIuPTR ")", this);
}
nvidia::cuda::context::~context()
{
D_LOG_DEBUG("Finalizing... (Addr: 0x%" PRIuPTR ")", this);
if (_has_device) {
_cuda->cuDevicePrimaryCtxRelease(_device);
}

View file

@ -25,8 +25,6 @@ namespace nvidia::cuda {
class context {
std::shared_ptr<::nvidia::cuda::cuda> _cuda;
::nvidia::cuda::context_t _ctx;
// Primary Device Context
bool _has_device;
::nvidia::cuda::device_t _device;

View file

@ -19,10 +19,27 @@
#include "nvidia-cuda-gs-texture.hpp"
#include "obs/gs/gs-helper.hpp"
#include "util/util-logging.hpp"
#ifdef _DEBUG
#define ST_PREFIX "<%s> "
#define D_LOG_ERROR(x, ...) P_LOG_ERROR(ST_PREFIX##x, __FUNCTION_SIG__, __VA_ARGS__)
#define D_LOG_WARNING(x, ...) P_LOG_WARN(ST_PREFIX##x, __FUNCTION_SIG__, __VA_ARGS__)
#define D_LOG_INFO(x, ...) P_LOG_INFO(ST_PREFIX##x, __FUNCTION_SIG__, __VA_ARGS__)
#define D_LOG_DEBUG(x, ...) P_LOG_DEBUG(ST_PREFIX##x, __FUNCTION_SIG__, __VA_ARGS__)
#else
#define ST_PREFIX "<nvidia::cuda::gstexture> "
#define D_LOG_ERROR(...) P_LOG_ERROR(ST_PREFIX __VA_ARGS__)
#define D_LOG_WARNING(...) P_LOG_WARN(ST_PREFIX __VA_ARGS__)
#define D_LOG_INFO(...) P_LOG_INFO(ST_PREFIX __VA_ARGS__)
#define D_LOG_DEBUG(...) P_LOG_DEBUG(ST_PREFIX __VA_ARGS__)
#endif
nvidia::cuda::gstexture::gstexture(std::shared_ptr<gs::texture> texture)
: _cuda(::nvidia::cuda::cuda::get()), _texture(texture), _resource(), _is_mapped(false), _pointer()
{
D_LOG_DEBUG("Initializating... (Addr: 0x%" PRIuPTR ")", this);
if (!texture)
throw std::invalid_argument("texture");
@ -63,6 +80,8 @@ nvidia::cuda::gstexture::gstexture(std::shared_ptr<gs::texture> texture)
nvidia::cuda::gstexture::~gstexture()
{
D_LOG_DEBUG("Finalizing... (Addr: 0x%" PRIuPTR ")", this);
unmap();
_cuda->cuGraphicsUnregisterResource(_resource);
}

View file

@ -19,9 +19,26 @@
#include "nvidia-cuda-memory.hpp"
#include <stdexcept>
#include "util/util-logging.hpp"
#ifdef _DEBUG
#define ST_PREFIX "<%s> "
#define D_LOG_ERROR(x, ...) P_LOG_ERROR(ST_PREFIX##x, __FUNCTION_SIG__, __VA_ARGS__)
#define D_LOG_WARNING(x, ...) P_LOG_WARN(ST_PREFIX##x, __FUNCTION_SIG__, __VA_ARGS__)
#define D_LOG_INFO(x, ...) P_LOG_INFO(ST_PREFIX##x, __FUNCTION_SIG__, __VA_ARGS__)
#define D_LOG_DEBUG(x, ...) P_LOG_DEBUG(ST_PREFIX##x, __FUNCTION_SIG__, __VA_ARGS__)
#else
#define ST_PREFIX "<nvidia::cuda::memory> "
#define D_LOG_ERROR(...) P_LOG_ERROR(ST_PREFIX __VA_ARGS__)
#define D_LOG_WARNING(...) P_LOG_WARN(ST_PREFIX __VA_ARGS__)
#define D_LOG_INFO(...) P_LOG_INFO(ST_PREFIX __VA_ARGS__)
#define D_LOG_DEBUG(...) P_LOG_DEBUG(ST_PREFIX __VA_ARGS__)
#endif
nvidia::cuda::memory::memory(size_t size) : _cuda(::nvidia::cuda::cuda::get()), _pointer(), _size(size)
{
D_LOG_DEBUG("Initializating... (Addr: 0x%" PRIuPTR ")", this);
::nvidia::cuda::result res = _cuda->cuMemAlloc(&_pointer, _size);
switch (res) {
case ::nvidia::cuda::result::SUCCESS:
@ -33,6 +50,8 @@ nvidia::cuda::memory::memory(size_t size) : _cuda(::nvidia::cuda::cuda::get()),
nvidia::cuda::memory::~memory()
{
D_LOG_DEBUG("Finalizing... (Addr: 0x%" PRIuPTR ")", this);
_cuda->cuMemFree(_pointer);
}
nvidia::cuda::device_ptr_t nvidia::cuda::memory::get()

View file

@ -19,9 +19,26 @@
#include "nvidia-cuda-stream.hpp"
#include <stdexcept>
#include "util/util-logging.hpp"
#ifdef _DEBUG
#define ST_PREFIX "<%s> "
#define D_LOG_ERROR(x, ...) P_LOG_ERROR(ST_PREFIX##x, __FUNCTION_SIG__, __VA_ARGS__)
#define D_LOG_WARNING(x, ...) P_LOG_WARN(ST_PREFIX##x, __FUNCTION_SIG__, __VA_ARGS__)
#define D_LOG_INFO(x, ...) P_LOG_INFO(ST_PREFIX##x, __FUNCTION_SIG__, __VA_ARGS__)
#define D_LOG_DEBUG(x, ...) P_LOG_DEBUG(ST_PREFIX##x, __FUNCTION_SIG__, __VA_ARGS__)
#else
#define ST_PREFIX "<nvidia::cuda::stream> "
#define D_LOG_ERROR(...) P_LOG_ERROR(ST_PREFIX __VA_ARGS__)
#define D_LOG_WARNING(...) P_LOG_WARN(ST_PREFIX __VA_ARGS__)
#define D_LOG_INFO(...) P_LOG_INFO(ST_PREFIX __VA_ARGS__)
#define D_LOG_DEBUG(...) P_LOG_DEBUG(ST_PREFIX __VA_ARGS__)
#endif
nvidia::cuda::stream::stream(::nvidia::cuda::stream_flags flags, int32_t priority) : _cuda(::nvidia::cuda::cuda::get())
{
D_LOG_DEBUG("Initializating... (Addr: 0x%" PRIuPTR ")", this);
nvidia::cuda::result res;
if (priority == 0) {
res = _cuda->cuStreamCreate(&_stream, flags);
@ -38,6 +55,8 @@ nvidia::cuda::stream::stream(::nvidia::cuda::stream_flags flags, int32_t priorit
nvidia::cuda::stream::~stream()
{
D_LOG_DEBUG("Finalizing... (Addr: 0x%" PRIuPTR ")", this);
_cuda->cuStreamDestroy(_stream);
}