Skip to content

Commit

Permalink
[Stack] Allow the the ulimit stack size less than expected (#195)
Browse files Browse the repository at this point in the history
* .

* .
  • Loading branch information
yaoyaoding committed Apr 28, 2023
1 parent af3d412 commit 81eb7a2
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions python/hidet/utils/stack_limit.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,23 @@
"""
Allow more stack space and recursion depth for python.
"""
from typing import Tuple
import warnings
import sys
import resource

# allow up to 128MB stack space
resource.setrlimit(resource.RLIMIT_STACK, (2**29, -1))
# allow up to 512 MiB stack space
expected_stack_size = 2**29 # 512 MiB
stack_limit: Tuple[int, int] = resource.getrlimit(resource.RLIMIT_STACK)
if stack_limit[1] != resource.RLIM_INFINITY and stack_limit[1] < expected_stack_size:
warnings.warn(
f'The hard limit for stack size is too small ({stack_limit[1] / 2**20:.1f} MiB), '
f'we recommend to increase it to {expected_stack_size / 2**20:.1f} MiB. '
'If you are the root user on Linux OS, you could refer to `man limits.conf` to increase this limit.'
)
resource.setrlimit(resource.RLIMIT_STACK, (stack_limit[1], stack_limit[1]))
else:
resource.setrlimit(resource.RLIMIT_STACK, (expected_stack_size, stack_limit[1]))

# allow up to 10^5 recursive python calls, increase this when needed
sys.setrecursionlimit(100000)

0 comments on commit 81eb7a2

Please sign in to comment.