ggerganov / llama.cpp

LLM inference in C/C++
MIT License
60.95k stars 8.7k forks source link

Windows ROCm Build. #2843

Open LFL38 opened 10 months ago

LFL38 commented 10 months ago

Hello! I'm trying to compile llama.cpp for ROCm on windows, the problem I'm having is that CMake uses CC=/opt/rocm/llvm/bin/clang and CXX=/opt/rocm/llvm/bin/clang++ but on windows the locations are at "C:\Program Files\AMD\ROCm\5.5\bin\clang.exe" and "C:\Program Files\AMD\ROCm\5.5\bin\clang++.exe", is there any way for me to compile it with those locations? I tried on visual studio with cmake but it says "CC not recognized as internal or external command".

Engininja2 commented 10 months ago

You can set them as environment variables before running cmake, or you can pass them as arguments.

cmake -B build -G "Ninja" -DCMAKE_C_COMPILER=clang.exe -DCMAKE_CXX_COMPILER=clang++.exe -DLLAMA_HIPBLAS=ON -DCMAKE_BUILD_TYPE=Release

If the HIP bin folder isn't in your PATH I think passing them as their full quoted path would work, but I haven't tried building llama.cpp that way.

LFL38 commented 10 months ago

You can set them as environment variables before running cmake, or you can pass them as arguments.

cmake -B build -G "Ninja" -DCMAKE_C_COMPILER=clang.exe -DCMAKE_CXX_COMPILER=clang++.exe -DLLAMA_HIPBLAS=ON -DCMAKE_BUILD_TYPE=Release

If the HIP bin folder isn't in your PATH I think passing them as their full quoted path would work, but I haven't tried building llama.cpp that way.

Sorry but can you perhaps translate that guide into plain english? I'm quite new with cmake and building stuff from source, meaning I have no idea what to do. I did try cmake -B build -G "Ninja" -DCMAKE_C_COMPILER=clang.exe -DCMAKE_CXX_COMPILER=clang++.exe -DLLAMA_HIPBLAS=ON -DCMAKE_BUILD_TYPE=Release but that just prints "The source directory does not appear to contain CMakeLists.txt", and when I tried cmake .. -DLLAMA_HIPBLAS=ON it printed

Invalid character escape '\P'. Call Stack (most recent call first): CMakeLists.txt:2 (project)

Engininja2 commented 10 months ago

After trying it, even if you build llama.cpp on Windows without the HIP SDK bin folder in your path (C:\Program Files\AMD\ROCm\5.5\bin) the resulting executables won't run because they can't find the .dll files there. The first thing to do is to add that folder to your PATH environment variable. Then this should work from a Visual Studio command prompt.

set CC=clang.exe
set CXX=clang++.exe
cd your-llamacpp-folder
mkdir build
cd build
cmake .. -G "Ninja" -DLLAMA_HIPBLAS=ON -DCMAKE_BUILD_TYPE=Release -DAMDGPU_TARGETS=YourGPUTarget
cmake --build .

You need to pass -G "Ninja" (or slightly different commands with -G "Ninja Multi-Config") or else the Visual Studio cmake will try to use MSVC. The Release build type has to be passed to Ninja with Visual Studio otherwise it will build Debug which is unusably slow. Your GPU should be listed as supported by HIP SDK, not the runtime, though I think gfx1101, gfx1102, and gfx906 while not listed would also work, and you need to pass that LLVM target for your GPU in -DAMDGPU_TARGETS=. edit: typos in supported gfx archs

SlyEcho commented 10 months ago

The CMake file should be updated for Windows support. I noticed that the SDK configures an environment variable HIP_PATH or something when it is installed. We should just check there as well as in /opt/rocm. And maybe we could release Windows builds from CI like we do for CUDA...

earonesty commented 9 months ago

not sure if this is the right ticket, but i think it would be desirable for a build that can support both nvidia and rocm, if the libs are present, would be quite useful. maybe that's just opencl?

SlyEcho commented 9 months ago

The architecture doesn't support that. Some applications that use llama.cpp as a dynamic library can do it by having different versions of llama.dll to load.

halninethousand commented 7 months ago

I managed to get past the the binaries location but now I get the following error:

-- The C compiler identification is Clang 17.0.0 with GNU-like command-line -- The CXX compiler identification is Clang 17.0.0 with GNU-like command-line -- Detecting C compiler ABI info -- Detecting C compiler ABI info - failed -- Check for working C compiler: C:/Program Files/AMD/ROCm/5.5/bin/clang.exe -- Check for working C compiler: C:/Program Files/AMD/ROCm/5.5/bin/clang.exe - broken CMake Error at C:/Program Files/CMake/share/cmake-3.28/Modules/CMakeTestCCompiler.cmake:67 (message): The C compiler

"C:/Program Files/AMD/ROCm/5.5/bin/clang.exe"

is not able to compile a simple test program.

It fails with the following output:

Change Dir: 'C:/Users/Zhaba/Desktop/AI/llama.cpp/build/CMakeFiles/CMakeScratch/TryCompile-pn1xyp'

Run Build Command(s): C:/PROGRA~2/MICROS~2/2019/BUILDT~1/Common7/IDE/COMMON~1/MICROS~1/CMake/Ninja/ninja.exe -v cmTC_86c80
[1/2] C:\PROGRA~1\AMD\ROCm\5.5\bin\clang.exe    -MD -MT CMakeFiles/cmTC_86c80.dir/testCCompiler.c.obj -MF CMakeFiles\cmTC_86c80.dir\testCCompiler.c.obj.d -o CMakeFiles/cmTC_86c80.dir/testCCompiler.c.obj -c C:/Users/Zhaba/Desktop/AI/llama.cpp/build/CMakeFiles/CMakeScratch/TryCompile-pn1xyp/testCCompiler.c
[2/2] C:\WINDOWS\system32\cmd.exe /C "cd . && C:\PROGRA~1\AMD\ROCm\5.5\bin\clang.exe -fuse-ld=lld-link -nostartfiles -nostdlib  -Xlinker /subsystem:console CMakeFiles/cmTC_86c80.dir/testCCompiler.c.obj -o cmTC_86c80.exe -Xlinker /MANIFEST:EMBED -Xlinker /implib:cmTC_86c80.lib -Xlinker /pdb:cmTC_86c80.pdb -Xlinker /version:0.0   -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32 -loldnames  && cd ."
FAILED: cmTC_86c80.exe
C:\WINDOWS\system32\cmd.exe /C "cd . && C:\PROGRA~1\AMD\ROCm\5.5\bin\clang.exe -fuse-ld=lld-link -nostartfiles -nostdlib  -Xlinker /subsystem:console CMakeFiles/cmTC_86c80.dir/testCCompiler.c.obj -o cmTC_86c80.exe -Xlinker /MANIFEST:EMBED -Xlinker /implib:cmTC_86c80.lib -Xlinker /pdb:cmTC_86c80.pdb -Xlinker /version:0.0   -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32 -loldnames  && cd ."
lld-link: error: <root>: undefined symbol: mainCRTStartup
clang: error: linker command failed with exit code 1 (use -v to see invocation)
ninja: build stopped: subcommand failed.

CMake will not be able to correctly generate this project. Call Stack (most recent call first): CMakeLists.txt:2 (project)

sorasoras commented 6 months ago

I was able to compile and run everything on my 7900XTX desktop but failed with my 6700XT system.

SlyEcho commented 6 months ago

Interesting, I have the 7900XTX also now but it should not matter, though. Was it on Windows 10 or 11?

sorasoras commented 6 months ago

Hello! I'm trying to compile llama.cpp for ROCm on windows, the problem I'm having is that CMake uses CC=/opt/rocm/llvm/bin/clang and CXX=/opt/rocm/llvm/bin/clang++ but on windows the locations are at "C:\Program Files\AMD\ROCm\5.5\bin\clang.exe" and "C:\Program Files\AMD\ROCm\5.5\bin\clang++.exe", is there any way for me to compile it with those locations? I tried on visual studio with cmake but it says "CC not recognized as internal or external command".

I think i know the reason now, you need to add rocm/bin to the env as path, then it should work.

davtur19 commented 4 months ago

I tried to build it on Windows 11 with an rx 5700 and I get this error, I followed the steps listed here: https://github.com/ggerganov/llama.cpp?tab=readme-ov-file#hipblas I added rocm/bin to the path.

C:\Users\Davide\Downloads\aigpu\llama.cpp\build>cmake .. -G "Ninja" -DAMDGPU_TARGETS=gfx1010 -DLLAMA_HIPBLAS=ON -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_BUILD_TYPE=Release
-- The C compiler identification is Clang 17.0.0 with GNU-like command-line
-- The CXX compiler identification is Clang 17.0.0 with GNU-like command-line
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - failed
-- Check for working C compiler: /c/Program Files/AMD/ROCm/5.7/bin/clang.exe
-- Check for working C compiler: /c/Program Files/AMD/ROCm/5.7/bin/clang.exe - broken
CMake Error at /usr/share/cmake/Modules/CMakeTestCCompiler.cmake:67 (message):
  The C compiler

    "/c/Program Files/AMD/ROCm/5.7/bin/clang.exe"

  is not able to compile a simple test program.

  It fails with the following output:

    Change Dir: '/c/Users/Davide/Downloads/aigpu/llama.cpp/build/CMakeFiles/CMakeScratch/TryCompile-EtolSB'

    Run Build Command(s): "/c/Program Files/Microsoft Visual Studio/2022/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/Ninja/ninja.exe" -v cmTC_0092e
    ninja: error: '/c/Users/Davide/Downloads/aigpu/llama.cpp/build/CMakeFiles/CMakeScratch/TryCompile-EtolSB/testCCompiler.c', needed by 'CMakeFiles/cmTC_0092e.dir/testCCompiler.c.o', missing and no known rule to make it

  CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
  CMakeLists.txt:2 (project)

-- Configuring incomplete, errors occurred!

EDIT: NOW IT WORKS! I fixed it by installing a windows specific perl since I was using the one from msys2

EDIT 2: Now it built "correctly", but it doesn't work....

C:\Users\Davide\Downloads\aigpu\llama.cpp\build\bin>main.exe
Log start
main: build = 2105 (8e6a9d2d)
main: built with  for x86_64-pc-windows-msvc
main: seed  = 1707432747

rocBLAS error: Cannot read C:\Program Files\AMD\ROCm\5.7\bin\/rocblas/library/TensileLibrary.dat: No such file or directory for GPU arch : gfx1036

rocBLAS error: Could not initialize Tensile host:
regex_error(error_backref): The expression contained an invalid back reference.

EDIT 3: I think it detected my cpu integrated gpu, and this command should hide it set HIP_VISIBLE_DEVICES=1. By doing so, the program now shows me gfx1010. Also I think I need to compile rocblas to make it work on my gpu.

zbrkic commented 4 months ago

@davtur19 How did you fix it by installing perl? What does perl have to do with The C compiler ... is not able to compile a simple test program?

davtur19 commented 4 months ago

@zbrkic rocm to build requires perl apparently, or at least for the version I was trying to build

https://github.com/search?q=repo%3AROCm%2FROCm+perl&type=code

fyq163 commented 3 months ago

Hello, could you share which version of release do you use for hip blas?

davtur19 commented 3 months ago

@fyq163 I used the rocm-5.7.1 branch

ppgabe commented 3 months ago

Building with ROCm always comes with headaches, it would seem in my case! I've also tried this on Linux back then, same number of headaches. Rant aside, has anyone encountered this error? Can't open perl script ".//hipconfig.pl": No such file or directory

I'm on Windows 11, RX 6800 XT, using x64 Native Tools (VS 2022) with the latest HIP SDK installed. I've also installed Strawberry Perl (thanks to @davtur19) but it has not fixed the issue. rocm/bin is in PATH. hipconfig.pl does exist, I've checked!

C:\Users\----\----\AI\llama.cpp\build>cmake .. -G "Ninja" -DAMDGPU_TARGETS=gfx1030 -DLLAMA_HIPBLAS=ON -DCMAKE_C_COMPILER
=clang -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_BUILD_TYPE=Release
-- The C compiler identification is Clang 17.0.0 with GNU-like command-line
-- The CXX compiler identification is Clang 17.0.0 with GNU-like command-line
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: C:/Program Files/AMD/ROCm/5.7/bin/clang.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/Program Files/AMD/ROCm/5.7/bin/clang++.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found Git: C:/Program Files/Git/cmd/git.exe (found version "2.44.0.windows.1")
_: line 1: C:/Program: No such file or directory
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Failed
-- Check if compiler accepts -pthread
-- Check if compiler accepts -pthread - no
-- Looking for pthread_create in pthreads
-- Looking for pthread_create in pthreads - not found
-- Looking for pthread_create in pthread
-- Looking for pthread_create in pthread - not found
-- Found Threads: TRUE
CMake Deprecation Warning at C:/Program Files/AMD/ROCm/5.7/lib/cmake/hip/hip-config.cmake:20 (cmake_minimum_required):
  Compatibility with CMake < 3.5 will be removed from a future version of
  CMake.

  Update the VERSION argument <min> value or use a ...<max> suffix to tell
  CMake that the project does not need compatibility with older versions.
Call Stack (most recent call first):
  CMakeLists.txt:510 (find_package)

Can't open perl script ".//hipconfig.pl": No such file or directory
CMake Error at C:/Program Files/AMD/ROCm/5.7/lib/cmake/hip/hip-config.cmake:156 (message):
  Unexpected HIP_PLATFORM:
Call Stack (most recent call first):
  CMakeLists.txt:510 (find_package)

-- Configuring incomplete, errors occurred!
louwangzhiyuY commented 3 months ago

Building with ROCm always comes with headaches, it would seem in my case! I've also tried this on Linux back then, same number of headaches. Rant aside, has anyone encountered this error? Can't open perl script ".//hipconfig.pl": No such file or directory

I'm on Windows 11, RX 6800 XT, using x64 Native Tools (VS 2022) with the latest HIP SDK installed. I've also installed Strawberry Perl (thanks to @davtur19) but it has not fixed the issue. rocm/bin is in PATH. hipconfig.pl does exist, I've checked!

C:\Users\----\----\AI\llama.cpp\build>cmake .. -G "Ninja" -DAMDGPU_TARGETS=gfx1030 -DLLAMA_HIPBLAS=ON -DCMAKE_C_COMPILER
=clang -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_BUILD_TYPE=Release
-- The C compiler identification is Clang 17.0.0 with GNU-like command-line
-- The CXX compiler identification is Clang 17.0.0 with GNU-like command-line
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: C:/Program Files/AMD/ROCm/5.7/bin/clang.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/Program Files/AMD/ROCm/5.7/bin/clang++.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found Git: C:/Program Files/Git/cmd/git.exe (found version "2.44.0.windows.1")
_: line 1: C:/Program: No such file or directory
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Failed
-- Check if compiler accepts -pthread
-- Check if compiler accepts -pthread - no
-- Looking for pthread_create in pthreads
-- Looking for pthread_create in pthreads - not found
-- Looking for pthread_create in pthread
-- Looking for pthread_create in pthread - not found
-- Found Threads: TRUE
CMake Deprecation Warning at C:/Program Files/AMD/ROCm/5.7/lib/cmake/hip/hip-config.cmake:20 (cmake_minimum_required):
  Compatibility with CMake < 3.5 will be removed from a future version of
  CMake.

  Update the VERSION argument <min> value or use a ...<max> suffix to tell
  CMake that the project does not need compatibility with older versions.
Call Stack (most recent call first):
  CMakeLists.txt:510 (find_package)

Can't open perl script ".//hipconfig.pl": No such file or directory
CMake Error at C:/Program Files/AMD/ROCm/5.7/lib/cmake/hip/hip-config.cmake:156 (message):
  Unexpected HIP_PLATFORM:
Call Stack (most recent call first):
  CMakeLists.txt:510 (find_package)

-- Configuring incomplete, errors occurred!

may caused by the below error. Unexpected HIP_PLATFORM:

ppgabe commented 3 months ago

may caused by the below error. Unexpected HIP_PLATFORM:

That is pretty weird! I wonder what's causing the issue. gfx1030 should be supported, if that's the platform it's complaining about. Hmm...

louwangzhiyuY commented 3 months ago

may caused by the below error. Unexpected HIP_PLATFORM:

That is pretty weird! I wonder what's causing the issue. gfx1030 should be supported, if that's the platform it's complaining about. Hmm...

I meet same error as you are facing. it can be solved via install https://strawberryperl.com/

ppgabe commented 3 months ago

may caused by the below error. Unexpected HIP_PLATFORM:

That is pretty weird! I wonder what's causing the issue. gfx1030 should be supported, if that's the platform it's complaining about. Hmm...

I meet same error as you are facing. it can be solved via install https://strawberryperl.com/

I already Strawberry Perl and it sadly didn't fix the issue. But, I managed to get it working by fiddling with the code, specifically hipconfig from C:\Program Files\AMD\ROCm. I modified line 42 to direct to the ROCm bin directory and also removed the / from lines 45 and 50. hipcc seems to suffer from the same issue as well, so I did the same fix.

my $isWindows =  ($^O eq 'MSWin32' or $^O eq 'msys');
my $SCRIPT_DIR= 'C:\Program Files\AMD\ROCm\5.7\bin';
if ($USE_PERL_SCRIPT) {
    #Invoke hipconfig.pl
    my $HIPCONFIG_PERL=catfile($SCRIPT_DIR, 'hipconfig.pl');
    system($^X, $HIPCONFIG_PERL, @ARGV);
} else {
    $BIN_NAME="hipconfig.bin";
    if ($isWindows) {
        $BIN_NAME="hipconfig.bin.exe";
    }
    my $HIPCONFIG_BIN=catfile($SCRIPT_DIR, $BIN_NAME);
    if ( -e $HIPCONFIG_BIN ) {
        #Invoke hipconfig.bin
        system($HIPCONFIG_BIN, @ARGV);
    } else {
        print "hipconfig.bin not present; Install HIPCC binaries before proceeding";
        exit(-1);
    }
}

It compiled successfully after that. No problems running llama-bench.exe too.

llama-bench.exe -m Blue-Orchid-2x7b-Q4_K_M.gguf -p 3968 -n 128 -ngl 99
ggml_init_cublas: GGML_CUDA_FORCE_MMQ:   no
ggml_init_cublas: CUDA_USE_TENSOR_CORES: yes
ggml_init_cublas: found 1 ROCm devices:
  Device 0: AMD Radeon RX 6800 XT, compute capability 10.3, VMM: no
| model                          |       size |     params | backend    | ngl | test       |
    t/s |
| ------------------------------ | ---------: | ---------: | ---------- | --: | ---------- | ---------------: |
| llama 7B Q4_K - Medium         |   7.25 GiB |    12.88 B | ROCm       |  99 | tg 128     |     18.19 ± 0.40 |

build: 7ce2c77f (2434)
a-downing commented 2 months ago

I have the same issue with clang failing to compile a test program.

C:\Users\andre\Desktop\development\llama.cpp\build>cmake -G Ninja -DAMDGPU_TARGETS=gfx1100 -DLLAMA_HIPBLAS=ON -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_BUILD_TYPE=Release ..
-- The C compiler identification is Clang 17.0.0 with GNU-like command-line
-- The CXX compiler identification is Clang 17.0.0 with GNU-like command-line
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - failed
-- Check for working C compiler: C:/Program Files/AMD/ROCm/5.7/bin/clang.exe
-- Check for working C compiler: C:/Program Files/AMD/ROCm/5.7/bin/clang.exe - broken
CMake Error at C:/Program Files/Microsoft Visual Studio/2022/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.28/Modules/CMakeTestCCompiler.cmake:67 (message):
  The C compiler

    "C:/Program Files/AMD/ROCm/5.7/bin/clang.exe"

  is not able to compile a simple test program.

  It fails with the following output:

    Change Dir: 'C:/Users/andre/Desktop/development/llama.cpp/build/CMakeFiles/CMakeScratch/TryCompile-2fjj12'

    Run Build Command(s): C:/bin/ninja.exe -v cmTC_aa5fc
    [1/2] C:\PROGRA~1\AMD\ROCm\5.7\bin\clang.exe   -O0 -g -Xclang -gcodeview -D_DEBUG -D_DLL -D_MT -Xclang --dependent-lib=msvcrtd -MD -MT CMakeFiles/cmTC_aa5fc.dir/testCCompiler.c.obj -MF CMakeFiles\cmTC_aa5fc.dir\testCCompiler.c.obj.d -o CMakeFiles/cmTC_aa5fc.dir/testCCompiler.c.obj -c C:/Users/andre/Desktop/development/llama.cpp/build/CMakeFiles/CMakeScratch/TryCompile-2fjj12/testCCompiler.c
    [2/2] C:\Windows\system32\cmd.exe /C "cd . && C:\PROGRA~1\AMD\ROCm\5.7\bin\clang.exe -fuse-ld=lld-link -nostartfiles -nostdlib -O0 -g -Xclang -gcodeview -D_DEBUG -D_DLL -D_MT -Xclang --dependent-lib=msvcrtd -Xlinker /subsystem:console CMakeFiles/cmTC_aa5fc.dir/testCCompiler.c.obj -o cmTC_aa5fc.exe -Xlinker /MANIFEST:EMBED -Xlinker /implib:cmTC_aa5fc.lib -Xlinker /pdb:cmTC_aa5fc.pdb -Xlinker /version:0.0   -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32 -loldnames  && cd ."
    FAILED: cmTC_aa5fc.exe
    C:\Windows\system32\cmd.exe /C "cd . && C:\PROGRA~1\AMD\ROCm\5.7\bin\clang.exe -fuse-ld=lld-link -nostartfiles -nostdlib -O0 -g -Xclang -gcodeview -D_DEBUG -D_DLL -D_MT -Xclang --dependent-lib=msvcrtd -Xlinker /subsystem:console CMakeFiles/cmTC_aa5fc.dir/testCCompiler.c.obj -o cmTC_aa5fc.exe -Xlinker /MANIFEST:EMBED -Xlinker /implib:cmTC_aa5fc.lib -Xlinker /pdb:cmTC_aa5fc.pdb -Xlinker /version:0.0   -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32 -loldnames  && cd ."
    lld-link: error: <root>: undefined symbol: mainCRTStartup
    clang: error: linker command failed with exit code 1 (use -v to see invocation)
    ninja: build stopped: subcommand failed.

  CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
  CMakeLists.txt:2 (project)

-- Configuring incomplete, errors occurred!

I dug a little deeper, but I don't see anything obviously wrong.

C:\Users\andre\Desktop\development\llama.cpp\build\CMakeFiles\CMakeScratch\TryCompile-62y296>C:\PROGRA~1\AMD\ROCm\5.7\bin\clang.exe -fuse-ld=lld-link -nostartfiles -nostdlib -O0 -g -Xclang -gcodeview -D_DEBUG -D_DLL -D_MT -Xclang --dependent-lib=msvcrtd -Xlinker /subsystem:console CMakeFiles/cmTC_54e52.dir/testCCompiler.c.obj -o cmTC_54e52.exe -Xlinker /MANIFEST:EMBED -Xlinker /implib:cmTC_54e52.lib -Xlinker /pdb:cmTC_54e52.pdb -Xlinker /version:0.0   -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32 -loldnames -v
clang version 17.0.0 (git@github.amd.com:Compute-Mirrors/llvm-project 6e709f613348e5258188527d11ee8d78376f26b7)
Target: x86_64-pc-windows-msvc
Thread model: posix
InstalledDir: C:\PROGRA~1\AMD\ROCm\5.7\bin
Found HIP installation: C:\PROGRA~1\AMD\ROCm\5.7, version 5.7.32000
 "C:\\PROGRA~1\\AMD\\ROCm\\5.7\\bin\\lld-link" -out:cmTC_54e52.exe "-libpath:C:\\PROGRA~1\\AMD\\ROCm\\5.7\\lib\\clang\\17.0.0\\lib\\windows" -nologo -debug /subsystem:console CMakeFiles/cmTC_54e52.dir/testCCompiler.c.obj /MANIFEST:EMBED /implib:cmTC_54e52.lib /pdb:cmTC_54e52.pdb /version:0.0 kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib oldnames.lib
lld-link: error: <root>: undefined symbol: mainCRTStartup
clang: error: linker command failed with exit code 1 (use -v to see invocation)
a-downing commented 2 months ago

The problem was that I was running the Developer Command Prompt instead of the x64 Developer Command Prompt.

Zibri commented 1 month ago

this is my full script to compile it under windows.. adapt it to your needs: https://github.com/ggerganov/llama.cpp/issues/7275

MrJackSpade commented 6 days ago

I have the same issue with clang failing to compile a test program.

C:\Users\andre\Desktop\development\llama.cpp\build>cmake -G Ninja -DAMDGPU_TARGETS=gfx1100 -DLLAMA_HIPBLAS=ON -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_BUILD_TYPE=Release ..
-- The C compiler identification is Clang 17.0.0 with GNU-like command-line
-- The CXX compiler identification is Clang 17.0.0 with GNU-like command-line
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - failed
-- Check for working C compiler: C:/Program Files/AMD/ROCm/5.7/bin/clang.exe
-- Check for working C compiler: C:/Program Files/AMD/ROCm/5.7/bin/clang.exe - broken
CMake Error at C:/Program Files/Microsoft Visual Studio/2022/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.28/Modules/CMakeTestCCompiler.cmake:67 (message):
  The C compiler

    "C:/Program Files/AMD/ROCm/5.7/bin/clang.exe"

  is not able to compile a simple test program.

  It fails with the following output:

    Change Dir: 'C:/Users/andre/Desktop/development/llama.cpp/build/CMakeFiles/CMakeScratch/TryCompile-2fjj12'

    Run Build Command(s): C:/bin/ninja.exe -v cmTC_aa5fc
    [1/2] C:\PROGRA~1\AMD\ROCm\5.7\bin\clang.exe   -O0 -g -Xclang -gcodeview -D_DEBUG -D_DLL -D_MT -Xclang --dependent-lib=msvcrtd -MD -MT CMakeFiles/cmTC_aa5fc.dir/testCCompiler.c.obj -MF CMakeFiles\cmTC_aa5fc.dir\testCCompiler.c.obj.d -o CMakeFiles/cmTC_aa5fc.dir/testCCompiler.c.obj -c C:/Users/andre/Desktop/development/llama.cpp/build/CMakeFiles/CMakeScratch/TryCompile-2fjj12/testCCompiler.c
    [2/2] C:\Windows\system32\cmd.exe /C "cd . && C:\PROGRA~1\AMD\ROCm\5.7\bin\clang.exe -fuse-ld=lld-link -nostartfiles -nostdlib -O0 -g -Xclang -gcodeview -D_DEBUG -D_DLL -D_MT -Xclang --dependent-lib=msvcrtd -Xlinker /subsystem:console CMakeFiles/cmTC_aa5fc.dir/testCCompiler.c.obj -o cmTC_aa5fc.exe -Xlinker /MANIFEST:EMBED -Xlinker /implib:cmTC_aa5fc.lib -Xlinker /pdb:cmTC_aa5fc.pdb -Xlinker /version:0.0   -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32 -loldnames  && cd ."
    FAILED: cmTC_aa5fc.exe
    C:\Windows\system32\cmd.exe /C "cd . && C:\PROGRA~1\AMD\ROCm\5.7\bin\clang.exe -fuse-ld=lld-link -nostartfiles -nostdlib -O0 -g -Xclang -gcodeview -D_DEBUG -D_DLL -D_MT -Xclang --dependent-lib=msvcrtd -Xlinker /subsystem:console CMakeFiles/cmTC_aa5fc.dir/testCCompiler.c.obj -o cmTC_aa5fc.exe -Xlinker /MANIFEST:EMBED -Xlinker /implib:cmTC_aa5fc.lib -Xlinker /pdb:cmTC_aa5fc.pdb -Xlinker /version:0.0   -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32 -loldnames  && cd ."
    lld-link: error: <root>: undefined symbol: mainCRTStartup
    clang: error: linker command failed with exit code 1 (use -v to see invocation)
    ninja: build stopped: subcommand failed.

  CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
  CMakeLists.txt:2 (project)

-- Configuring incomplete, errors occurred!

I dug a little deeper, but I don't see anything obviously wrong.

C:\Users\andre\Desktop\development\llama.cpp\build\CMakeFiles\CMakeScratch\TryCompile-62y296>C:\PROGRA~1\AMD\ROCm\5.7\bin\clang.exe -fuse-ld=lld-link -nostartfiles -nostdlib -O0 -g -Xclang -gcodeview -D_DEBUG -D_DLL -D_MT -Xclang --dependent-lib=msvcrtd -Xlinker /subsystem:console CMakeFiles/cmTC_54e52.dir/testCCompiler.c.obj -o cmTC_54e52.exe -Xlinker /MANIFEST:EMBED -Xlinker /implib:cmTC_54e52.lib -Xlinker /pdb:cmTC_54e52.pdb -Xlinker /version:0.0   -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32 -loldnames -v
clang version 17.0.0 (git@github.amd.com:Compute-Mirrors/llvm-project 6e709f613348e5258188527d11ee8d78376f26b7)
Target: x86_64-pc-windows-msvc
Thread model: posix
InstalledDir: C:\PROGRA~1\AMD\ROCm\5.7\bin
Found HIP installation: C:\PROGRA~1\AMD\ROCm\5.7, version 5.7.32000
 "C:\\PROGRA~1\\AMD\\ROCm\\5.7\\bin\\lld-link" -out:cmTC_54e52.exe "-libpath:C:\\PROGRA~1\\AMD\\ROCm\\5.7\\lib\\clang\\17.0.0\\lib\\windows" -nologo -debug /subsystem:console CMakeFiles/cmTC_54e52.dir/testCCompiler.c.obj /MANIFEST:EMBED /implib:cmTC_54e52.lib /pdb:cmTC_54e52.pdb /version:0.0 kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib oldnames.lib
lld-link: error: <root>: undefined symbol: mainCRTStartup
clang: error: linker command failed with exit code 1 (use -v to see invocation)

I'm getting this same issue using the x64 prompt