Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
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

[BUG] global variable initialized from num_performance_cores() become 0 after compile #3311

Closed
SynodicMonth opened this issue Jul 26, 2024 · 5 comments
Labels
bug Something isn't working mojo-repo Tag all issues with this label

Comments

@SynodicMonth
Copy link
Contributor

Bug description

from sys.info import num_performance_cores
var workers = num_performance_cores()

def main():
    print(workers)

Using mojo run, it works normally and prints 6.
After mojo compile, it prints 0.

Steps to reproduce

just run the code above.

btw,

from sys.info import num_performance_cores

def main():
    print(num_performance_cores())

This works well in both mojo run and mojo compile.

System information

- Ubuntu 22.04.4 LTS
- mojo 24.4.0 (2cb57382)
- modular 0.8.0 (39a426b5)
@SynodicMonth SynodicMonth added bug Something isn't working mojo-repo Tag all issues with this label labels Jul 26, 2024
@DWSimmons
Copy link

DWSimmons commented Jul 26, 2024

Appears it's not just cores, it's all of sys.info(?!)*

Confirmed same behavior on mojo 2024.7.2521 (a7cec710) and ubuntu 22.04.4

*Tested 5 of the sys.info calls

from sys.info import *

var workers = num_performance_cores()
var logical = num_logical_cores()
var physical = num_physical_cores()

var SIMD_BIT_WIDTH = simdbitwidth()
var SIMDBITEWIDTH = simdbytewidth()


def main():
    print(workers)
    print(logical)
    print(physical)
    print(SIMD_BIT_WIDTH)
    print(SIMDBITEWIDTH)

Returns

darin@home:~/Playground/mojo_bug_testing$ mojo 3311_test_extra.mojo
8
16
8
256
32
darin@home:~/Playground/mojo_bug_testing$ mojo build 3311_test_extra.mojo
darin@home:~/Playground/mojo_bug_testing$ ./3311_test_extra 
0
0
0
0
0

@DWSimmons
Copy link

Aliasing all the above calls does not compile

from sys.info import *

alias workers = num_performance_cores()
alias logical = num_logical_cores()
alias physical = num_physical_cores()

alias SIMD_BIT_WIDTH = simdbitwidth()
alias SIMDBITEWIDTH = simdbytewidth()


def main():
    print(workers)
    print(logical)
    print(physical)
    print(SIMD_BIT_WIDTH)
    print(SIMDBITEWIDTH)

returns

/__w/modular/modular/open-source/mojo/stdlib/stdlib/builtin/_startup.mojo:113:4: error: call expansion failed
/__w/modular/modular/open-source/mojo/stdlib/stdlib/builtin/_startup.mojo:96:4: note: function instantiation failed
/__w/modular/modular/open-source/mojo/stdlib/stdlib/builtin/_startup.mojo:108:57: note: call expansion failed
/__w/modular/modular/open-source/mojo/stdlib/stdlib/builtin/_startup.mojo:68:4: note: function instantiation failed
/__w/modular/modular/open-source/mojo/stdlib/stdlib/builtin/_startup.mojo:84:18: note: call expansion failed
/__w/modular/modular/open-source/mojo/stdlib/stdlib/builtin/_startup.mojo:105:8: note: function instantiation failed
<unknown>:0: note: failed to compile-time evaluate function call
/__w/modular/modular/open-source/mojo/stdlib/stdlib/sys/info.mojo:709:4: note: failed to interpret function @stdlib::sys::info::num_performance_cores()
/__w/modular/modular/open-source/mojo/stdlib/stdlib/sys/info.mojo:716:76: note: call expansion failed
/__w/modular/modular/open-source/mojo/stdlib/stdlib/sys/ffi.mojo:342:6: note: failed to interpret operation pop.external_call{func: "KGEN_CompilerRT_NumPerformanceCores" : !kgen.string, funcAttrs: ["willreturn"], memory: #llvm.memory_effects<other = none, argMem = none, inaccessibleMem = none>, resAttrs: [{llvm.noundef}]}(#kgen.pack<> : !kgen.pack<[]>)
/__w/modular/modular/open-source/mojo/stdlib/stdlib/sys/info.mojo:716:76: note: call expansion failed
/__w/modular/modular/open-source/mojo/stdlib/stdlib/sys/ffi.mojo:342:6: note: unable to interpret call to unknown external function: KGEN_CompilerRT_NumPerformanceCores
mojo: error: failed to run the pass manager

@jackos
Copy link
Collaborator

jackos commented Jul 26, 2024

I can't reproduce this on the current internal build. If you move var workers = num_performance_cores() into def main like:

from sys.info import num_performance_cores

def main():
    var workers = num_performance_cores()
    print(workers)

Does that fix it?

@abduld is a global var statement undefined behavior at the moment?

@DWSimmons
Copy link

I can't reproduce this on the current internal build. If you move var workers = num_performance_cores() into def main like:

from sys.info import num_performance_cores

def main():
    var workers = num_performance_cores()
    print(workers)

Does that fix it?

@abduld is a global var statement undefined behavior at the moment?

Yes, var in scope of main works.

alias workers in global throws an error on print for variadic statements [expected?]
alias workers in def main returns

/__w/modular/modular/open-source/mojo/stdlib/stdlib/builtin/_startup.mojo:113:4: error: call expansion failed
/__w/modular/modular/open-source/mojo/stdlib/stdlib/builtin/_startup.mojo:96:4: note: function instantiation failed
/__w/modular/modular/open-source/mojo/stdlib/stdlib/builtin/_startup.mojo:108:57: note: call expansion failed
/__w/modular/modular/open-source/mojo/stdlib/stdlib/builtin/_startup.mojo:68:4: note: function instantiation failed
/__w/modular/modular/open-source/mojo/stdlib/stdlib/builtin/_startup.mojo:84:18: note: call expansion failed
/__w/modular/modular/open-source/mojo/stdlib/stdlib/builtin/_startup.mojo:105:8: note: function instantiation failed
<unknown>:0: note: failed to compile-time evaluate function call
/__w/modular/modular/open-source/mojo/stdlib/stdlib/sys/info.mojo:709:4: note: failed to interpret function @stdlib::sys::info::num_performance_cores()
/__w/modular/modular/open-source/mojo/stdlib/stdlib/sys/info.mojo:716:76: note: call expansion failed
/__w/modular/modular/open-source/mojo/stdlib/stdlib/sys/ffi.mojo:342:6: note: failed to interpret operation pop.external_call{func: "KGEN_CompilerRT_NumPerformanceCores" : !kgen.string, funcAttrs: ["willreturn"], memory: #llvm.memory_effects<other = none, argMem = none, inaccessibleMem = none>, resAttrs: [{llvm.noundef}]}(#kgen.pack<> : !kgen.pack<[]>)
/__w/modular/modular/open-source/mojo/stdlib/stdlib/sys/info.mojo:716:76: note: call expansion failed
/__w/modular/modular/open-source/mojo/stdlib/stdlib/sys/ffi.mojo:342:6: note: unable to interpret call to unknown external function: KGEN_CompilerRT_NumPerformanceCores
mojo: error: failed to run the pass manager

@jackos
Copy link
Collaborator

jackos commented Jul 26, 2024

alias workers in global throws an error on print for variadic statements [expected?]

No that is unexpected and we should fix it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working mojo-repo Tag all issues with this label
Projects
None yet
Development

No branches or pull requests

4 participants