Build ROCr core and image libraries as one shared object
Change-Id: I3a16c1227e7db2e386ab33886965596fa0fb0c87
[ROCm/ROCR-Runtime commit: 0ca0691ca7]
This commit is contained in:
committed by
Sean Keely
parent
f80ce871b3
commit
c9f453a8a8
@@ -68,9 +68,14 @@ class ExtensionEntryPoints {
|
||||
ExtensionEntryPoints();
|
||||
|
||||
bool LoadFinalizer(std::string library_name);
|
||||
bool LoadImage(std::string library_name);
|
||||
void Unload();
|
||||
|
||||
// Update Image Api table with handles to implementation
|
||||
bool LoadImage();
|
||||
|
||||
// Reset Api tables to point to null implementations
|
||||
void UnloadImage();
|
||||
|
||||
private:
|
||||
typedef void (*Load_t)(const ::HsaApiTable* table);
|
||||
typedef void (*Unload_t)();
|
||||
@@ -87,7 +92,7 @@ class ExtensionEntryPoints {
|
||||
void InitAmdExtTable();
|
||||
|
||||
// Update Amd Ext table for Api related to Images
|
||||
void UpdateAmdExtTable(void *func_ptr);
|
||||
void UpdateAmdExtTable(decltype(::hsa_amd_image_create)* func_ptr);
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(ExtensionEntryPoints);
|
||||
};
|
||||
|
||||
@@ -40,134 +40,18 @@
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "image/inc/hsa_ext_image_impl.h"
|
||||
#include "core/inc/hsa_ext_interface.h"
|
||||
#include "core/inc/runtime.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "core/inc/runtime.h"
|
||||
// Implementations for missing / unsupported extensions
|
||||
template <class R, class... ARGS> static R hsa_ext_null(ARGS...) {
|
||||
return HSA_STATUS_ERROR_NOT_INITIALIZED;
|
||||
}
|
||||
|
||||
namespace core {
|
||||
// Implementations for missing / unsupported extensions
|
||||
template <class T0>
|
||||
static T0 hsa_ext_null() {
|
||||
return HSA_STATUS_ERROR_NOT_INITIALIZED;
|
||||
}
|
||||
template <class T0, class T1>
|
||||
static T0 hsa_ext_null(T1) {
|
||||
return HSA_STATUS_ERROR_NOT_INITIALIZED;
|
||||
}
|
||||
template <class T0, class T1, class T2>
|
||||
static T0 hsa_ext_null(T1, T2) {
|
||||
return HSA_STATUS_ERROR_NOT_INITIALIZED;
|
||||
}
|
||||
template <class T0, class T1, class T2, class T3>
|
||||
static T0 hsa_ext_null(T1, T2, T3) {
|
||||
return HSA_STATUS_ERROR_NOT_INITIALIZED;
|
||||
}
|
||||
template <class T0, class T1, class T2, class T3, class T4>
|
||||
static T0 hsa_ext_null(T1, T2, T3, T4) {
|
||||
return HSA_STATUS_ERROR_NOT_INITIALIZED;
|
||||
}
|
||||
template <class T0, class T1, class T2, class T3, class T4, class T5>
|
||||
static T0 hsa_ext_null(T1, T2, T3, T4, T5) {
|
||||
return HSA_STATUS_ERROR_NOT_INITIALIZED;
|
||||
}
|
||||
template <class T0, class T1, class T2, class T3, class T4, class T5, class T6>
|
||||
static T0 hsa_ext_null(T1, T2, T3, T4, T5, T6) {
|
||||
return HSA_STATUS_ERROR_NOT_INITIALIZED;
|
||||
}
|
||||
template <class T0, class T1, class T2, class T3, class T4, class T5, class T6,
|
||||
class T7>
|
||||
static T0 hsa_ext_null(T1, T2, T3, T4, T5, T6, T7) {
|
||||
return HSA_STATUS_ERROR_NOT_INITIALIZED;
|
||||
}
|
||||
template <class T0, class T1, class T2, class T3, class T4, class T5, class T6,
|
||||
class T7, class T8>
|
||||
static T0 hsa_ext_null(T1, T2, T3, T4, T5, T6, T7, T8) {
|
||||
return HSA_STATUS_ERROR_NOT_INITIALIZED;
|
||||
}
|
||||
template <class T0, class T1, class T2, class T3, class T4, class T5, class T6,
|
||||
class T7, class T8, class T9>
|
||||
static T0 hsa_ext_null(T1, T2, T3, T4, T5, T6, T7, T8, T9) {
|
||||
return HSA_STATUS_ERROR_NOT_INITIALIZED;
|
||||
}
|
||||
template <class T0, class T1, class T2, class T3, class T4, class T5, class T6,
|
||||
class T7, class T8, class T9, class T10>
|
||||
static T0 hsa_ext_null(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10) {
|
||||
return HSA_STATUS_ERROR_NOT_INITIALIZED;
|
||||
}
|
||||
template <class T0, class T1, class T2, class T3, class T4, class T5, class T6,
|
||||
class T7, class T8, class T9, class T10, class T11>
|
||||
static T0 hsa_ext_null(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11) {
|
||||
return HSA_STATUS_ERROR_NOT_INITIALIZED;
|
||||
}
|
||||
template <class T0, class T1, class T2, class T3, class T4, class T5, class T6,
|
||||
class T7, class T8, class T9, class T10, class T11, class T12>
|
||||
static T0 hsa_ext_null(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12) {
|
||||
return HSA_STATUS_ERROR_NOT_INITIALIZED;
|
||||
}
|
||||
template <class T0, class T1, class T2, class T3, class T4, class T5, class T6,
|
||||
class T7, class T8, class T9, class T10, class T11, class T12,
|
||||
class T13>
|
||||
static T0 hsa_ext_null(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13) {
|
||||
return HSA_STATUS_ERROR_NOT_INITIALIZED;
|
||||
}
|
||||
template <class T0, class T1, class T2, class T3, class T4, class T5, class T6,
|
||||
class T7, class T8, class T9, class T10, class T11, class T12,
|
||||
class T13, class T14>
|
||||
static T0 hsa_ext_null(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,
|
||||
T14) {
|
||||
return HSA_STATUS_ERROR_NOT_INITIALIZED;
|
||||
}
|
||||
template <class T0, class T1, class T2, class T3, class T4, class T5, class T6,
|
||||
class T7, class T8, class T9, class T10, class T11, class T12,
|
||||
class T13, class T14, class T15>
|
||||
static T0 hsa_ext_null(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,
|
||||
T14, T15) {
|
||||
return HSA_STATUS_ERROR_NOT_INITIALIZED;
|
||||
}
|
||||
template <class T0, class T1, class T2, class T3, class T4, class T5, class T6,
|
||||
class T7, class T8, class T9, class T10, class T11, class T12,
|
||||
class T13, class T14, class T15, class T16>
|
||||
static T0 hsa_ext_null(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,
|
||||
T14, T15, T16) {
|
||||
return HSA_STATUS_ERROR_NOT_INITIALIZED;
|
||||
}
|
||||
template <class T0, class T1, class T2, class T3, class T4, class T5, class T6,
|
||||
class T7, class T8, class T9, class T10, class T11, class T12,
|
||||
class T13, class T14, class T15, class T16, class T17>
|
||||
static T0 hsa_ext_null(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,
|
||||
T14, T15, T16, T17) {
|
||||
return HSA_STATUS_ERROR_NOT_INITIALIZED;
|
||||
}
|
||||
template <class T0, class T1, class T2, class T3, class T4, class T5, class T6,
|
||||
class T7, class T8, class T9, class T10, class T11, class T12,
|
||||
class T13, class T14, class T15, class T16, class T17, class T18>
|
||||
static T0 hsa_ext_null(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,
|
||||
T14, T15, T16, T17, T18) {
|
||||
return HSA_STATUS_ERROR_NOT_INITIALIZED;
|
||||
}
|
||||
template <class T0, class T1, class T2, class T3, class T4, class T5, class T6,
|
||||
class T7, class T8, class T9, class T10, class T11, class T12,
|
||||
class T13, class T14, class T15, class T16, class T17, class T18,
|
||||
class T19>
|
||||
static T0 hsa_ext_null(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,
|
||||
T14, T15, T16, T17, T18, T19) {
|
||||
return HSA_STATUS_ERROR_NOT_INITIALIZED;
|
||||
}
|
||||
template <class T0, class T1, class T2, class T3, class T4, class T5, class T6,
|
||||
class T7, class T8, class T9, class T10, class T11, class T12,
|
||||
class T13, class T14, class T15, class T16, class T17, class T18,
|
||||
class T19, class T20>
|
||||
static T0 hsa_ext_null(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,
|
||||
T14, T15, T16, T17, T18, T19, T20) {
|
||||
return HSA_STATUS_ERROR_NOT_INITIALIZED;
|
||||
}
|
||||
template <class T0, class T1, class T2, class T3, class T4, class T5, class T6>
|
||||
static T0 hsa_amd_null(T1, T2, T3, T4, T5, T6) {
|
||||
return HSA_STATUS_ERROR_NOT_INITIALIZED;
|
||||
}
|
||||
|
||||
ExtensionEntryPoints::ExtensionEntryPoints() {
|
||||
InitFinalizerExtTable();
|
||||
InitImageExtTable();
|
||||
@@ -223,21 +107,28 @@ void ExtensionEntryPoints::InitAmdExtTable() {
|
||||
// Update Amd Ext table for Api related to Images.
|
||||
// @note: Interface should be updated when Amd Ext table
|
||||
// begins hosting Api's from other extension libraries
|
||||
void ExtensionEntryPoints::UpdateAmdExtTable(void *func_ptr) {
|
||||
|
||||
void ExtensionEntryPoints::UpdateAmdExtTable(decltype(::hsa_amd_image_create)* func_ptr) {
|
||||
assert(hsa_api_table_.amd_ext_api.hsa_amd_image_create_fn ==
|
||||
(decltype(hsa_amd_image_create)*)hsa_ext_null &&
|
||||
"Duplicate load of extension import.");
|
||||
assert(hsa_internal_api_table_.amd_ext_api.hsa_amd_image_create_fn ==
|
||||
(decltype(hsa_amd_image_create)*)hsa_ext_null &&
|
||||
"Duplicate load of extension import.");
|
||||
hsa_api_table_.amd_ext_api.hsa_amd_image_create_fn =
|
||||
(decltype(hsa_amd_image_create)*)func_ptr;
|
||||
hsa_internal_api_table_.amd_ext_api.hsa_amd_image_create_fn =
|
||||
(decltype(hsa_amd_image_create)*)func_ptr;
|
||||
hsa_api_table_.amd_ext_api.hsa_amd_image_create_fn = func_ptr;
|
||||
hsa_internal_api_table_.amd_ext_api.hsa_amd_image_create_fn = func_ptr;
|
||||
}
|
||||
|
||||
void ExtensionEntryPoints::UnloadImage() {
|
||||
InitAmdExtTable();
|
||||
InitImageExtTable();
|
||||
core::hsa_internal_api_table_.Reset();
|
||||
rocr::image::ReleaseImageRsrcs();
|
||||
}
|
||||
|
||||
void ExtensionEntryPoints::Unload() {
|
||||
// Reset Image apis to hsa_ext_null function
|
||||
UnloadImage();
|
||||
|
||||
for (auto lib : libs_) {
|
||||
void* ptr = os::GetExportAddress(lib, "Unload");
|
||||
if (ptr) {
|
||||
@@ -259,138 +150,17 @@ void ExtensionEntryPoints::Unload() {
|
||||
core::hsa_internal_api_table_.Reset();
|
||||
}
|
||||
|
||||
bool ExtensionEntryPoints::LoadImage(std::string library_name) {
|
||||
os::LibHandle lib = os::LoadLib(library_name);
|
||||
if (lib == NULL) {
|
||||
return false;
|
||||
}
|
||||
libs_.push_back(lib);
|
||||
|
||||
void* ptr;
|
||||
|
||||
ptr = os::GetExportAddress(lib, "hsa_ext_image_get_capability_impl");
|
||||
if (ptr != NULL) {
|
||||
assert(image_api.hsa_ext_image_get_capability_fn ==
|
||||
(decltype(::hsa_ext_image_get_capability)*)hsa_ext_null &&
|
||||
"Duplicate load of extension import.");
|
||||
image_api.hsa_ext_image_get_capability_fn =
|
||||
(decltype(::hsa_ext_image_get_capability)*)ptr;
|
||||
bool ExtensionEntryPoints::LoadImage() {
|
||||
// Consult user input on linking to Image implementation
|
||||
bool disable_image = core::Runtime::runtime_singleton_->flag().disable_image();
|
||||
if (disable_image) {
|
||||
return true;
|
||||
}
|
||||
|
||||
ptr = os::GetExportAddress(lib, "hsa_ext_image_data_get_info_impl");
|
||||
if (ptr != NULL) {
|
||||
assert(image_api.hsa_ext_image_data_get_info_fn ==
|
||||
(decltype(::hsa_ext_image_data_get_info)*)hsa_ext_null &&
|
||||
"Duplicate load of extension import.");
|
||||
image_api.hsa_ext_image_data_get_info_fn =
|
||||
(decltype(::hsa_ext_image_data_get_info)*)ptr;
|
||||
}
|
||||
// Bind to Image implementation api's
|
||||
decltype(::hsa_amd_image_create)* func;
|
||||
rocr::image::LoadImage(&image_api, &func);
|
||||
|
||||
ptr = os::GetExportAddress(lib, "hsa_ext_image_create_impl");
|
||||
if (ptr != NULL) {
|
||||
assert(image_api.hsa_ext_image_create_fn ==
|
||||
(decltype(::hsa_ext_image_create)*)hsa_ext_null &&
|
||||
"Duplicate load of extension import.");
|
||||
image_api.hsa_ext_image_create_fn = (decltype(::hsa_ext_image_create)*)ptr;
|
||||
}
|
||||
|
||||
ptr = os::GetExportAddress(lib, "hsa_ext_image_import_impl");
|
||||
if (ptr != NULL) {
|
||||
assert(image_api.hsa_ext_image_import_fn ==
|
||||
(decltype(::hsa_ext_image_import)*)hsa_ext_null &&
|
||||
"Duplicate load of extension import.");
|
||||
image_api.hsa_ext_image_import_fn = (decltype(::hsa_ext_image_import)*)ptr;
|
||||
}
|
||||
|
||||
ptr = os::GetExportAddress(lib, "hsa_ext_image_export_impl");
|
||||
if (ptr != NULL) {
|
||||
assert(image_api.hsa_ext_image_export_fn ==
|
||||
(decltype(::hsa_ext_image_export)*)hsa_ext_null &&
|
||||
"Duplicate load of extension import.");
|
||||
image_api.hsa_ext_image_export_fn = (decltype(::hsa_ext_image_export)*)ptr;
|
||||
}
|
||||
|
||||
ptr = os::GetExportAddress(lib, "hsa_ext_image_copy_impl");
|
||||
if (ptr != NULL) {
|
||||
assert(image_api.hsa_ext_image_copy_fn ==
|
||||
(decltype(::hsa_ext_image_copy)*)hsa_ext_null &&
|
||||
"Duplicate load of extension import.");
|
||||
image_api.hsa_ext_image_copy_fn = (decltype(::hsa_ext_image_copy)*)ptr;
|
||||
}
|
||||
|
||||
ptr = os::GetExportAddress(lib, "hsa_ext_image_clear_impl");
|
||||
if (ptr != NULL) {
|
||||
assert(image_api.hsa_ext_image_clear_fn ==
|
||||
(decltype(::hsa_ext_image_clear)*)hsa_ext_null &&
|
||||
"Duplicate load of extension import.");
|
||||
image_api.hsa_ext_image_clear_fn = (decltype(::hsa_ext_image_clear)*)ptr;
|
||||
}
|
||||
|
||||
ptr = os::GetExportAddress(lib, "hsa_ext_image_destroy_impl");
|
||||
if (ptr != NULL) {
|
||||
assert(image_api.hsa_ext_image_destroy_fn ==
|
||||
(decltype(::hsa_ext_image_destroy)*)hsa_ext_null &&
|
||||
"Duplicate load of extension import.");
|
||||
image_api.hsa_ext_image_destroy_fn = (decltype(::hsa_ext_image_destroy)*)ptr;
|
||||
}
|
||||
|
||||
ptr = os::GetExportAddress(lib, "hsa_ext_sampler_create_impl");
|
||||
if (ptr != NULL) {
|
||||
assert(image_api.hsa_ext_sampler_create_fn ==
|
||||
(decltype(::hsa_ext_sampler_create)*)hsa_ext_null &&
|
||||
"Duplicate load of extension import.");
|
||||
image_api.hsa_ext_sampler_create_fn = (decltype(::hsa_ext_sampler_create)*)ptr;
|
||||
}
|
||||
|
||||
ptr = os::GetExportAddress(lib, "hsa_ext_sampler_destroy_impl");
|
||||
if (ptr != NULL) {
|
||||
assert(image_api.hsa_ext_sampler_destroy_fn ==
|
||||
(decltype(::hsa_ext_sampler_destroy)*)hsa_ext_null &&
|
||||
"Duplicate load of extension import.");
|
||||
image_api.hsa_ext_sampler_destroy_fn =
|
||||
(decltype(::hsa_ext_sampler_destroy)*)ptr;
|
||||
}
|
||||
|
||||
ptr = os::GetExportAddress(lib, "hsa_ext_image_get_capability_with_layout_impl");
|
||||
if (ptr != NULL) {
|
||||
assert(image_api.hsa_ext_image_get_capability_with_layout_fn ==
|
||||
(decltype(::hsa_ext_image_get_capability_with_layout)*)hsa_ext_null &&
|
||||
"Duplicate load of extension import.");
|
||||
image_api.hsa_ext_image_get_capability_with_layout_fn =
|
||||
(decltype(::hsa_ext_image_get_capability_with_layout)*)ptr;
|
||||
}
|
||||
|
||||
ptr = os::GetExportAddress(lib, "hsa_ext_image_data_get_info_with_layout_impl");
|
||||
if (ptr != NULL) {
|
||||
assert(image_api.hsa_ext_image_data_get_info_with_layout_fn ==
|
||||
(decltype(::hsa_ext_image_data_get_info_with_layout)*)hsa_ext_null &&
|
||||
"Duplicate load of extension import.");
|
||||
image_api.hsa_ext_image_data_get_info_with_layout_fn =
|
||||
(decltype(::hsa_ext_image_data_get_info_with_layout)*)ptr;
|
||||
}
|
||||
|
||||
ptr = os::GetExportAddress(lib, "hsa_ext_image_create_with_layout_impl");
|
||||
if (ptr != NULL) {
|
||||
assert(image_api.hsa_ext_image_create_with_layout_fn ==
|
||||
(decltype(::hsa_ext_image_create_with_layout)*)hsa_ext_null &&
|
||||
"Duplicate load of extension import.");
|
||||
image_api.hsa_ext_image_create_with_layout_fn = (decltype(::hsa_ext_image_create_with_layout)*)ptr;
|
||||
}
|
||||
|
||||
ptr = os::GetExportAddress(lib, "hsa_amd_image_get_info_max_dim_impl");
|
||||
if (ptr != NULL) {
|
||||
assert(image_api.hsa_amd_image_get_info_max_dim_fn ==
|
||||
(decltype(::hsa_amd_image_get_info_max_dim)*)hsa_ext_null &&
|
||||
"Duplicate load of extension import.");
|
||||
image_api.hsa_amd_image_get_info_max_dim_fn =
|
||||
(decltype(::hsa_amd_image_get_info_max_dim)*)ptr;
|
||||
}
|
||||
|
||||
ptr = os::GetExportAddress(lib, "hsa_amd_image_create_impl");
|
||||
if (ptr != NULL) {
|
||||
UpdateAmdExtTable(ptr);
|
||||
}
|
||||
|
||||
// Initialize Version of Api Table
|
||||
image_api.version.major_id = HSA_IMAGE_API_TABLE_MAJOR_VERSION;
|
||||
image_api.version.minor_id = sizeof(ImageExtTable);
|
||||
@@ -400,11 +170,8 @@ bool ExtensionEntryPoints::LoadImage(std::string library_name) {
|
||||
hsa_internal_api_table_.CloneExts(&image_api,
|
||||
core::HsaApiTable::HSA_EXT_IMAGE_API_TABLE_ID);
|
||||
|
||||
ptr = os::GetExportAddress(lib, "Load");
|
||||
if (ptr != NULL) {
|
||||
((Load_t)ptr)(&core::hsa_internal_api_table_.hsa_api);
|
||||
}
|
||||
|
||||
// Update Amd Ext Api table Api that deals with Images
|
||||
UpdateAmdExtTable(func);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -1349,13 +1349,9 @@ void Runtime::LoadExtensions() {
|
||||
#ifdef HSA_LARGE_MODEL
|
||||
static const std::string kFinalizerLib[] = {"hsa-ext-finalize64.dll",
|
||||
"libhsa-ext-finalize64.so.1"};
|
||||
static const std::string kImageLib[] = {"hsa-ext-image64.dll",
|
||||
"libhsa-ext-image64.so.1"};
|
||||
#else
|
||||
static const std::string kFinalizerLib[] = {"hsa-ext-finalize.dll",
|
||||
"libhsa-ext-finalize.so.1"};
|
||||
static const std::string kImageLib[] = {"hsa-ext-image.dll",
|
||||
"libhsa-ext-image.so.1"};
|
||||
#endif
|
||||
|
||||
// Update Hsa Api Table with handle of Finalizer extension Apis
|
||||
@@ -1366,7 +1362,7 @@ void Runtime::LoadExtensions() {
|
||||
core::HsaApiTable::HSA_EXT_FINALIZER_API_TABLE_ID);
|
||||
|
||||
// Update Hsa Api Table with handle of Image extension Apis
|
||||
extensions_.LoadImage(kImageLib[os_index(os::current_os)]);
|
||||
extensions_.LoadImage();
|
||||
hsa_api_table_.LinkExts(&extensions_.image_api,
|
||||
core::HsaApiTable::HSA_EXT_IMAGE_API_TABLE_ID);
|
||||
}
|
||||
|
||||
@@ -113,6 +113,9 @@ class Flag {
|
||||
|
||||
var = os::GetEnvVar("HSA_NO_SCRATCH_THREAD_LIMITER");
|
||||
no_scratch_thread_limit_ = (var == "1") ? true : false;
|
||||
|
||||
var = os::GetEnvVar("HSA_DISABLE_IMAGE");
|
||||
disable_image_ = (var == "1") ? true : false;
|
||||
}
|
||||
|
||||
bool check_flat_scratch() const { return check_flat_scratch_; }
|
||||
@@ -153,6 +156,8 @@ class Flag {
|
||||
|
||||
std::string tools_lib_names() const { return tools_lib_names_; }
|
||||
|
||||
bool disable_image() const { return disable_image_; }
|
||||
|
||||
private:
|
||||
bool check_flat_scratch_;
|
||||
bool enable_vm_fault_message_;
|
||||
@@ -167,6 +172,7 @@ class Flag {
|
||||
bool fine_grain_pcie_;
|
||||
bool no_scratch_reclaim_;
|
||||
bool no_scratch_thread_limit_;
|
||||
bool disable_image_;
|
||||
|
||||
std::string enable_sdma_;
|
||||
|
||||
|
||||
@@ -326,6 +326,50 @@ static __forceinline std::string& rtrim(std::string& s) {
|
||||
|
||||
static __forceinline std::string& trim(std::string& s) { return ltrim(rtrim(s)); }
|
||||
|
||||
template <uint32_t lowBit, uint32_t highBit, typename T>
|
||||
static __forceinline uint32_t BitSelect(T p) {
|
||||
static_assert(sizeof(T) <= sizeof(uintptr_t), "Type out of range.");
|
||||
static_assert(highBit < sizeof(uintptr_t) * 8, "Bit index out of range.");
|
||||
|
||||
uintptr_t ptr = p;
|
||||
if (highBit != (sizeof(uintptr_t) * 8 - 1))
|
||||
return (uint32_t)((ptr & ((1ull << (highBit + 1)) - 1)) >> lowBit);
|
||||
else
|
||||
return (uint32_t)(ptr >> lowBit);
|
||||
}
|
||||
|
||||
inline uint32_t PtrLow16Shift8(const void* p) {
|
||||
uintptr_t ptr = reinterpret_cast<uintptr_t>(p);
|
||||
return (uint32_t)((ptr & 0xFFFFULL) >> 8);
|
||||
}
|
||||
|
||||
inline uint32_t PtrHigh64Shift16(const void* p) {
|
||||
uintptr_t ptr = reinterpret_cast<uintptr_t>(p);
|
||||
return (uint32_t)((ptr & 0xFFFFFFFFFFFF0000ULL) >> 16);
|
||||
}
|
||||
|
||||
inline uint32_t PtrLow40Shift8(const void* p) {
|
||||
uintptr_t ptr = reinterpret_cast<uintptr_t>(p);
|
||||
return (uint32_t)((ptr & 0xFFFFFFFFFFULL) >> 8);
|
||||
}
|
||||
|
||||
inline uint32_t PtrHigh64Shift40(const void* p) {
|
||||
uintptr_t ptr = reinterpret_cast<uintptr_t>(p);
|
||||
return (uint32_t)((ptr & 0xFFFFFF0000000000ULL) >> 40);
|
||||
}
|
||||
|
||||
inline uint32_t PtrLow32(const void* p) {
|
||||
return static_cast<uint32_t>(reinterpret_cast<uintptr_t>(p));
|
||||
}
|
||||
|
||||
inline uint32_t PtrHigh32(const void* p) {
|
||||
uint32_t ptr = 0;
|
||||
#ifdef HSA_LARGE_MODEL
|
||||
ptr = static_cast<uint32_t>(reinterpret_cast<uintptr_t>(p) >> 32);
|
||||
#endif
|
||||
return ptr;
|
||||
}
|
||||
|
||||
#include "atomic_helpers.h"
|
||||
|
||||
#endif // HSA_RUNTIME_CORE_UTIL_UTIIS_H_
|
||||
#endif // HSA_RUNTIME_CORE_UTIL_UTILS_H_
|
||||
|
||||
Reference in New Issue
Block a user