Opened 11 years ago

Closed 10 years ago

#2422 closed enhancement (fixed)

Compilation with OpenCL fails when w32threads or os2threads are enabled

Reported by: jamal Owned by:
Priority: wish Component: avutil
Version: git-master Keywords: opencl
Cc: Blocked By:
Blocking: Reproduced by developer: yes
Analyzed by developer: no

Description

Mingw32-w64 example:

$ ./configure --enable-opencl

[...]

$ grep 'THREADS' config.mak
!HAVE_PTHREADS=yes
HAVE_W32THREADS=yes
!HAVE_OS2THREADS=yes
HAVE_THREADS=yes

$ grep 'OPENCL' config.mak
CONFIG_OPENCL=yes

$ make

[...]

CC      libavutil/opencl.o
D:/MinGW/msys/1.0/ffmpeg/src/libavutil/opencl.c: In function 'av_opencl_register_kernel_code':
D:/MinGW/msys/1.0/ffmpeg/src/libavutil/opencl.c:188:5: error: 'LOCK_OPENCL' undeclared (first use in this function)
D:/MinGW/msys/1.0/ffmpeg/src/libavutil/opencl.c:188:5: note: each undeclared identifier is reported only once for each function it appears in
D:/MinGW/msys/1.0/ffmpeg/src/libavutil/opencl.c:206:5: error: 'UNLOCK_OPENCL' undeclared (first use in this function)
D:/MinGW/msys/1.0/ffmpeg/src/libavutil/opencl.c: In function 'av_opencl_create_kernel':
D:/MinGW/msys/1.0/ffmpeg/src/libavutil/opencl.c:214:5: error: 'LOCK_OPENCL' undeclared (first use in this function)
D:/MinGW/msys/1.0/ffmpeg/src/libavutil/opencl.c:243:5: error: 'UNLOCK_OPENCL' undeclared (first use in this function)
D:/MinGW/msys/1.0/ffmpeg/src/libavutil/opencl.c: In function 'av_opencl_release_kernel':
D:/MinGW/msys/1.0/ffmpeg/src/libavutil/opencl.c:250:5: error: 'LOCK_OPENCL' undeclared (first use in this function)
D:/MinGW/msys/1.0/ffmpeg/src/libavutil/opencl.c:251:5: error: expected ';' before 'if'
D:/MinGW/msys/1.0/ffmpeg/src/libavutil/opencl.c:263:5: error: 'UNLOCK_OPENCL' undeclared (first use in this function)
D:/MinGW/msys/1.0/ffmpeg/src/libavutil/opencl.c:264:1: error: expected ';' before '}' token
D:/MinGW/msys/1.0/ffmpeg/src/libavutil/opencl.c:262:1: warning: label 'end' defined but not used [-Wunused-label]
D:/MinGW/msys/1.0/ffmpeg/src/libavutil/opencl.c: In function 'av_opencl_init':
D:/MinGW/msys/1.0/ffmpeg/src/libavutil/opencl.c:516:5: error: 'LOCK_OPENCL' undeclared (first use in this function)
D:/MinGW/msys/1.0/ffmpeg/src/libavutil/opencl.c:517:5: error: expected ';' before 'if'
D:/MinGW/msys/1.0/ffmpeg/src/libavutil/opencl.c:545:5: error: 'UNLOCK_OPENCL' undeclared (first use in this function)
D:/MinGW/msys/1.0/ffmpeg/src/libavutil/opencl.c:546:5: error: expected ';' before 'return'
D:/MinGW/msys/1.0/ffmpeg/src/libavutil/opencl.c:515:24: warning: unused variable 'opt_device_entry' [-Wunused-variable]
D:/MinGW/msys/1.0/ffmpeg/src/libavutil/opencl.c:514:24: warning: unused variable 'opt_platform_entry' [-Wunused-variable]
D:/MinGW/msys/1.0/ffmpeg/src/libavutil/opencl.c: In function 'av_opencl_uninit':
D:/MinGW/msys/1.0/ffmpeg/src/libavutil/opencl.c:553:5: error: unknown type name'LOCK_OPENCL'
D:/MinGW/msys/1.0/ffmpeg/src/libavutil/opencl.c:554:12: error: expected '=', ',', ';', 'asm' or '__attribute__' before '.' token
D:/MinGW/msys/1.0/ffmpeg/src/libavutil/opencl.c:587:5: error: 'UNLOCK_OPENCL' undeclared (first use in this function)
D:/MinGW/msys/1.0/ffmpeg/src/libavutil/opencl.c:588:1: error: expected ';' before '}' token
D:/MinGW/msys/1.0/ffmpeg/src/libavutil/opencl.c: At top level:
D:/MinGW/msys/1.0/ffmpeg/src/libavutil/opencl.c:266:12: warning: 'init_opencl_env' defined but not used [-Wunused-function]
D:/MinGW/msys/1.0/ffmpeg/src/libavutil/opencl.c: In function 'av_opencl_init':
D:/MinGW/msys/1.0/ffmpeg/src/libavutil/opencl.c:547:1: error: control reaches end of non-void function [-Werror=return-type]
cc1.exe: some warnings being treated as errors
make: *** [libavutil/opencl.o] Error 1

LOCK_OPENCL and UNLOCK_OPENCL are only defined when compiling with pthreads, or no threading at all.

I sent an email to ffmpeg-devel with a possible way to deal with this, but I'm opening a ticket anyway to keep track of this problem.

Change History (7)

comment:1 by Roger Pack, 11 years ago

with pthreads it works?

comment:2 by highgpd, 11 years ago

It is because I use a atomic_opencl_lock to make sure that the "opencl_ctx" can be accessed by only one thread at the same time, and it is require pthreads I think. If disable the pthreads, there will be no "static pthread_mutex_t atomic_opencl_lock = PTHREAD_MUTEX_INITIALIZER;", so is there any other better way to implement it?

in reply to:  1 comment:3 by highgpd, 11 years ago

Replying to rogerdpack:

with pthreads it works?

I think it should work, I tested on my computer

in reply to:  2 comment:4 by Carl Eugen Hoyos, 11 years ago

Replying to highgod:

If disable the pthreads, there will be no "static pthread_mutex_t atomic_opencl_lock = PTHREAD_MUTEX_INITIALIZER;", so is there any other better way to implement it?

I don't know but this is not the important point about this issue (imo):
configure currently does not fail for --enable-opencl if pthreads is not available, please fix the conditions for opencl in configure so that it already fails when configuring, not later at compile time.

(I suspect that you should use the functions from libavutil/atomic.h but maybe that does not work with opencl?)

comment:5 by Carl Eugen Hoyos, 11 years ago

Priority: importantwish
Reproduced by developer: set
Status: newopen
Type: defectenhancement

configure now tells the user that opencl does not work with Windows native threads, making opencl work with --enable-w32threads is a feature request.

comment:6 by Carl Eugen Hoyos, 10 years ago

I believe this was fixed by Matt Oliver in 1ccd1a38

comment:7 by Carl Eugen Hoyos, 10 years ago

Resolution: fixed
Status: openclosed
Note: See TracTickets for help on using tickets.