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

Add CPU feature helper function #50402

Merged
merged 2 commits into from
Jul 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/jl_exported_funcs.inc
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@
XX(jl_get_binding_or_error) \
XX(jl_get_binding_wr) \
XX(jl_get_cpu_name) \
XX(jl_get_cpu_features) \
XX(jl_get_current_task) \
XX(jl_get_default_sysimg_path) \
XX(jl_get_excstack) \
Expand Down
2 changes: 2 additions & 0 deletions src/processor.h
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,8 @@ jl_image_t jl_init_processor_pkgimg(void *hdl);

// Return the name of the host CPU as a julia string.
JL_DLLEXPORT jl_value_t *jl_get_cpu_name(void);
// Return the features of the host CPU as a julia string.
JL_DLLEXPORT jl_value_t *jl_get_cpu_features(void);
// Dump the name and feature set of the host CPU
// For debugging only
JL_DLLEXPORT void jl_dump_host_cpu(void);
Expand Down
5 changes: 5 additions & 0 deletions src/processor_arm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1802,6 +1802,11 @@ JL_DLLEXPORT jl_value_t *jl_get_cpu_name(void)
return jl_cstr_to_string(host_cpu_name().c_str());
}

JL_DLLEXPORT jl_value_t *jl_get_cpu_features(void)
{
return jl_cstr_to_string(jl_get_cpu_features_llvm().c_str());
}

jl_image_t jl_init_processor_sysimg(void *hdl)
{
if (!jit_targets.empty())
Expand Down
5 changes: 5 additions & 0 deletions src/processor_fallback.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,11 @@ JL_DLLEXPORT jl_value_t *jl_get_cpu_name(void)
return jl_cstr_to_string(host_cpu_name().c_str());
}

JL_DLLEXPORT jl_value_t *jl_get_cpu_features(void)
{
return jl_cstr_to_string(jl_get_cpu_features_llvm().c_str());
}

JL_DLLEXPORT void jl_dump_host_cpu(void)
{
jl_safe_printf("CPU: %s\n", host_cpu_name().c_str());
Expand Down
5 changes: 5 additions & 0 deletions src/processor_x86.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1042,6 +1042,11 @@ JL_DLLEXPORT jl_value_t *jl_get_cpu_name(void)
return jl_cstr_to_string(host_cpu_name().c_str());
}

JL_DLLEXPORT jl_value_t *jl_get_cpu_features(void)
{
return jl_cstr_to_string(jl_get_cpu_features_llvm().c_str());
}

jl_image_t jl_init_processor_sysimg(void *hdl)
{
if (!jit_targets.empty())
Expand Down
3 changes: 3 additions & 0 deletions test/sysinfo.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ Base.Sys.loadavg()
@test Base.libllvm_path() isa Symbol
@test contains(String(Base.libllvm_path()), "LLVM")

@test length(ccall(:jl_get_cpu_name, String, ())) != 0
@test length(ccall(:jl_get_cpu_features, String, ())) >= 0

if Sys.isunix()
mktempdir() do tempdir
firstdir = joinpath(tempdir, "first")
Expand Down