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

Suppress automatic GIL acquire to avoid deadlock #3037

Merged
merged 2 commits into from
Oct 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
- PR #3004: Remove Single Process Multi GPU (SPMG) code

## Bug Fixes
- PR #3037: Avoid logging deadlock in multi-threaded C code
- PR #2983: Fix seeding of KISS99 RNG
- PR #3011: Fix unused initialize_embeddings parameter in Barnes-Hut t-SNE
- PR #3008: Check number of columns in check_array validator
Expand Down
35 changes: 28 additions & 7 deletions python/cuml/common/logger.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ level_critical = CUML_LEVEL_CRITICAL
"""Disables all log messages"""
level_off = CUML_LEVEL_OFF

cdef void _log_callback(int lvl, const char * msg) with gil:
cdef void _log_callback(int lvl, const char * msg) nogil:
"""
Default spdlogs callback function to redirect logs correctly to sys.stdout

Expand All @@ -86,14 +86,35 @@ cdef void _log_callback(int lvl, const char * msg) with gil:
msg : char *
Message to be logged
"""
print(msg.decode('utf-8'), end='')
with gil:
print(msg.decode('utf-8'), end='')

cdef void _log_flush() with gil:

cdef void _nogil_log_callback(int lvl, const char * msg) nogil:
"""
Wrapper for _log_callback to explicitly disable Cython's automatic GIL
acquire
"""
with nogil:
_log_callback(lvl, msg)


cdef void _log_flush() nogil:
"""
Default spdlogs callback function to flush logs
"""
if sys.stdout is not None:
sys.stdout.flush()
with gil:
if sys.stdout is not None:
sys.stdout.flush()


cdef void _nogil_log_flush() nogil:
"""
Wrapper for _log_flush to explicitly disable Cython's automatic GIL
acquire
"""
with nogil:
_log_flush()


class LogLevelSetter:
Expand Down Expand Up @@ -345,5 +366,5 @@ def flush():


# Set callback functions to handle redirected sys.stdout in Python
Logger.get().setCallback(_log_callback)
Logger.get().setFlush(_log_flush)
Logger.get().setCallback(_nogil_log_callback)
Logger.get().setFlush(_nogil_log_flush)