nvcodec: Drop system installed cuda.h dependency

... and add our stub cuda header.

Newly introduced stub cuda.h file is defining minimal types in order to
build nvcodec plugin without system installed CUDA toolkit dependency.
This will make cross-compile possible.
This commit is contained in:
Seungha Yang 2019-07-23 09:40:24 +09:00
parent a2ada54265
commit 367e742e5d
3 changed files with 105 additions and 65 deletions

View file

@ -12,70 +12,13 @@ nvdec_sources = [
'gstcuvidloader.c',
]
use_nvcodec_gl = false
if get_option('nvcodec').disabled()
subdir_done()
endif
plugin_incdirs = [configinc, include_directories('./stub')]
extra_c_args = []
cuda_dep = dependency('', required : false)
cuda_header_dep = dependency('', required : false)
cuda_incdir = ''
nvcodec_option = get_option('nvcodec')
if nvcodec_option.disabled()
subdir_done()
endif
cuda_versions = [
'10.1',
'10.0',
'9.2',
'9.1',
'9.0',
'8.0',
'7.5',
'7.0',
'6.5',
]
cuda_ver = ''
cuda_dep = dependency('cuda', required:false)
if cuda_dep.found()
cuda_ver = cuda_dep.version()
endif
# FIXME: use break syntax when we use meson >= '0.49'
foreach v : cuda_versions
if cuda_ver == ''
cuda_dep = dependency('cuda-' + v, required: false)
if cuda_dep.found()
cuda_ver = v
endif
endif
endforeach
if cuda_dep.found()
if cc.has_header('cuda.h', dependencies: cuda_dep)
cuda_header_dep = cuda_dep.partial_dependency(compile_args : true, includes : true)
endif
endif
if not cuda_header_dep.found()
cuda_root = run_command(python3, '-c', 'import os; print(os.environ.get("CUDA_PATH"))').stdout().strip()
if cuda_root != '' and cuda_root != 'None'
cuda_incdir = join_paths (cuda_root, 'include')
if cc.has_header('cuda.h', args: '-I' + cuda_incdir)
cuda_header_dep = declare_dependency(include_directories: include_directories(cuda_incdir))
endif
endif
endif
if not cuda_header_dep.found()
if nvcodec_option.enabled()
error('The nvcodec plugin was enabled explicitly, but required CUDA dependency was not found.')
endif
subdir_done()
endif
if gstgl_dep.found()
# FIXME: make nvdec usable without OpenGL dependency
nvcodec_sources += nvdec_sources
@ -85,8 +28,8 @@ endif
gstnvcodec = library('gstnvcodec',
nvcodec_sources,
c_args : gst_plugins_bad_args + extra_c_args,
include_directories : [configinc],
dependencies : [gstbase_dep, gstvideo_dep, gstpbutils_dep, gstgl_dep, cuda_header_dep, gmodule_dep],
include_directories : plugin_incdirs,
dependencies : [gstbase_dep, gstvideo_dep, gstpbutils_dep, gstgl_dep, gmodule_dep],
install : true,
install_dir : plugins_install_dir,
)

97
sys/nvcodec/stub/cuda.h Normal file
View file

@ -0,0 +1,97 @@
/* CUDA stub header
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#ifndef __GST_CUDA_STUB_H__
#define __GST_CUDA_STUB_H__
#include <gst/gst.h>
G_BEGIN_DECLS
typedef gpointer CUcontext;
typedef gpointer CUgraphicsResource;
typedef gpointer CUstream;
typedef gpointer CUarray;
typedef guintptr CUdeviceptr;
typedef gint CUdevice;
typedef enum
{
CUDA_SUCCESS = 0,
} CUresult;
typedef enum
{
CU_MEMORYTYPE_HOST = 1,
CU_MEMORYTYPE_DEVICE = 2,
CU_MEMORYTYPE_ARRAY = 3,
CU_MEMORYTYPE_UNIFIED = 4,
} CUmemorytype;
typedef enum
{
CU_DEVICE_ATTRIBUTE_COMPUTE_CAPABILITY_MAJOR = 75,
CU_DEVICE_ATTRIBUTE_COMPUTE_CAPABILITY_MINOR = 76,
} CUdevice_attribute;
typedef enum
{
CU_GRAPHICS_REGISTER_FLAGS_READ_ONLY = 1,
CU_GRAPHICS_REGISTER_FLAGS_WRITE_DISCARD = 2
} CUgraphicsRegisterFlags;
typedef struct
{
gsize srcXInBytes;
gsize srcY;
CUmemorytype srcMemoryType;
gconstpointer srcHost;
CUdeviceptr srcDevice;
CUarray srcArray;
guint srcPitch;
gsize dstXInBytes;
gsize dstY;
CUmemorytype dstMemoryType;
gpointer dstHost;
CUdeviceptr dstDevice;
CUarray dstArray;
gsize dstPitch;
gsize WidthInBytes;
gsize Height;
} CUDA_MEMCPY2D;
#define CUDA_VERSION 10000
#define CUDAAPI
#define cuCtxCreate cuCtxCreate_v2
#define cuCtxDestroy cuCtxDestroy_v2
#define cuCtxPopCurrent cuCtxPopCurrent_v2
#define cuCtxPushCurrent cuCtxPushCurrent_v2
#define cuGraphicsResourceGetMappedPointer cuGraphicsResourceGetMappedPointer_v2
#define cuMemAlloc cuMemAlloc_v2
#define cuMemAllocPitch cuMemAllocPitch_v2
#define cuMemcpy2D cuMemcpy2D_v2
#define cuMemFree cuMemFree_v2
G_END_DECLS
#endif /* __GST_CUDA_STUB_H__ */

View file

@ -34,7 +34,7 @@ base_tests = [
[['elements/msdkh264enc.c'], not have_msdk, [msdk_dep]],
[['elements/mxfdemux.c']],
[['elements/mxfmux.c']],
[['elements/nvenc.c'], not cuda_header_dep.found(), [gmodule_dep, gstgl_dep]],
[['elements/nvenc.c'], false, [gmodule_dep, gstgl_dep]],
[['elements/pcapparse.c'], false, [libparser_dep]],
[['elements/pnm.c']],
[['elements/rtponvifparse.c']],