Przeglądaj źródła

Avoid rocm runner and dependency clash

Putting the rocm symlink next to the runners is risky.  This moves
the payloads into a subdir to avoid potential clashes.
Daniel Hiltgen 1 rok temu
rodzic
commit
bc13da2bfe
3 zmienionych plików z 10 dodań i 6 usunięć
  1. 1 1
      gpu/amd_linux.go
  2. 8 4
      gpu/assets.go
  3. 1 1
      llm/generate/gen_linux.sh

+ 1 - 1
gpu/amd_linux.go

@@ -282,7 +282,7 @@ func AMDValidateLibDir() (string, error) {
 	}
 	}
 
 
 	// If we already have a rocm dependency wired, nothing more to do
 	// If we already have a rocm dependency wired, nothing more to do
-	rocmTargetDir := filepath.Join(payloadsDir, "rocm")
+	rocmTargetDir := filepath.Clean(filepath.Join(payloadsDir, "..", "rocm"))
 	if rocmLibUsable(rocmTargetDir) {
 	if rocmLibUsable(rocmTargetDir) {
 		return rocmTargetDir, nil
 		return rocmTargetDir, nil
 	}
 	}

+ 8 - 4
gpu/assets.go

@@ -23,7 +23,9 @@ func PayloadsDir() (string, error) {
 		if err != nil {
 		if err != nil {
 			return "", fmt.Errorf("failed to generate tmp dir: %w", err)
 			return "", fmt.Errorf("failed to generate tmp dir: %w", err)
 		}
 		}
-		payloadsDir = tmpDir
+		// We create a distinct subdirectory for payloads within the tmpdir
+		// This will typically look like /tmp/ollama3208993108/runners on linux
+		payloadsDir = filepath.Join(tmpDir, "runners")
 	}
 	}
 	return payloadsDir, nil
 	return payloadsDir, nil
 }
 }
@@ -32,10 +34,12 @@ func Cleanup() {
 	lock.Lock()
 	lock.Lock()
 	defer lock.Unlock()
 	defer lock.Unlock()
 	if payloadsDir != "" {
 	if payloadsDir != "" {
-		slog.Debug("cleaning up", "dir", payloadsDir)
-		err := os.RemoveAll(payloadsDir)
+		// We want to fully clean up the tmpdir parent of the payloads dir
+		tmpDir := filepath.Clean(filepath.Join(payloadsDir, ".."))
+		slog.Debug("cleaning up", "dir", tmpDir)
+		err := os.RemoveAll(tmpDir)
 		if err != nil {
 		if err != nil {
-			slog.Warn("failed to clean up", "dir", payloadsDir, "err", err)
+			slog.Warn("failed to clean up", "dir", tmpDir, "err", err)
 		}
 		}
 	}
 	}
 }
 }

+ 1 - 1
llm/generate/gen_linux.sh

@@ -185,7 +185,7 @@ if [ -d "${ROCM_PATH}" ]; then
     init_vars
     init_vars
     CMAKE_DEFS="${COMMON_CMAKE_DEFS} ${CMAKE_DEFS} -DLLAMA_HIPBLAS=on -DCMAKE_C_COMPILER=$ROCM_PATH/llvm/bin/clang -DCMAKE_CXX_COMPILER=$ROCM_PATH/llvm/bin/clang++ -DAMDGPU_TARGETS=$(amdGPUs) -DGPU_TARGETS=$(amdGPUs)"
     CMAKE_DEFS="${COMMON_CMAKE_DEFS} ${CMAKE_DEFS} -DLLAMA_HIPBLAS=on -DCMAKE_C_COMPILER=$ROCM_PATH/llvm/bin/clang -DCMAKE_CXX_COMPILER=$ROCM_PATH/llvm/bin/clang++ -DAMDGPU_TARGETS=$(amdGPUs) -DGPU_TARGETS=$(amdGPUs)"
     BUILD_DIR="${LLAMACPP_DIR}/build/linux/${ARCH}/rocm${ROCM_VARIANT}"
     BUILD_DIR="${LLAMACPP_DIR}/build/linux/${ARCH}/rocm${ROCM_VARIANT}"
-    EXTRA_LIBS="-L${ROCM_PATH}/lib -L/opt/amdgpu/lib/x86_64-linux-gnu/ -Wl,-rpath,\$ORIGIN/../rocm/ -lhipblas -lrocblas -lamdhip64 -lrocsolver -lamd_comgr -lhsa-runtime64 -lrocsparse -ldrm -ldrm_amdgpu"
+    EXTRA_LIBS="-L${ROCM_PATH}/lib -L/opt/amdgpu/lib/x86_64-linux-gnu/ -Wl,-rpath,\$ORIGIN/../../rocm/ -lhipblas -lrocblas -lamdhip64 -lrocsolver -lamd_comgr -lhsa-runtime64 -lrocsparse -ldrm -ldrm_amdgpu"
     build
     build
 
 
     # Record the ROCM dependencies
     # Record the ROCM dependencies