Skip to content

Commit

Permalink
Add CPU feature helper function (#50402)
Browse files Browse the repository at this point in the history
(cherry picked from commit 435c1c1)
  • Loading branch information
wsmoses authored and KristofferC committed Jul 11, 2023
1 parent afb80a1 commit 019e08f
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 0 deletions.
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

0 comments on commit 019e08f

Please sign in to comment.