gen_linux.sh 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #!/bin/bash
  2. # This script is intended to run inside the go generate
  3. # working directory must be ../llm/llama.cpp
  4. set -ex
  5. set -o pipefail
  6. echo "Starting linux generate script"
  7. if [ -z "${CUDACXX}" -a -x /usr/local/cuda/bin/nvcc ] ; then
  8. export CUDACXX=/usr/local/cuda/bin/nvcc
  9. fi
  10. source $(dirname $0)/gen_common.sh
  11. init_vars
  12. git_module_setup
  13. apply_patches
  14. CMAKE_DEFS="-DLLAMA_CUBLAS=on -DCMAKE_POSITION_INDEPENDENT_CODE=on -DLLAMA_NATIVE=off -DLLAMA_AVX=on -DLLAMA_AVX2=off -DLLAMA_AVX512=off -DLLAMA_FMA=off -DLLAMA_F16C=off ${CMAKE_DEFS}"
  15. BUILD_DIR="gguf/build/cuda"
  16. LIB_DIR="${BUILD_DIR}/lib"
  17. mkdir -p ../../dist/
  18. build
  19. # TODO - explore mechanism to soften the hard cuda dependency on linux
  20. # by conditionally building some archive here that aggregates the cuda libs if present
  21. # so that the cgo flags link this intermediate archive instead of the underlying cuda libs
  22. #
  23. # gcc -fPIC -g -shared -o ${LIB_DIR}/libcuda_server.so \
  24. # -Wl,--whole-archive \
  25. # ${BUILD_DIR}/examples/server/CMakeFiles/ext_server.dir/server.cpp.o \
  26. # ${BUILD_DIR}/common/libcommon.a \
  27. # ${BUILD_DIR}/libllama.a \
  28. # ${BUILD_DIR}/examples/llava/libllava_static.a \
  29. # -Wl,--no-whole-archive \
  30. # -lrt -lpthread -ldl -lstdc++ -lm \
  31. # /usr/local/cuda/lib64/libcudart_static.a \
  32. # /usr/local/cuda/lib64/libcublas_static.a \
  33. # /usr/local/cuda/lib64/libcublasLt_static.a \
  34. # /usr/local/cuda/lib64/libcudadevrt.a \
  35. # /usr/local/cuda/lib64/libculibos.a
  36. if [ -z "${ROCM_PATH}" ] ; then
  37. # Try the default location in case it exists
  38. ROCM_PATH=/opt/rocm
  39. fi
  40. if [ -z "${CLBlast_DIR}" ] ; then
  41. # Try the default location in case it exists
  42. if [ -d /usr/lib/cmake/CLBlast ]; then
  43. export CLBlast_DIR=/usr/lib/cmake/CLBlast
  44. fi
  45. fi
  46. BUILD_DIR="gguf/build/rocm"
  47. LIB_DIR="${BUILD_DIR}/lib"
  48. mkdir -p ${LIB_DIR}
  49. # Ensure we have at least one file present for the embed
  50. touch ${LIB_DIR}/.generated
  51. if [ -d "${ROCM_PATH}" ] ; then
  52. echo "Building ROCm"
  53. init_vars
  54. CMAKE_DEFS="-DCMAKE_POSITION_INDEPENDENT_CODE=on -DCMAKE_VERBOSE_MAKEFILE=on -DLLAMA_HIPBLAS=on -DCMAKE_C_COMPILER=$ROCM_PATH/llvm/bin/clang -DCMAKE_CXX_COMPILER=$ROCM_PATH/llvm/bin/clang++ -DAMDGPU_TARGETS='gfx803;gfx900;gfx906:xnack-;gfx908:xnack-;gfx90a:xnack+;gfx90a:xnack-;gfx1010;gfx1012;gfx1030;gfx1100;gfx1101;gfx1102' -DGPU_TARGETS='gfx803;gfx900;gfx906:xnack-;gfx908:xnack-;gfx90a:xnack+;gfx90a:xnack-;gfx1010;gfx1012;gfx1030;gfx1100;gfx1101;gfx1102'"
  55. CMAKE_DEFS="-DLLAMA_ACCELERATE=on -DLLAMA_NATIVE=off -DLLAMA_AVX=on -DLLAMA_AVX2=off -DLLAMA_AVX512=off -DLLAMA_FMA=off -DLLAMA_F16C=off ${CMAKE_DEFS}"
  56. build
  57. gcc -fPIC -g -shared -o ${LIB_DIR}/librocm_server.so \
  58. -Wl,--whole-archive \
  59. ${BUILD_DIR}/examples/server/libext_server.a \
  60. ${BUILD_DIR}/common/libcommon.a \
  61. ${BUILD_DIR}/libllama.a \
  62. -Wl,--no-whole-archive \
  63. -lrt -lpthread -ldl -lstdc++ -lm \
  64. -L/opt/rocm/lib -L/opt/amdgpu/lib/x86_64-linux-gnu/ \
  65. -Wl,-rpath,/opt/rocm/lib,-rpath,/opt/amdgpu/lib/x86_64-linux-gnu/ \
  66. -lhipblas -lrocblas -lamdhip64 -lrocsolver -lamd_comgr -lhsa-runtime64 -lrocsparse -ldrm -ldrm_amdgpu
  67. fi