-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
print feature flags used for matching pkgimage #50172
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
cf05e2f
print feature flags used for matching pkgimage
vchuravy 6e031a7
Collect cache file rejection messages
pchintalapudi 3798c7b
Apply suggestions from code review
vchuravy 87e2596
pass rejection reason to caller
vchuravy 7165525
fixup! pass rejection reason to caller
vchuravy 00ddf10
Apply suggestions from code review
vchuravy b920030
add JL_NOTSAFEPOINT
vchuravy c77be08
fix fallback
vchuravy 22f1077
fixup! fix fallback
vchuravy 713095c
fixup! fixup! fix fallback
vchuravy 4e9811b
fixup! fixup! fixup! fix fallback
vchuravy bcc50ec
fixup! fixup! fixup! fixup! fix fallback
vchuravy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -107,13 +107,13 @@ static inline bool test_nbit(const T1 &bits, T2 _bitidx) | |
} | ||
|
||
template<typename T> | ||
static inline void unset_bits(T &bits) | ||
static inline void unset_bits(T &bits) JL_NOTSAFEPOINT | ||
{ | ||
(void)bits; | ||
} | ||
|
||
template<typename T, typename T1, typename... Rest> | ||
static inline void unset_bits(T &bits, T1 _bitidx, Rest... rest) | ||
static inline void unset_bits(T &bits, T1 _bitidx, Rest... rest) JL_NOTSAFEPOINT | ||
{ | ||
auto bitidx = static_cast<uint32_t>(_bitidx); | ||
auto u32idx = bitidx / 32; | ||
|
@@ -142,7 +142,7 @@ static inline void set_bit(T &bits, T1 _bitidx, bool val) | |
template<size_t n> | ||
struct FeatureList { | ||
uint32_t eles[n]; | ||
uint32_t &operator[](size_t pos) | ||
uint32_t &operator[](size_t pos) JL_NOTSAFEPOINT | ||
{ | ||
return eles[pos]; | ||
} | ||
|
@@ -297,12 +297,6 @@ static inline void append_ext_features(std::vector<std::string> &features, | |
* Target specific type/constant definitions, always enable. | ||
*/ | ||
|
||
struct FeatureName { | ||
const char *name; | ||
uint32_t bit; // bit index into a `uint32_t` array; | ||
uint32_t llvmver; // 0 if it is available on the oldest LLVM version we support | ||
}; | ||
|
||
template<typename CPU, size_t n> | ||
struct CPUSpec { | ||
const char *name; | ||
|
@@ -636,7 +630,13 @@ static inline jl_image_t parse_sysimg(void *hdl, F &&callback) | |
jl_dlsym(hdl, "jl_image_pointers", (void**)&pointers, 1); | ||
|
||
const void *ids = pointers->target_data; | ||
uint32_t target_idx = callback(ids); | ||
jl_value_t* rejection_reason = nullptr; | ||
JL_GC_PUSH1(&rejection_reason); | ||
uint32_t target_idx = callback(ids, &rejection_reason); | ||
if (target_idx == (uint32_t)-1) { | ||
jl_throw(jl_new_struct(jl_errorexception_type, rejection_reason)); | ||
} | ||
JL_GC_POP(); | ||
|
||
if (pointers->header->version != 1) { | ||
jl_error("Image file is not compatible with this version of Julia"); | ||
|
@@ -855,17 +855,20 @@ struct SysimgMatch { | |
// Find the best match in the sysimg. | ||
// Select the best one based on the largest vector register and largest compatible feature set. | ||
template<typename S, typename T, typename F> | ||
static inline SysimgMatch match_sysimg_targets(S &&sysimg, T &&target, F &&max_vector_size) | ||
static inline SysimgMatch match_sysimg_targets(S &&sysimg, T &&target, F &&max_vector_size, jl_value_t **rejection_reason) | ||
{ | ||
SysimgMatch match; | ||
bool match_name = false; | ||
int feature_size = 0; | ||
std::vector<const char *> rejection_reasons; | ||
rejection_reasons.reserve(sysimg.size()); | ||
for (uint32_t i = 0; i < sysimg.size(); i++) { | ||
auto &imgt = sysimg[i]; | ||
if (!(imgt.en.features & target.dis.features).empty()) { | ||
// Check sysimg enabled features against runtime disabled features | ||
// This is valid (and all what we can do) | ||
// even if one or both of the targets are unknown. | ||
rejection_reasons.push_back("Rejecting this target due to use of runtime-disabled features\n"); | ||
continue; | ||
} | ||
if (imgt.name == target.name) { | ||
|
@@ -876,25 +879,44 @@ static inline SysimgMatch match_sysimg_targets(S &&sysimg, T &&target, F &&max_v | |
} | ||
} | ||
else if (match_name) { | ||
rejection_reasons.push_back("Rejecting this target since another target has a cpu name match\n"); | ||
continue; | ||
} | ||
int new_vsz = max_vector_size(imgt.en.features); | ||
if (match.vreg_size > new_vsz) | ||
if (match.vreg_size > new_vsz) { | ||
rejection_reasons.push_back("Rejecting this target since another target has a larger vector register size\n"); | ||
continue; | ||
} | ||
int new_feature_size = imgt.en.features.nbits(); | ||
if (match.vreg_size < new_vsz) { | ||
match.best_idx = i; | ||
match.vreg_size = new_vsz; | ||
feature_size = new_feature_size; | ||
rejection_reasons.push_back("Updating best match to this target due to larger vector register size\n"); | ||
continue; | ||
} | ||
if (new_feature_size < feature_size) | ||
if (new_feature_size < feature_size) { | ||
rejection_reasons.push_back("Rejecting this target since another target has a larger feature set\n"); | ||
continue; | ||
} | ||
match.best_idx = i; | ||
feature_size = new_feature_size; | ||
rejection_reasons.push_back("Updating best match to this target\n"); | ||
} | ||
if (match.best_idx == (uint32_t)-1) { | ||
// Construct a nice error message for debugging purposes | ||
std::string error_msg = "Unable to find compatible target in cached code image.\n"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Normally you would wrap this in a std::stringstream, so that |
||
for (size_t i = 0; i < rejection_reasons.size(); i++) { | ||
error_msg += "Target "; | ||
error_msg += std::to_string(i); | ||
error_msg += " ("; | ||
error_msg += sysimg[i].name; | ||
error_msg += "): "; | ||
error_msg += rejection_reasons[i]; | ||
} | ||
if (rejection_reason) | ||
*rejection_reason = jl_pchar_to_string(error_msg.data(), error_msg.size()); | ||
} | ||
if (match.best_idx == (uint32_t)-1) | ||
jl_error("Unable to find compatible target in system image."); | ||
return match; | ||
} | ||
|
||
|
@@ -946,3 +968,30 @@ static inline void dump_cpu_spec(uint32_t cpu, const FeatureList<n> &features, | |
#include "processor_fallback.cpp" | ||
|
||
#endif | ||
|
||
extern "C" JL_DLLEXPORT jl_value_t* jl_reflect_clone_targets() { | ||
auto specs = jl_get_llvm_clone_targets(); | ||
const uint32_t base_flags = 0; | ||
std::vector<uint8_t> data; | ||
auto push_i32 = [&] (uint32_t v) { | ||
uint8_t buff[4]; | ||
memcpy(buff, &v, 4); | ||
data.insert(data.end(), buff, buff + 4); | ||
}; | ||
push_i32(specs.size()); | ||
for (uint32_t i = 0; i < specs.size(); i++) { | ||
push_i32(base_flags | (specs[i].flags & JL_TARGET_UNKNOWN_NAME)); | ||
auto &specdata = specs[i].data; | ||
data.insert(data.end(), specdata.begin(), specdata.end()); | ||
} | ||
|
||
jl_value_t *arr = (jl_value_t*)jl_alloc_array_1d(jl_array_uint8_type, data.size()); | ||
uint8_t *out = (uint8_t*)jl_array_data(arr); | ||
memcpy(out, data.data(), data.size()); | ||
return arr; | ||
} | ||
|
||
extern "C" JL_DLLEXPORT void jl_reflect_feature_names(const FeatureName **fnames, size_t *nf) { | ||
*fnames = feature_names; | ||
*nf = nfeature_names; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Neat! Could we also print which features were disabled?