Skip to content

Commit d41bd80

Browse files
committed
Removed dependency on NVIDIA's oclUtil library
1 parent 98c91a4 commit d41bd80

File tree

10 files changed

+262
-87
lines changed

10 files changed

+262
-87
lines changed

mythtv/programs/mythgpucommflag/ffmpegvideodecoder.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,9 @@ void release_avf_buffer(struct AVCodecContext *c, AVFrame *pic)
8282

8383
VideoConsumer *nd = (VideoConsumer *)(c->opaque);
8484
(void)nd;
85-
// if (nd)
86-
// nd->DeLimboFrame((VideoFrame*)pic->opaque);
8785

88-
assert(pic->type == FF_BUFFER_TYPE_USER);
86+
if(pic->type != FF_BUFFER_TYPE_USER);
87+
return;
8988

9089
for (uint i = 0; i < 4; i++)
9190
pic->data[i] = NULL;

mythtv/programs/mythgpucommflag/mythgpucommflag.pro

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ INCLUDEPATH += $$SDK/shared/inc $$SDK/OpenCL/common/inc
1515
LIBPATH += $$SDK/shared/lib $$SDK/shared/lib/linux
1616
LIBPATH += $$SDK/OpenCL/common/lib
1717

18-
LIBS += -lOpenCL -loclUtil_x86_64 -lshrutil_x86_64 -lglut -lGLEW
18+
#LIBS += -lOpenCL -loclUtil_x86_64 -lshrutil_x86_64 -lglut -lGLEW
19+
LIBS += -lOpenCL -lglut -lGLEW
1920

2021
# Input
2122
HEADERS += commandlineparser.h

mythtv/programs/mythgpucommflag/openclaudioprocessor.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
#include "audioprocessor.h"
88
#include "audiopacket.h"
99

10+
#ifndef MIN
11+
#define MIN(x,y) ((x) < (y) ? (x) : (y))
12+
#endif
13+
1014
// Prototypes
1115
unsigned int nextPow2(unsigned int x);
1216
void OpenCLVolumeLevelCleanup(cl_mem **bufs);
@@ -259,7 +263,8 @@ FlagResults *OpenCLVolumeLevel(OpenCLDevice *dev, int16_t *samples, int size,
259263
if (ciErrNum != CL_SUCCESS)
260264
{
261265
LOG(VB_GPU, LOG_ERR, QString("Error running kernel %1: %2 (%3)")
262-
.arg(kern[0].entry) .arg(ciErrNum) .arg(oclErrorString(ciErrNum)));
266+
.arg(kern[0].entry) .arg(ciErrNum)
267+
.arg(openCLErrorString(ciErrNum)));
263268
delete memBufs;
264269
return NULL;
265270
}
@@ -273,7 +278,8 @@ FlagResults *OpenCLVolumeLevel(OpenCLDevice *dev, int16_t *samples, int size,
273278
if (ciErrNum != CL_SUCCESS)
274279
{
275280
LOG(VB_GPU, LOG_ERR, QString("Error running kernel %1: %2 (%3)")
276-
.arg(kern[1].entry) .arg(ciErrNum) .arg(oclErrorString(ciErrNum)));
281+
.arg(kern[1].entry) .arg(ciErrNum)
282+
.arg(openCLErrorString(ciErrNum)));
277283
delete memBufs;
278284
return NULL;
279285
}
@@ -285,7 +291,8 @@ FlagResults *OpenCLVolumeLevel(OpenCLDevice *dev, int16_t *samples, int size,
285291
if (ciErrNum != CL_SUCCESS)
286292
{
287293
LOG(VB_GPU, LOG_ERR, QString("Error running kernel %1: %2 (%3)")
288-
.arg(kern[2].entry) .arg(ciErrNum) .arg(oclErrorString(ciErrNum)));
294+
.arg(kern[2].entry) .arg(ciErrNum)
295+
.arg(openCLErrorString(ciErrNum)));
289296
delete memBufs;
290297
return NULL;
291298
}

mythtv/programs/mythgpucommflag/openclinterface.cpp

Lines changed: 206 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,14 @@
99
#include <strings.h>
1010

1111
#include "mythlogging.h"
12-
#ifdef MAX
13-
#undef MAX
14-
#endif
15-
#ifdef MIN
16-
#undef MIN
17-
#endif
18-
#include <oclUtils.h>
12+
13+
#include <CL/opencl.h>
1914
#include "openclinterface.h"
2015
#include "openglsupport.h"
2116

2217
void openCLDisplayImageFormats(cl_context context);
2318
void openCLPrintDevInfo(cl_device_id device);
19+
cl_int openCLGetPlatformID(cl_platform_id* clSelectedPlatformID);
2420

2521
cl_platform_id clSelectedPlatformID = NULL;
2622

@@ -31,11 +27,11 @@ OpenCLDeviceMap::OpenCLDeviceMap(void)
3127
m_valid = false;
3228

3329
// Get OpenCL platform ID for NVIDIA if avaiable, otherwise default
34-
cl_int ciErrNum = oclGetPlatformID (&clSelectedPlatformID);
30+
cl_int ciErrNum = openCLGetPlatformID(&clSelectedPlatformID);
3531
if (ciErrNum != CL_SUCCESS)
3632
{
3733
LOG(VB_GENERAL, LOG_ERR, QString("OpenCL Error # %1 (%2)")
38-
.arg(ciErrNum) .arg(oclErrorString(ciErrNum)));
34+
.arg(ciErrNum) .arg(openCLErrorString(ciErrNum)));
3935
return;
4036
}
4137

@@ -63,10 +59,6 @@ OpenCLDeviceMap::OpenCLDeviceMap(void)
6359

6460
LOG(VB_GENERAL, LOG_INFO, QString("OpenCL Version: %1") .arg(cBuffer));
6561

66-
// Log OpenCL SDK Revision #
67-
LOG(VB_GENERAL, LOG_INFO, QString("OpenCL SDK Revision: %1")
68-
.arg(OCL_SDKREVISION));
69-
7062
// Get and log OpenCL device info
7163
cl_uint ciDeviceCount;
7264
cl_device_id *devices;
@@ -152,10 +144,10 @@ void openCLDisplayImageFormats(cl_context context)
152144
{
153145
LOG(VB_GENERAL, LOG_INFO, QString("%1%2%3")
154146
.arg(i + 1, -6)
155-
.arg(oclImageFormatString(ImageFormats[i].
156-
image_channel_order), -16)
157-
.arg(oclImageFormatString(ImageFormats[i].
158-
image_channel_data_type), -22));
147+
.arg(openCLImageFormatString(ImageFormats[i].
148+
image_channel_order), -16)
149+
.arg(openCLImageFormatString(ImageFormats[i].
150+
image_channel_data_type), -22));
159151
}
160152
delete [] ImageFormats;
161153

@@ -180,10 +172,10 @@ void openCLDisplayImageFormats(cl_context context)
180172
{
181173
LOG(VB_GENERAL, LOG_INFO, QString("%1%2%3")
182174
.arg(i + 1, -6)
183-
.arg(oclImageFormatString(ImageFormats[i].
184-
image_channel_order), -16)
185-
.arg(oclImageFormatString(ImageFormats[i].
186-
image_channel_data_type), -22));
175+
.arg(openCLImageFormatString(ImageFormats[i].
176+
image_channel_order), -16)
177+
.arg(openCLImageFormatString(ImageFormats[i].
178+
image_channel_data_type), -22));
187179
}
188180
delete [] ImageFormats;
189181
}
@@ -689,6 +681,23 @@ void OpenCLDeviceNvidiaSpecific::Display(void)
689681
.arg(m_integratedMem ? "yes" : "no"));
690682
}
691683

684+
// Adapted from the NVIDIA GPY Computing SDK shrUtils.h
685+
int OpenCLDeviceNvidiaSpecific::ConvertSMVer2Cores(int major, int minor)
686+
{
687+
if (major == 1 && minor >= 0 && minor <= 3)
688+
return 8;
689+
690+
if (major == 2 && minor == 0)
691+
return 32;
692+
693+
if (major == 2 && minor == 1)
694+
return 48;
695+
696+
LOG(VB_GENERAL, LOG_ERR, QString("Unknown SM version %d.%d!")
697+
.arg(major) .arg(minor));
698+
return -1;
699+
}
700+
692701
OpenCLKernel *OpenCLKernel::Create(OpenCLDevice *device, QString entry,
693702
QString filename)
694703
{
@@ -742,7 +751,7 @@ OpenCLKernel *OpenCLKernel::Create(OpenCLDevice *device, QString entry,
742751
if (!kernel)
743752
{
744753
LOG(VB_GENERAL, LOG_ERR, QString("Error creating kernel %1: %2 (%3)")
745-
.arg(entryPt) .arg(ciErrNum) .arg(oclErrorString(ciErrNum)));
754+
.arg(entryPt) .arg(ciErrNum) .arg(openCLErrorString(ciErrNum)));
746755
clReleaseProgram(program);
747756
return NULL;
748757
}
@@ -774,6 +783,181 @@ OpenCLBuffers::~OpenCLBuffers()
774783
delete [] m_bufs;
775784
}
776785

786+
cl_int openCLGetPlatformID(cl_platform_id* clSelectedPlatformID)
787+
{
788+
char chBuffer[1024];
789+
cl_uint num_platforms;
790+
cl_platform_id* clPlatformIDs;
791+
cl_int ciErrNum;
792+
*clSelectedPlatformID = NULL;
793+
794+
// Get OpenCL platform count
795+
ciErrNum = clGetPlatformIDs (0, NULL, &num_platforms);
796+
if (ciErrNum != CL_SUCCESS)
797+
{
798+
LOG(VB_GENERAL, LOG_ERR, QString("Error %1 in clGetPlatformIDs")
799+
.arg(ciErrNum));
800+
return -1000;
801+
}
802+
803+
if (num_platforms == 0)
804+
{
805+
LOG(VB_GENERAL, LOG_ERR, "No OpenCL platform found!");
806+
return -2000;
807+
}
808+
809+
// if there's a platform or more, make space for ID's
810+
clPlatformIDs = new cl_platform_id[num_platforms];
811+
if (!clPlatformIDs)
812+
{
813+
LOG(VB_GENERAL, LOG_ERR,
814+
"Failed to allocate memory for cl_platform IDs!");
815+
return -3000;
816+
}
817+
818+
// get platform info for each platform and trap the NVIDIA platform if found
819+
ciErrNum = clGetPlatformIDs (num_platforms, clPlatformIDs, NULL);
820+
for(cl_uint i = 0; i < num_platforms; ++i)
821+
{
822+
ciErrNum = clGetPlatformInfo (clPlatformIDs[i], CL_PLATFORM_NAME, 1024,
823+
&chBuffer, NULL);
824+
if(ciErrNum == CL_SUCCESS)
825+
{
826+
if(strstr(chBuffer, "NVIDIA") != NULL)
827+
{
828+
*clSelectedPlatformID = clPlatformIDs[i];
829+
break;
830+
}
831+
}
832+
}
833+
834+
// default to zeroeth platform if NVIDIA not found
835+
if(*clSelectedPlatformID == NULL)
836+
{
837+
LOG(VB_GENERAL, LOG_WARNING, "NVIDIA OpenCL platform not found - "
838+
"defaulting to first platform!");
839+
*clSelectedPlatformID = clPlatformIDs[0];
840+
}
841+
842+
delete [] clPlatformIDs;
843+
return CL_SUCCESS;
844+
}
845+
846+
const char *openCLErrorString(cl_int error)
847+
{
848+
static const char* errorString[] = {
849+
"CL_SUCCESS",
850+
"CL_DEVICE_NOT_FOUND",
851+
"CL_DEVICE_NOT_AVAILABLE",
852+
"CL_COMPILER_NOT_AVAILABLE",
853+
"CL_MEM_OBJECT_ALLOCATION_FAILURE",
854+
"CL_OUT_OF_RESOURCES",
855+
"CL_OUT_OF_HOST_MEMORY",
856+
"CL_PROFILING_INFO_NOT_AVAILABLE",
857+
"CL_MEM_COPY_OVERLAP",
858+
"CL_IMAGE_FORMAT_MISMATCH",
859+
"CL_IMAGE_FORMAT_NOT_SUPPORTED",
860+
"CL_BUILD_PROGRAM_FAILURE",
861+
"CL_MAP_FAILURE",
862+
"",
863+
"",
864+
"",
865+
"",
866+
"",
867+
"",
868+
"",
869+
"",
870+
"",
871+
"",
872+
"",
873+
"",
874+
"",
875+
"",
876+
"",
877+
"",
878+
"",
879+
"CL_INVALID_VALUE",
880+
"CL_INVALID_DEVICE_TYPE",
881+
"CL_INVALID_PLATFORM",
882+
"CL_INVALID_DEVICE",
883+
"CL_INVALID_CONTEXT",
884+
"CL_INVALID_QUEUE_PROPERTIES",
885+
"CL_INVALID_COMMAND_QUEUE",
886+
"CL_INVALID_HOST_PTR",
887+
"CL_INVALID_MEM_OBJECT",
888+
"CL_INVALID_IMAGE_FORMAT_DESCRIPTOR",
889+
"CL_INVALID_IMAGE_SIZE",
890+
"CL_INVALID_SAMPLER",
891+
"CL_INVALID_BINARY",
892+
"CL_INVALID_BUILD_OPTIONS",
893+
"CL_INVALID_PROGRAM",
894+
"CL_INVALID_PROGRAM_EXECUTABLE",
895+
"CL_INVALID_KERNEL_NAME",
896+
"CL_INVALID_KERNEL_DEFINITION",
897+
"CL_INVALID_KERNEL",
898+
"CL_INVALID_ARG_INDEX",
899+
"CL_INVALID_ARG_VALUE",
900+
"CL_INVALID_ARG_SIZE",
901+
"CL_INVALID_KERNEL_ARGS",
902+
"CL_INVALID_WORK_DIMENSION",
903+
"CL_INVALID_WORK_GROUP_SIZE",
904+
"CL_INVALID_WORK_ITEM_SIZE",
905+
"CL_INVALID_GLOBAL_OFFSET",
906+
"CL_INVALID_EVENT_WAIT_LIST",
907+
"CL_INVALID_EVENT",
908+
"CL_INVALID_OPERATION",
909+
"CL_INVALID_GL_OBJECT",
910+
"CL_INVALID_BUFFER_SIZE",
911+
"CL_INVALID_MIP_LEVEL",
912+
"CL_INVALID_GLOBAL_WORK_SIZE",
913+
};
914+
915+
const int errorCount = sizeof(errorString) / sizeof(errorString[0]);
916+
917+
const int index = -error;
918+
919+
return (index >= 0 && index < errorCount) ? errorString[index] :
920+
"Unspecified Error";
921+
}
922+
923+
const char *openCLImageFormatString(cl_uint uiImageFormat)
924+
{
925+
switch (uiImageFormat)
926+
{
927+
// cl_channel_order
928+
case CL_R: return "CL_R";
929+
case CL_A: return "CL_A";
930+
case CL_RG: return "CL_RG";
931+
case CL_RA: return "CL_RA";
932+
case CL_RGB: return "CL_RGB";
933+
case CL_RGBA: return "CL_RGBA";
934+
case CL_BGRA: return "CL_BGRA";
935+
case CL_ARGB: return "CL_ARGB";
936+
case CL_INTENSITY: return "CL_INTENSITY";
937+
case CL_LUMINANCE: return "CL_LUMINANCE";
938+
939+
// cl_channel_type
940+
case CL_SNORM_INT8: return "CL_SNORM_INT8";
941+
case CL_SNORM_INT16: return "CL_SNORM_INT16";
942+
case CL_UNORM_INT8: return "CL_UNORM_INT8";
943+
case CL_UNORM_INT16: return "CL_UNORM_INT16";
944+
case CL_UNORM_SHORT_565: return "CL_UNORM_SHORT_565";
945+
case CL_UNORM_SHORT_555: return "CL_UNORM_SHORT_555";
946+
case CL_UNORM_INT_101010: return "CL_UNORM_INT_101010";
947+
case CL_SIGNED_INT8: return "CL_SIGNED_INT8";
948+
case CL_SIGNED_INT16: return "CL_SIGNED_INT16";
949+
case CL_SIGNED_INT32: return "CL_SIGNED_INT32";
950+
case CL_UNSIGNED_INT8: return "CL_UNSIGNED_INT8";
951+
case CL_UNSIGNED_INT16: return "CL_UNSIGNED_INT16";
952+
case CL_UNSIGNED_INT32: return "CL_UNSIGNED_INT32";
953+
case CL_HALF_FLOAT: return "CL_HALF_FLOAT";
954+
case CL_FLOAT: return "CL_FLOAT";
955+
956+
// unknown constant
957+
default: return "Unknown";
958+
}
959+
}
960+
777961
/*
778962
* vim:ts=4:sw=4:ai:et:si:sts=4
779963
*/

mythtv/programs/mythgpucommflag/openclinterface.h

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,7 @@
11
#ifndef _openclinterface_h
22
#define _openclinterface_h
33

4-
#ifdef MAX
5-
#undef MAX
6-
#endif
7-
#ifdef MIN
8-
#undef MIN
9-
#endif
10-
11-
#include <oclUtils.h>
4+
#include <CL/opencl.h>
125
#include <QString>
136
#include <QStringList>
147
#include <QList>
@@ -114,6 +107,7 @@ class OpenCLDeviceNvidiaSpecific : public OpenCLDeviceSpecific
114107
OpenCLDeviceNvidiaSpecific(OpenCLDevice *parent);
115108
~OpenCLDeviceNvidiaSpecific() {};
116109
void Display(void);
110+
int ConvertSMVer2Cores(int major, int minor);
117111

118112
// protected:
119113
cl_uint m_computeCapMajor;
@@ -175,6 +169,9 @@ class OpenCLBuffers : public QObject
175169

176170
typedef QPointer<OpenCLBuffers> OpenCLBufferPtr;
177171

172+
const char *openCLErrorString(cl_int error);
173+
const char *openCLImageFormatString(cl_uint uiImageFormat);
174+
178175
#endif
179176

180177
/*

0 commit comments

Comments
 (0)