Browse Source

mock getpid func
171c556f349e96400867de4937fe0c703849c0c8

zhukoff-pavel 6 months ago
parent
commit
9f71049204
2 changed files with 14 additions and 7 deletions
  1. 11 6
      build/scripts/compile_cuda.py
  2. 3 1
      build/ymake_conf.py

+ 11 - 6
build/scripts/compile_cuda.py

@@ -44,6 +44,10 @@ def main():
     if sys.argv[1] == '--mtime':
         mtime0 = sys.argv[2]
         cmd = 3
+    if sys.argv[cmd] == '--custom-pid':
+        custom_pid = sys.argv[4]
+        cmd = 5
+
     command = sys.argv[cmd:spl]
     cflags = sys.argv[spl + 1 :]
 
@@ -168,15 +172,16 @@ def main():
     # generated files (otherwise it also prepends tmpxft_{pid}_00000000-5), and
     # cicc derives the module name from its {input}.cpp1.ii file name.
     command += ['--keep', '--keep-dir', tempfile.mkdtemp(prefix='compile_cuda.py.')]
-    # nvcc generates symbols like __fatbinwrap_{len}_{basename}_{hash} where
+    # nvcc generates symbols like __fatbinwrap_{len}_{basename}_{hash}_{pid} where
     # {basename} is {input}.cpp1.ii with non-C chars translated to _, {len} is
-    # {basename} length, and {hash} is the hash of first exported symbol in
+    # {basename} length, {hash} is the hash of first exported symbol in
     # {input}.cpp1.ii if there is one, otherwise it is based on its modification
     # time (converted to string in the local timezone) and the current working
-    # directory.  To stabilize the names of these symbols we need to fix mtime,
-    # timezone, and cwd.
-    if mtime0:
-        os.environ['LD_PRELOAD'] = mtime0
+    # directory, and {pid} is a pid of nvcc process. To stabilize the names of
+    # these symbols we need to fix mtime, timezone, cwd and pid.
+    preload = [os.environ.get('LD_PRELOAD', ''), mtime0, custom_pid]
+    os.environ['LD_PRELOAD'] = ' '.join(filter(None, preload))
+
     os.environ['TZ'] = 'UTC0'  # POSIX fixed offset format.
     os.environ['TZDIR'] = '/var/empty'  # Against counterfeit /usr/share/zoneinfo/$TZ.
 

+ 3 - 1
build/ymake_conf.py

@@ -2423,10 +2423,12 @@ class Cuda(object):
 
     def print_macros(self):
         mtime = ' '
+        custom_pid = ' '
         if self.build.host_target[1].is_linux:
             mtime = ' --mtime ${tool:"tools/mtime0"} '
+            custom_pid = '--custom-pid ${tool:"tools/custom_pid"} '
         if not self.cuda_use_clang.value:
-            cmd = '$YMAKE_PYTHON ${input:"build/scripts/compile_cuda.py"}' + mtime + '$NVCC_OLD $NVCC_STD $NVCC_FLAGS -c ${input:SRC} -o ${output;suf=${OBJ_SUF}${NVCC_OBJ_EXT}:SRC} ${pre=-I:_C__INCLUDE} --cflags $C_FLAGS_PLATFORM $CXXFLAGS $NVCC_STD $NVCC_CFLAGS $SRCFLAGS ${input;hide:"build/platform/cuda/cuda_runtime_include.h"} $NVCC_ENV $CUDA_HOST_COMPILER_ENV ${kv;hide:"p CC"} ${kv;hide:"pc light-green"}'  # noqa E501
+            cmd = '$YMAKE_PYTHON ${input:"build/scripts/compile_cuda.py"}' + mtime + custom_pid + '$NVCC_OLD $NVCC_STD $NVCC_FLAGS -c ${input:SRC} -o ${output;suf=${OBJ_SUF}${NVCC_OBJ_EXT}:SRC} ${pre=-I:_C__INCLUDE} --cflags $C_FLAGS_PLATFORM $CXXFLAGS $NVCC_STD $NVCC_CFLAGS $SRCFLAGS ${input;hide:"build/platform/cuda/cuda_runtime_include.h"} $NVCC_ENV $CUDA_HOST_COMPILER_ENV ${kv;hide:"p CC"} ${kv;hide:"pc light-green"}'  # noqa E501
         else:
             cmd = '$CXX_COMPILER_OLD --cuda-path=$CUDA_ROOT $C_FLAGS_PLATFORM -c ${input:SRC} -o ${output;suf=${OBJ_SUF}${NVCC_OBJ_EXT}:SRC} ${pre=-I:_C__INCLUDE} $CXXFLAGS $SRCFLAGS $TOOLCHAIN_ENV ${kv;hide:"p CU"} ${kv;hide:"pc green"}'  # noqa E501