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

[Docs]Constrained example with num_phyiscal_cores doesn't work #4014

Open
Ivo-Balbaert opened this issue Feb 25, 2025 · 1 comment
Open

[Docs]Constrained example with num_phyiscal_cores doesn't work #4014

Ivo-Balbaert opened this issue Feb 25, 2025 · 1 comment
Assignees
Labels
documentation Improvements or additions to documentation mojo-repo Tag all issues with this label

Comments

@Ivo-Balbaert
Copy link

Where is the problem?

https://docs.modular.com/mojo/stdlib/builtin/constrained/constrained/

What can we do better?

The code on this page gives a compile error (see also #3683)

from sys.info import num_physical_cores

def main():
   alias cores_to_use = 2
   multicore_check[cores_to_use]()

def multicore_check[cores: Int]():
   constrained[
       cores <= num_physical_cores(),
       "build failed: not enough cores"
   ]()
   constrained[
       cores >= 2,
       "at least two cores are required"
   ]()

The error is:

open-source/mojo/stdlib/stdlib/builtin/_startup.mojo:114:4: error: call expansion failed
open-source/mojo/stdlib/stdlib/builtin/_startup.mojo:97:4: note: function instantiation failed
open-source/mojo/stdlib/stdlib/builtin/_startup.mojo:109:57: note: call expansion failed
open-source/mojo/stdlib/stdlib/builtin/_startup.mojo:69:4: note: function instantiation failed
open-source/mojo/stdlib/stdlib/builtin/_startup.mojo:85:18: note: call expansion failed
open-source/mojo/stdlib/stdlib/builtin/_startup.mojo:106:8: note: function instantiation failed
/home/ivo/mojo_book/using_functions/test.mojo:6:34: note: call expansion failed
multicore_checkcores_to_use
^
/home/ivo/mojo_book/using_functions/test.mojo:9:5: note: function instantiation failed
def multicore_checkcores: Int:
^
/home/ivo/mojo_book/using_functions/test.mojo:12:6: note: call expansion failed
]()
^
open-source/mojo/stdlib/stdlib/builtin/constrained.mojo:56:6: note: failed to compile-time evaluate function call
open-source/mojo/stdlib/stdlib/sys/info.mojo:789:4: note: failed to interpret function @StdLib::sys::info::num_physical_cores()
open-source/mojo/stdlib/stdlib/sys/info.mojo:796:73: note: call expansion failed
open-source/mojo/stdlib/stdlib/sys/ffi.mojo:624:6: note: failed to interpret operation pop.external_call{func: "KGEN_CompilerRT_NumPhysicalCores" : !kgen.string, funcAttrs: ["willreturn"], memory: #llvm.memory_effects<other = none, argMem = none, inaccessibleMem = none>, resAttrs: [{llvm.noundef}]}(#kgen.pack<> : !kgen.pack<[]>)
open-source/mojo/stdlib/stdlib/sys/info.mojo:796:73: note: call expansion failed
open-source/mojo/stdlib/stdlib/sys/ffi.mojo:624:6: note: unable to interpret call to unknown external function: KGEN_CompilerRT_NumPhysicalCores

mojo: error: failed to run the pass manager

Anything else?

No response

@Ivo-Balbaert Ivo-Balbaert added the documentation Improvements or additions to documentation label Feb 25, 2025
Copy link
Collaborator

Reproduced. Thanks for filing.

@scottamain scottamain added the mojo Issues that are related to mojo label Feb 26, 2025 — with Linear
@ematejska ematejska added the mojo-repo Tag all issues with this label label Feb 26, 2025
@ematejska ematejska removed mojo Issues that are related to mojo mojo-playground labels Feb 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation mojo-repo Tag all issues with this label
Projects
None yet
Development

No branches or pull requests

4 participants