Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix build-info on MSVC. #3309

Merged
merged 1 commit into from
Sep 25, 2023
Merged

Conversation

dranger003
Copy link
Contributor

Update scripts/build-info.cmake to fix erroring out using MSVC.
Below shows the error this update is fixing.

Z:\llama.cpp>md build && cd build && cmake -DLLAMA_CUBLAS=ON -DBUILD_SHARED_LIBS=ON ..
-- Building for: Visual Studio 17 2022
-- The C compiler identification is MSVC 19.37.32824.0
-- The CXX compiler identification is MSVC 19.37.32824.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: C:/Program Files/Microsoft Visual Studio/2022/Professional/VC/Tools/MSVC/14.37.32822/bin/Hostx64/x64/cl.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/Microsoft Visual Studio/2022/Professional/VC/Tools/MSVC/14.37.32822/bin/Hostx64/x64/cl.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found Git: C:/Program Files/Git/cmd/git.exe (found version "2.41.0.windows.3")
Microsoft (R) C/C++ Optimizing Compiler Version 19.37.32824 for x64
Copyright (C) Microsoft Corporation.  All rights reserved.

cl : Command line warning D9002 : ignoring unknown option '-dumpmachine'
cl : Command line error D8003 : missing source filename
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Failed
-- 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
-- Found CUDAToolkit: C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v11.7/include (found version "11.7.64")
-- cuBLAS found
-- The CUDA compiler identification is NVIDIA 11.7.64
-- Detecting CUDA compiler ABI info
-- Detecting CUDA compiler ABI info - done
-- Check for working CUDA compiler: C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v11.7/bin/nvcc.exe - skipped
-- Detecting CUDA compile features
-- Detecting CUDA compile features - done
-- Using CUDA architectures: 52;61;70
-- CMAKE_SYSTEM_PROCESSOR: AMD64
-- CMAKE_GENERATOR_PLATFORM:
-- x86 detected
-- Configuring done (10.4s)
-- Generating done (0.3s)
-- Build files have been written to: Z:/llama.cpp/build

@cebtenzzre
Copy link
Collaborator

I tried with mkdir build && cmake .. && cmake --build . on Windows and did not get any useful compiler information. BUILD_COMPILER and BUILD_TARGET are both empty.

@dranger003
Copy link
Contributor Author

dranger003 commented Sep 22, 2023

I tried with mkdir build && cmake .. && cmake --build . on Windows and did not get any useful compiler information. BUILD_COMPILER and BUILD_TARGET are both empty.

Below is the full output now, I updated BUILD_TARGET but BUILD_COMPILER is fine on my end - I am running this inside a VS dev command prompt.

Z:\>git clone -b build-info-msvc-fix https://github.com/dranger003/llama.cpp.git
Z:\>cd llama.cpp
Z:\llama.cpp>md build && cd build && cmake.exe ..
-- Building for: Visual Studio 17 2022
-- The C compiler identification is MSVC 19.37.32824.0
-- The CXX compiler identification is MSVC 19.37.32824.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: C:/Program Files/Microsoft Visual Studio/2022/Professional/VC/Tools/MSVC/14.37.32822/bin/Hostx64/x64/cl.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/Microsoft Visual Studio/2022/Professional/VC/Tools/MSVC/14.37.32822/bin/Hostx64/x64/cl.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found Git: C:/Program Files/Git/cmd/git.exe (found version "2.41.0.windows.3")
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Failed
-- 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_SYSTEM_PROCESSOR: AMD64
-- CMAKE_GENERATOR_PLATFORM:
-- x86 detected
-- Configuring done (5.1s)
-- Generating done (0.3s)
-- Build files have been written to: Z:/llama.cpp/build

Z:\llama.cpp\build>type ..\build-info.h
#ifndef BUILD_INFO_H
#define BUILD_INFO_H

#define BUILD_NUMBER 1271
#define BUILD_COMMIT "9051f38"
#define BUILD_COMPILER "MSVC"
#define BUILD_TARGET "x64"

#endif // BUILD_INFO_H

Z:\llama.cpp\build>

@cebtenzzre
Copy link
Collaborator

It shows up correctly at configure time, but when you run cmake --build it overwrites the file with one without compiler information.

@dranger003
Copy link
Contributor Author

dranger003 commented Sep 23, 2023

It shows up correctly at configure time, but when you run cmake --build it overwrites the file with one without compiler information.

Interesting, I will need to do some research as I'm not overly familiar with cmake and I don't know why this is getting overwritten.

EDIT1: So I did output the variable values and they are set properly during the configure phase but for some reason they are all blank during the build phase (even MSVC is blank).

EDIT2: build-info.h is currently set to be rebuilt after a configure and this rebuild runs cmake in "script mode" which does not inherit variables from the parent process (it seems this is by design).

So to fix this we need to update the parent CMakeLists.txt on line 121 to pass in the variables for the script mode run:

        COMMAND ${CMAKE_COMMAND} -P "${CMAKE_CURRENT_SOURCE_DIR}/scripts/build-info.cmake"

And add pass the variables:

        COMMAND ${CMAKE_COMMAND} -DMSVC=${MSVC} -DCMAKE_C_COMPILER_ID=${CMAKE_C_COMPILER_ID} -DCMAKE_VS_PLATFORM_NAME=${CMAKE_VS_PLATFORM_NAME} -P "${CMAKE_CURRENT_SOURCE_DIR}/scripts/build-info.cmake"
    )

@dranger003
Copy link
Contributor Author

@cebtenzzre I have added a commit to pass-in the variables let me know what you think, thanks.

@cebtenzzre
Copy link
Collaborator

Now I understand how @slaren ran into this:

_: line 1: --version: command not found

We need to pass CMAKE_C_COMPILER to the script as well, for use on non-Windows platforms.

@cebtenzzre
Copy link
Collaborator

Seems to work fine on Linux and Windows. One other thing - cmake is able to identify the MSVC version:

-- The C compiler identification is MSVC 19.36.32537.0

Do you think we could make that appear in the build info? On Unix-like platforms, we use --version to get both the compiler name and version.

@dranger003
Copy link
Contributor Author

dranger003 commented Sep 25, 2023

Seems to work fine on Linux and Windows. One other thing - cmake is able to identify the MSVC version:

-- The C compiler identification is MSVC 19.36.32537.0

Do you think we could make that appear in the build info? On Unix-like platforms, we use --version to get both the compiler name and version.

@cebtenzzre I added the compiler version, let me know if you need anything else.

EDIT: I squashed the commits so this is a bit cleaner.

@cebtenzzre cebtenzzre merged commit 99115f3 into ggerganov:master Sep 25, 2023
1 check passed
pkrmf pushed a commit to morlockstudios-com/llama.cpp that referenced this pull request Sep 26, 2023
joelkuiper added a commit to vortext/llama.cpp that referenced this pull request Sep 27, 2023
…example

* 'master' of github.com:ggerganov/llama.cpp:
  convert : remove bug in convert.py permute function (ggerganov#3364)
  make-ggml.py : compatibility with more models and GGUF (ggerganov#3290)
  gguf : fix a few general keys (ggerganov#3341)
  metal : reusing llama.cpp logging (ggerganov#3152)
  build : add ACCELERATE_NEW_LAPACK to fix warning on macOS Sonoma (ggerganov#3342)
  readme : add some recent perplexity and bpw measurements to READMES, link for k-quants (ggerganov#3340)
  cmake : fix build-info.h on MSVC (ggerganov#3309)
  docs: Fix typo CLBlast_DIR var. (ggerganov#3330)
  nix : add cuda, use a symlinked toolkit for cmake (ggerganov#3202)
@dranger003 dranger003 deleted the build-info-msvc-fix branch December 13, 2023 17:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants