Skip to content

Conversation

@B1rds3y
Copy link

@B1rds3y B1rds3y commented Sep 15, 2025

Title: Guard ThreadPowerThrottling block for non-MSVC compilers

Description:
This patch wraps the ThreadPowerThrottling block in ggml-cpu.c with an
MSVC-only preprocessor guard so MinGW/GCC builds don't attempt to compile
Windows SDK-only types (e.g. THREAD_POWER_THROTTLING_STATE).

Patch snippet (apply inside llama.cpp/ggml/src/ggml-cpu/ggml-cpu.c where the
ThreadPowerThrottling block appears):

/* Guard MSVC-only ThreadPowerThrottling block so MinGW/GCC do not compile
   Windows SDK-only types. */
#if defined(_MSC_VER)
#if _WIN32_WINNT >= 0x0602
    /* existing ThreadPowerThrottling code that references
       THREAD_POWER_THROTTLING_STATE and related symbols */
#endif
#endif // defined(_MSC_VER)

Notes:

  • This change keeps the existing _WIN32_WINNT guard and only adds a
    surrounding #if defined(_MSC_VER) so non-MSVC compilers skip the block.
  • It is intentionally minimal and should be safe for MSVC builds.

Suggested PR title:
Guard ThreadPowerThrottling block in ggml-cpu.c for non-MSVC compilers

Suggested PR description:
The ThreadPowerThrottling block references Windows SDK-only types which
cause MinGW/GCC builds to fail with unknown type errors. This change adds
an MSVC-only guard so that MinGW/GCC skip the block. MSVC builds are
unaffected.

@github-actions github-actions bot added the ggml changes relating to the ggml tensor library for machine learning label Sep 15, 2025
@jeffbolznv
Copy link
Collaborator

Can you try changing the value of GGML_WIN_VER in ggml/cmakelists.txt to a high enough value to enable this command instead?

@slaren
Copy link
Member

slaren commented Sep 15, 2025

I believe this is only an issue in old versions of mingw. There is no reason to disable it for all mingw versions. We have CI that tests the build in mingw (msys2).

@jeffbolznv
Copy link
Collaborator

IIUC we're supposed to set the minimum version we support via _WIN32_WINNT (https://learn.microsoft.com/en-us/cpp/porting/modifying-winver-and-win32-winnt?view=msvc-170) and we're setting it to something less than win8 which i think is unintended.

@jwijffels
Copy link

jwijffels commented Oct 20, 2025

I'm upgrading the audio.whisper R wrapper around whisper.cpp to 1.8.2 (https://github.com/bnosac/audio.whisper/tree/v1.8.2) and also see this error when doing the continuous integration. E.g. https://github.com/bnosac/audio.whisper/actions/runs/18661388118/job/53202464986?pr=80

Is there something I can help to further narrow down the issue / suggested fix?

[ 35%] Building C object ggml/src/CMakeFiles/ggml-cpu.dir/ggml-cpu/ggml-cpu.c.obj
C:/Users/runneradmin/AppData/Local/Temp/RtmpQ3CdIt/R.INSTALL11947b597713/audio.whisper/inst/whisper.cpp/ggml/src/ggml-cpu/ggml-cpu.c: In function 'ggml_thread_apply_priority':
C:/Users/runneradmin/AppData/Local/Temp/RtmpQ3CdIt/R.INSTALL11947b597713/audio.whisper/inst/whisper.cpp/ggml/src/ggml-cpu/ggml-cpu.c:2439:9: error: unknown type name 'THREAD_POWER_THROTTLING_STATE'; did you mean 'PPROCESS_POWER_THROTTLING_STATE'?
 2439 |         THREAD_POWER_THROTTLING_STATE t;
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |         PPROCESS_POWER_THROTTLING_STATE
C:/Users/runneradmin/AppData/Local/Temp/RtmpQ3CdIt/R.INSTALL11947b597713/audio.whisper/inst/whisper.cpp/ggml/src/ggml-cpu/ggml-cpu.c:2441:10: error: request for member 'Version' in something not a structure or union
 2441 |         t.Version     = THREAD_POWER_THROTTLING_CURRENT_VERSION;
      |          ^
C:/Users/runneradmin/AppData/Local/Temp/RtmpQ3CdIt/R.INSTALL11947b597713/audio.whisper/inst/whisper.cpp/ggml/src/ggml-cpu/ggml-cpu.c:2441:25: error: 'THREAD_POWER_THROTTLING_CURRENT_VERSION' undeclared (first use in this function); did you mean 'PROCESS_POWER_THROTTLING_CURRENT_VERSION'?
 2441 |         t.Version     = THREAD_POWER_THROTTLING_CURRENT_VERSION;
      |                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |                         PROCESS_POWER_THROTTLING_CURRENT_VERSION
C:/Users/runneradmin/AppData/Local/Temp/RtmpQ3CdIt/R.INSTALL11947b597713/audio.whisper/inst/whisper.cpp/ggml/src/ggml-cpu/ggml-cpu.c:2441:25: note: each undeclared identifier is reported only once for each function it appears in
C:/Users/runneradmin/AppData/Local/Temp/RtmpQ3CdIt/R.INSTALL11947b597713/audio.whisper/inst/whisper.cpp/ggml/src/ggml-cpu/ggml-cpu.c:2442:10: error: request for member 'ControlMask' in something not a structure or union
 2442 |         t.ControlMask = THREAD_POWER_THROTTLING_EXECUTION_SPEED;
      |          ^
C:/Users/runneradmin/AppData/Local/Temp/RtmpQ3CdIt/R.INSTALL11947b597713/audio.whisper/inst/whisper.cpp/ggml/src/ggml-cpu/ggml-cpu.c:2442:25: error: 'THREAD_POWER_THROTTLING_EXECUTION_SPEED' undeclared (first use in this function); did you mean 'PROCESS_POWER_THROTTLING_EXECUTION_SPEED'?
 2442 |         t.ControlMask = THREAD_POWER_THROTTLING_EXECUTION_SPEED;
      |                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |                         PROCESS_POWER_THROTTLING_EXECUTION_SPEED
C:/Users/runneradmin/AppData/Local/Temp/RtmpQ3CdIt/R.INSTALL11947b597713/audio.whisper/inst/whisper.cpp/ggml/src/ggml-cpu/ggml-cpu.c:2443:10: error: request for member 'StateMask' in something not a structure or union
 2443 |         t.StateMask   = 0;
      |          ^
gmake[2]: *** [ggml/src/CMakeFiles/ggml-cpu.dir/build.make:77: ggml/src/CMakeFiles/ggml-cpu.dir/ggml-cpu/ggml-cpu.c.obj] Error 1

@jeffbolznv
Copy link
Collaborator

I installed the latest msys but wasn't able to reproduce this. My suggested steps for how to proceed are at #14953 (comment).

@slaren
Copy link
Member

slaren commented Oct 20, 2025

This is very likely a bug in old versions of mingw, so I am not even convinced that we need to do anything. If someone is willing to put the work to figure exactly what version is broken and needs to be guarded we could possibly do that, but I am not sure that we would be doing anyone a favor by disabling the feature, and it might just be easier to update to a newer version of mingw.

@jwijffels
Copy link

jwijffels commented Oct 22, 2025

FWIW.
The build shown here: #16014 (comment) is run on Windows compiling against whisper.cpp 1.8.2 using the current release of R (4.5.1) which has build tools put into RTools documented here https://cran.r-project.org/bin/windows/Rtools/rtools45/rtools.html and where you can download the installer.

From the docs there:

`Rtools45 consists of Msys2 build tools, GCC 14/MinGW-w64 compiler toolchain, libraries built using the toolchain, and QPDF. Rtools45 supports 64-bit Windows and UCRT as the C runtime.

Full build log
ℹ Building audio.whisper 0.5.0
✖ Failed to build audio.whisper 0.5.0 (51.8s)
Error: 
! error in pak subprocess
Caused by error in `stop_task_build(state, worker)`:
! Failed to build source package audio.whisper.
Full installation output:
* installing *source* package 'audio.whisper' ...
** this is package 'audio.whisper' version '0.5.0'
staged installation is only possible with locking
** using non-staged installation
-- The C compiler identification is GNU 14.2.0
-- The CXX compiler identification is GNU 14.2.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: C:/rtools45/x86_64-w64-mingw32.static.posix/bin/gcc.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:/rtools45/x86_64-w64-mingw32.static.posix/bin/g++.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found Git: C:/Program Files/Git/bin/git.exe (found version "2.51.0.windows.2")
fatal: not a git repository (or any of the parent directories): .git
fatal: not a git repository (or any of the parent directories): .git
-- The ASM compiler identification is GNU
-- Found assembler: C:/rtools45/x86_64-w64-mingw32.static.posix/bin/gcc.exe
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Success
-- Found Threads: TRUE
-- ccache found, compilation results will be cached. Disable with GGML_CCACHE=OFF.
-- CMAKE_SYSTEM_PROCESSOR: AMD64
-- GGML_SYSTEM_ARCH: x86
-- Including CPU backend
-- Found OpenMP_C: -fopenmp (found version "4.5")
-- Found OpenMP_CXX: -fopenmp (found version "4.5")
-- Found OpenMP: TRUE (found version "4.5")
-- x86 detected
-- Adding CPU backend variant ggml-cpu: -march=native 
-- ggml version: 0.9.4-dirty
-- ggml commit:  unknown
-- Configuring done (10.6s)
-- Generating done (0.1s)
-- Build files have been written to: C:/Users/runneradmin/AppData/Local/Temp/RtmpQ3CdIt/R.INSTALL11947b597713/audio.whisper/src/build
[  3%] Building C object ggml/src/CMakeFiles/ggml-base.dir/ggml.c.obj
[  7%] Building CXX object ggml/src/CMakeFiles/ggml-base.dir/ggml.cpp.obj
[ 10%] Building C object ggml/src/CMakeFiles/ggml-base.dir/ggml-alloc.c.obj
[ 14%] Building CXX object ggml/src/CMakeFiles/ggml-base.dir/ggml-backend.cpp.obj
[ 17%] Building CXX object ggml/src/CMakeFiles/ggml-base.dir/ggml-opt.cpp.obj
[ 21%] Building CXX object ggml/src/CMakeFiles/ggml-base.dir/ggml-threading.cpp.obj
[ 25%] Building C object ggml/src/CMakeFiles/ggml-base.dir/ggml-quants.c.obj
[ 28%] Building CXX object ggml/src/CMakeFiles/ggml-base.dir/gguf.cpp.obj
[ 32%] Linking CXX static library ggml-base.a
[ 32%] Built target ggml-base
[ 35%] Building C object ggml/src/CMakeFiles/ggml-cpu.dir/ggml-cpu/ggml-cpu.c.obj
C:/Users/runneradmin/AppData/Local/Temp/RtmpQ3CdIt/R.INSTALL11947b597713/audio.whisper/inst/whisper.cpp/ggml/src/ggml-cpu/ggml-cpu.c: In function 'ggml_thread_apply_priority':
C:/Users/runneradmin/AppData/Local/Temp/RtmpQ3CdIt/R.INSTALL11947b597713/audio.whisper/inst/whisper.cpp/ggml/src/ggml-cpu/ggml-cpu.c:2439:9: error: unknown type name 'THREAD_POWER_THROTTLING_STATE'; did you mean 'PPROCESS_POWER_THROTTLING_STATE'?
 2439 |         THREAD_POWER_THROTTLING_STATE t;
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |         PPROCESS_POWER_THROTTLING_STATE
C:/Users/runneradmin/AppData/Local/Temp/RtmpQ3CdIt/R.INSTALL11947b597713/audio.whisper/inst/whisper.cpp/ggml/src/ggml-cpu/ggml-cpu.c:2441:10: error: request for member 'Version' in something not a structure or union
 2441 |         t.Version     = THREAD_POWER_THROTTLING_CURRENT_VERSION;
      |          ^
C:/Users/runneradmin/AppData/Local/Temp/RtmpQ3CdIt/R.INSTALL11947b597713/audio.whisper/inst/whisper.cpp/ggml/src/ggml-cpu/ggml-cpu.c:2441:25: error: 'THREAD_POWER_THROTTLING_CURRENT_VERSION' undeclared (first use in this function); did you mean 'PROCESS_POWER_THROTTLING_CURRENT_VERSION'?
 2441 |         t.Version     = THREAD_POWER_THROTTLING_CURRENT_VERSION;
      |                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |                         PROCESS_POWER_THROTTLING_CURRENT_VERSION
C:/Users/runneradmin/AppData/Local/Temp/RtmpQ3CdIt/R.INSTALL11947b597713/audio.whisper/inst/whisper.cpp/ggml/src/ggml-cpu/ggml-cpu.c:2441:25: note: each undeclared identifier is reported only once for each function it appears in
C:/Users/runneradmin/AppData/Local/Temp/RtmpQ3CdIt/R.INSTALL11947b597713/audio.whisper/inst/whisper.cpp/ggml/src/ggml-cpu/ggml-cpu.c:2442:10: error: request for member 'ControlMask' in something not a structure or union
 2442 |         t.ControlMask = THREAD_POWER_THROTTLING_EXECUTION_SPEED;
      |          ^
C:/Users/runneradmin/AppData/Local/Temp/RtmpQ3CdIt/R.INSTALL11947b597713/audio.whisper/inst/whisper.cpp/ggml/src/ggml-cpu/ggml-cpu.c:2442:25: error: 'THREAD_POWER_THROTTLING_EXECUTION_SPEED' undeclared (first use in this function); did you mean 'PROCESS_POWER_THROTTLING_EXECUTION_SPEED'?
 2442 |         t.ControlMask = THREAD_POWER_THROTTLING_EXECUTION_SPEED;
      |                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |                         PROCESS_POWER_THROTTLING_EXECUTION_SPEED
C:/Users/runneradmin/AppData/Local/Temp/RtmpQ3CdIt/R.INSTALL11947b597713/audio.whisper/inst/whisper.cpp/ggml/src/ggml-cpu/ggml-cpu.c:2443:10: error: request for member 'StateMask' in something not a structure or union
 2443 |         t.StateMask   = 0;
      |          ^
gmake[2]: *** [ggml/src/CMakeFiles/ggml-cpu.dir/build.make:77: ggml/src/CMakeFiles/ggml-cpu.dir/ggml-cpu/ggml-cpu.c.obj] Error 1
gmake[1]: *** [CMakeFiles/Makefile2:205: ggml/src/CMakeFiles/ggml-cpu.dir/all] Error 2
gmake: *** [Makefile:136: all] Error 2
** libs
using C++ compiler: 'G__~1.EXE (GCC) 14.2.0'
using C++11
make: *** No rule to make target 'grammar-parser.o', needed by 'audio.whisper.dll'.  Stop.
ERROR: compilation failed for package 'audio.whisper'
* removing 'C:/Users/RUNNER~1/AppData/Local/Temp/Rtmp6ZsLXT/pkg-lib6648e4515a/audio.whisper'

`

@jeffbolznv
Copy link
Collaborator

I tried using the rtools environment and the build still worked for me. I suspect I'm getting a newer toolchain.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ggml changes relating to the ggml tensor library for machine learning

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants