Skip to content

ggml: fix ms compiler error involving restrict keyword - #1238

Closed
grahameth wants to merge 1 commit into
ggml-org:masterfrom
grahameth:restrict
Closed

grahameth wants to merge 1 commit into
ggml-org:masterfrom
grahameth:restrict

Conversation

@grahameth

Copy link
Copy Markdown
Contributor

Use __restrict instead of restrict on MS compiler to prevent compiler error on VS2017 and VS2019.

@slaren

slaren commented Apr 29, 2023

Copy link
Copy Markdown
Member

Can you help me understand what does this exactly enable? Isn't building with MSVC already supported? I can build without issue (well, other than the million of warnings) with VS 2019 Community.

@grahameth

Copy link
Copy Markdown
Contributor Author

Hm, that's strange. I get this error on the first line where restrict is used:

ggml.h(889): error C2146: syntax error: missing ')' before identifier 'x'

I checked this on one computer with VS2017 and on another with VS2019

@slaren

slaren commented Apr 29, 2023

Copy link
Copy Markdown
Member

I am not sure in what version this was added, but MSVC does support restrict with /std:c11.

@grahameth

Copy link
Copy Markdown
Contributor Author

Well, I updated my MSVC 2017 and also updated the language standard in the project settings, but I still get the same error. But if I'm the only one with this issue I guess you can close it.

@grencez

grencez commented May 1, 2023

Copy link
Copy Markdown
Contributor

@grahameth are you using CMake? If so, check the compile_commands.json file in the build directory to find the exact build command. Maybe it's not compiling ggml.c as C11 (or newer). C++ or older C versions won't recognize the keyword.

@Green-Sky

Copy link
Copy Markdown
Collaborator

afaik MS was very (very) slow to add c11 features to their compiler, so might just be a miss.
nvm, it's a c99 feature.

    C99 standard (ISO/IEC 9899:1999): 

        6.7.3.1 Formal definition of restrict (p: 110-112) 

@grahameth

Copy link
Copy Markdown
Contributor Author

@grencez I don't find a generated file named "compile_commands.json" anywhere.

But anyway, I just set up a VM with a fresh install of VS2022 and cmake and there it indeed works. I still don't understand why it doesn't work on my machines, but it's not worth the time to investigate this.

@grahameth grahameth closed this May 8, 2023
phuongncn pushed a commit to phuongncn/llama.cpp-gx10-dgx-sparks-deepseekv4 that referenced this pull request Apr 28, 2026
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.

4 participants