Fix Api table copy operation and tools version checking.

Change-Id: Ia76d16f3ea6d0abb931813f90bc3bc2119da5999


[ROCm/ROCR-Runtime commit: 505d722b7d]
This commit is contained in:
Sean Keely
2017-02-04 15:08:07 -06:00
parent d984194fa5
commit de0fa51022
3 changed files with 53 additions and 53 deletions
@@ -78,6 +78,8 @@ static inline uint32_t Min(const uint32_t a, const uint32_t b) {
}
// Structure of Version used to identify an instance of Api table
// Must be the first member (offsetof == 0) of all API tables.
// This is the root of the table passing ABI.
struct ApiTableVersion {
uint32_t major_id;
uint32_t minor_id;
@@ -109,9 +111,9 @@ struct ImageExtTable {
decltype(hsa_ext_image_destroy)* hsa_ext_image_destroy_fn;
decltype(hsa_ext_sampler_create)* hsa_ext_sampler_create_fn;
decltype(hsa_ext_sampler_destroy)* hsa_ext_sampler_destroy_fn;
decltype(hsa_ext_image_get_capability_with_layout)* hsa_ext_image_get_capability_with_layout_fn;
decltype(hsa_ext_image_data_get_info_with_layout)* hsa_ext_image_data_get_info_with_layout_fn;
decltype(hsa_ext_image_create_with_layout)* hsa_ext_image_create_with_layout_fn;
decltype(hsa_ext_image_get_capability_with_layout)* hsa_ext_image_get_capability_with_layout_fn;
decltype(hsa_ext_image_data_get_info_with_layout)* hsa_ext_image_data_get_info_with_layout_fn;
decltype(hsa_ext_image_create_with_layout)* hsa_ext_image_create_with_layout_fn;
};
// Table to export AMD Extension Apis
@@ -393,59 +395,48 @@ void inline copyApi(void* src, void* dest, size_t size) {
(size - sizeof(ApiTableVersion)));
}
// Copy Api child tables if valid.
static void inline copyElement(ApiTableVersion* dest, ApiTableVersion* src) {
if (dest->major_id == src->major_id) {
dest->step_id = src->step_id;
dest->minor_id = Min(dest->minor_id, src->minor_id);
copyApi(dest, src, dest->minor_id);
} else {
dest->major_id = 0;
dest->minor_id = 0;
dest->step_id = 0;
}
}
// Copy constructor for all Api tables. The function assumes the
// user has initialized an instance of tables container correctly
// for the Major, Minor and Stepping Ids of Root and Child Api tables.
// The function will overwrite the value of Minor Id by taking the
// minimum of source and destination parameters. It will also overwrite
// the stepping Id with value from source parameter.
static const
void inline copyTables(const HsaApiTable* src, HsaApiTableContainer* dest) {
// Verify Major Id of source and destination tables are valid
assert(dest->root.version.major_id == src->version.major_id);
assert(dest->core.version.major_id == src->core_->version.major_id);
assert(dest->amd_ext.version.major_id == src->amd_ext_->version.major_id);
assert(dest->finalizer_ext.version.major_id == src->finalizer_ext_->version.major_id);
assert(dest->image_ext.version.major_id == src->image_ext_->version.major_id);
static void inline copyTables(const HsaApiTable* src, HsaApiTable* dest) {
// Verify Major Id of source and destination tables match
if (dest->version.major_id != src->version.major_id) {
dest->version.major_id = 0;
dest->version.minor_id = 0;
dest->version.step_id = 0;
return;
}
// Initialize the stepping id and minor id of root table. For the
// minor id which encodes struct size, take the minimum of source
// and destination parameters
dest->root.version.step_id = src->version.step_id;
dest->root.version.minor_id = Min(dest->root.version.minor_id, src->version.minor_id);
// Copy the Core Api table
size_t size = dest->root.version.minor_id;
if (size > offsetof(HsaApiTable, core_)) {
dest->core.version.step_id = src->core_->version.step_id;
dest->core.version.minor_id = Min(dest->core.version.minor_id,
src->core_->version.minor_id);
copyApi(&dest->core, src->core_, dest->core.version.minor_id);
}
// Copy the Amd Ext Api table
if (size > offsetof(HsaApiTable, amd_ext_)) {
dest->amd_ext.version.step_id = src->amd_ext_->version.step_id;
dest->amd_ext.version.minor_id = Min(dest->core.version.minor_id,
src->amd_ext_->version.minor_id);
copyApi(&dest->amd_ext, src->amd_ext_, dest->amd_ext.version.minor_id);
}
// Copy the Finalizer Ext Api table
if (size > offsetof(HsaApiTable, finalizer_ext_)) {
dest->finalizer_ext.version.step_id = src->finalizer_ext_->version.step_id;
dest->finalizer_ext.version.minor_id = Min(dest->core.version.minor_id,
src->finalizer_ext_->version.minor_id);
copyApi(&dest->finalizer_ext, src->finalizer_ext_, dest->finalizer_ext.version.minor_id);
}
// Copy the Image Ext Api table
if (size > offsetof(HsaApiTable, image_ext_)) {
dest->image_ext.version.step_id = src->image_ext_->version.step_id;
dest->image_ext.version.minor_id = Min(dest->core.version.minor_id,
src->image_ext_->version.minor_id);
copyApi(&dest->image_ext, src->image_ext_, dest->image_ext.version.minor_id);
}
dest->version.step_id = src->version.step_id;
dest->version.minor_id = Min(dest->version.minor_id, src->version.minor_id);
// Copy child tables if present
if ((offsetof(HsaApiTable, core_) < dest->version.minor_id))
copyElement(&dest->core_->version, &src->core_->version);
if ((offsetof(HsaApiTable, amd_ext_) < dest->version.minor_id))
copyElement(&dest->amd_ext_->version, &src->amd_ext_->version);
if ((offsetof(HsaApiTable, finalizer_ext_) < dest->version.minor_id))
copyElement(&dest->finalizer_ext_->version, &src->finalizer_ext_->version);
if ((offsetof(HsaApiTable, image_ext_) < dest->version.minor_id))
copyElement(&dest->image_ext_->version, &src->image_ext_->version);
}
#endif