Add try/catch blocks to image APIs.
Change-Id: I724dcc8015ac556649278dd6cdf1ad4097aaa846
[ROCm/ROCR-Runtime commit: 248904ab26]
This commit is contained in:
@@ -42,8 +42,24 @@
|
||||
|
||||
#include "image_runtime.h"
|
||||
#include "image/inc/hsa_ext_image_impl.h"
|
||||
#include "core/inc/exceptions.h"
|
||||
|
||||
namespace rocr {
|
||||
|
||||
namespace AMD {
|
||||
hsa_status_t handleException();
|
||||
|
||||
template <class T> static __forceinline T handleExceptionT() {
|
||||
handleException();
|
||||
abort();
|
||||
return T();
|
||||
}
|
||||
} // namespace amd
|
||||
|
||||
#define TRY try {
|
||||
#define CATCH } catch(...) { return AMD::handleException(); }
|
||||
#define CATCHRET(RETURN_TYPE) } catch(...) { return AMD::handleExceptionT<RETURN_TYPE>(); }
|
||||
|
||||
namespace image {
|
||||
|
||||
//---------------------------------------------------------------------------//
|
||||
@@ -88,6 +104,7 @@ static void enforceDefaultPitch(hsa_agent_t agent,
|
||||
|
||||
hsa_status_t hsa_amd_image_get_info_max_dim(hsa_agent_t agent, hsa_agent_info_t attribute,
|
||||
void* value) {
|
||||
TRY;
|
||||
if (agent.handle == 0) {
|
||||
return HSA_STATUS_ERROR_INVALID_AGENT;
|
||||
}
|
||||
@@ -97,12 +114,14 @@ hsa_status_t hsa_amd_image_get_info_max_dim(hsa_agent_t agent, hsa_agent_info_t
|
||||
}
|
||||
|
||||
return ImageRuntime::instance()->GetImageInfoMaxDimension(agent, attribute, value);
|
||||
CATCH;
|
||||
}
|
||||
|
||||
hsa_status_t hsa_ext_image_get_capability(hsa_agent_t agent,
|
||||
hsa_ext_image_geometry_t image_geometry,
|
||||
const hsa_ext_image_format_t* image_format,
|
||||
uint32_t* capability_mask) {
|
||||
TRY;
|
||||
if (agent.handle == 0) {
|
||||
return HSA_STATUS_ERROR_INVALID_AGENT;
|
||||
}
|
||||
@@ -115,12 +134,14 @@ hsa_status_t hsa_ext_image_get_capability(hsa_agent_t agent,
|
||||
|
||||
return ImageRuntime::instance()->GetImageCapability(agent, *image_format, image_geometry,
|
||||
*capability_mask);
|
||||
CATCH;
|
||||
}
|
||||
|
||||
hsa_status_t hsa_ext_image_data_get_info(hsa_agent_t agent,
|
||||
const hsa_ext_image_descriptor_t* image_descriptor,
|
||||
hsa_access_permission_t access_permission,
|
||||
hsa_ext_image_data_info_t* image_data_info) {
|
||||
TRY;
|
||||
if (agent.handle == 0) {
|
||||
return HSA_STATUS_ERROR_INVALID_AGENT;
|
||||
}
|
||||
@@ -133,12 +154,14 @@ hsa_status_t hsa_ext_image_data_get_info(hsa_agent_t agent,
|
||||
|
||||
return ImageRuntime::instance()->GetImageSizeAndAlignment(
|
||||
agent, *image_descriptor, HSA_EXT_IMAGE_DATA_LAYOUT_OPAQUE, 0, 0, *image_data_info);
|
||||
CATCH;
|
||||
}
|
||||
|
||||
hsa_status_t hsa_ext_image_create(hsa_agent_t agent,
|
||||
const hsa_ext_image_descriptor_t* image_descriptor,
|
||||
const void* image_data, hsa_access_permission_t access_permission,
|
||||
hsa_ext_image_t* image) {
|
||||
TRY;
|
||||
if (agent.handle == 0) {
|
||||
return HSA_STATUS_ERROR_INVALID_AGENT;
|
||||
}
|
||||
@@ -150,19 +173,23 @@ hsa_status_t hsa_ext_image_create(hsa_agent_t agent,
|
||||
return ImageRuntime::instance()->CreateImageHandle(
|
||||
agent, *image_descriptor, image_data, access_permission, HSA_EXT_IMAGE_DATA_LAYOUT_OPAQUE, 0,
|
||||
0, *image);
|
||||
CATCH;
|
||||
}
|
||||
|
||||
hsa_status_t hsa_ext_image_destroy(hsa_agent_t agent, hsa_ext_image_t image) {
|
||||
TRY;
|
||||
if (agent.handle == 0) {
|
||||
return HSA_STATUS_ERROR_INVALID_AGENT;
|
||||
}
|
||||
|
||||
return ImageRuntime::instance()->DestroyImageHandle(image);
|
||||
CATCH;
|
||||
}
|
||||
|
||||
hsa_status_t hsa_ext_image_copy(hsa_agent_t agent, hsa_ext_image_t src_image,
|
||||
const hsa_dim3_t* src_offset, hsa_ext_image_t dst_image,
|
||||
const hsa_dim3_t* dst_offset, const hsa_dim3_t* range) {
|
||||
TRY;
|
||||
if (agent.handle == 0) {
|
||||
return HSA_STATUS_ERROR_INVALID_AGENT;
|
||||
}
|
||||
@@ -174,11 +201,13 @@ hsa_status_t hsa_ext_image_copy(hsa_agent_t agent, hsa_ext_image_t src_image,
|
||||
|
||||
return ImageRuntime::instance()->CopyImage(src_image, dst_image, *src_offset, *dst_offset,
|
||||
*range);
|
||||
CATCH;
|
||||
}
|
||||
|
||||
hsa_status_t hsa_ext_image_import(hsa_agent_t agent, const void* src_memory, size_t src_row_pitch,
|
||||
size_t src_slice_pitch, hsa_ext_image_t dst_image,
|
||||
const hsa_ext_image_region_t* image_region) {
|
||||
TRY;
|
||||
if (agent.handle == 0) {
|
||||
return HSA_STATUS_ERROR_INVALID_AGENT;
|
||||
}
|
||||
@@ -189,11 +218,13 @@ hsa_status_t hsa_ext_image_import(hsa_agent_t agent, const void* src_memory, siz
|
||||
|
||||
return ImageRuntime::instance()->CopyBufferToImage(src_memory, src_row_pitch, src_slice_pitch,
|
||||
dst_image, *image_region);
|
||||
CATCH;
|
||||
}
|
||||
|
||||
hsa_status_t hsa_ext_image_export(hsa_agent_t agent, hsa_ext_image_t src_image, void* dst_memory,
|
||||
size_t dst_row_pitch, size_t dst_slice_pitch,
|
||||
const hsa_ext_image_region_t* image_region) {
|
||||
TRY;
|
||||
if (agent.handle == 0) {
|
||||
return HSA_STATUS_ERROR_INVALID_AGENT;
|
||||
}
|
||||
@@ -204,10 +235,12 @@ hsa_status_t hsa_ext_image_export(hsa_agent_t agent, hsa_ext_image_t src_image,
|
||||
|
||||
return ImageRuntime::instance()->CopyImageToBuffer(src_image, dst_memory, dst_row_pitch,
|
||||
dst_slice_pitch, *image_region);
|
||||
CATCH;
|
||||
}
|
||||
|
||||
hsa_status_t hsa_ext_image_clear(hsa_agent_t agent, hsa_ext_image_t image, const void* data,
|
||||
const hsa_ext_image_region_t* image_region) {
|
||||
TRY;
|
||||
if (agent.handle == 0) {
|
||||
return HSA_STATUS_ERROR_INVALID_AGENT;
|
||||
}
|
||||
@@ -217,11 +250,13 @@ hsa_status_t hsa_ext_image_clear(hsa_agent_t agent, hsa_ext_image_t image, const
|
||||
}
|
||||
|
||||
return ImageRuntime::instance()->FillImage(image, data, *image_region);
|
||||
CATCH;
|
||||
};
|
||||
|
||||
hsa_status_t hsa_ext_sampler_create(hsa_agent_t agent,
|
||||
const hsa_ext_sampler_descriptor_t* sampler_descriptor,
|
||||
hsa_ext_sampler_t* sampler) {
|
||||
TRY;
|
||||
if (agent.handle == 0) {
|
||||
return HSA_STATUS_ERROR_INVALID_AGENT;
|
||||
}
|
||||
@@ -231,14 +266,17 @@ hsa_status_t hsa_ext_sampler_create(hsa_agent_t agent,
|
||||
}
|
||||
|
||||
return ImageRuntime::instance()->CreateSamplerHandle(agent, *sampler_descriptor, *sampler);
|
||||
CATCH;
|
||||
}
|
||||
|
||||
hsa_status_t hsa_ext_sampler_destroy(hsa_agent_t agent, hsa_ext_sampler_t sampler) {
|
||||
TRY;
|
||||
if (agent.handle == 0) {
|
||||
return HSA_STATUS_ERROR_INVALID_AGENT;
|
||||
}
|
||||
|
||||
return ImageRuntime::instance()->DestroySamplerHandle(sampler);
|
||||
CATCH;
|
||||
}
|
||||
|
||||
hsa_status_t hsa_ext_image_get_capability_with_layout(hsa_agent_t agent,
|
||||
@@ -246,6 +284,7 @@ hsa_status_t hsa_ext_image_get_capability_with_layout(hsa_agent_t agent,
|
||||
const hsa_ext_image_format_t* image_format,
|
||||
hsa_ext_image_data_layout_t image_data_layout,
|
||||
uint32_t* capability_mask) {
|
||||
TRY;
|
||||
if (agent.handle == 0) {
|
||||
return HSA_STATUS_ERROR_INVALID_AGENT;
|
||||
}
|
||||
@@ -259,6 +298,7 @@ hsa_status_t hsa_ext_image_get_capability_with_layout(hsa_agent_t agent,
|
||||
|
||||
return ImageRuntime::instance()->GetImageCapability(agent, *image_format, image_geometry,
|
||||
*capability_mask);
|
||||
CATCH;
|
||||
}
|
||||
|
||||
hsa_status_t hsa_ext_image_data_get_info_with_layout(
|
||||
@@ -266,6 +306,7 @@ hsa_status_t hsa_ext_image_data_get_info_with_layout(
|
||||
hsa_access_permission_t access_permission, hsa_ext_image_data_layout_t image_data_layout,
|
||||
size_t image_data_row_pitch, size_t image_data_slice_pitch,
|
||||
hsa_ext_image_data_info_t* image_data_info) {
|
||||
TRY;
|
||||
if (agent.handle == 0) {
|
||||
return HSA_STATUS_ERROR_INVALID_AGENT;
|
||||
}
|
||||
@@ -282,12 +323,14 @@ hsa_status_t hsa_ext_image_data_get_info_with_layout(
|
||||
return ImageRuntime::instance()->GetImageSizeAndAlignment(
|
||||
agent, *image_descriptor, image_data_layout, image_data_row_pitch, image_data_slice_pitch,
|
||||
*image_data_info);
|
||||
CATCH;
|
||||
}
|
||||
|
||||
hsa_status_t hsa_ext_image_create_with_layout(
|
||||
hsa_agent_t agent, const hsa_ext_image_descriptor_t* image_descriptor, const void* image_data,
|
||||
hsa_access_permission_t access_permission, hsa_ext_image_data_layout_t image_data_layout,
|
||||
size_t image_data_row_pitch, size_t image_data_slice_pitch, hsa_ext_image_t* image) {
|
||||
TRY;
|
||||
if (agent.handle == 0) {
|
||||
return HSA_STATUS_ERROR_INVALID_AGENT;
|
||||
}
|
||||
@@ -302,6 +345,7 @@ hsa_status_t hsa_ext_image_create_with_layout(
|
||||
return ImageRuntime::instance()->CreateImageHandle(
|
||||
agent, *image_descriptor, image_data, access_permission, image_data_layout,
|
||||
image_data_row_pitch, image_data_slice_pitch, *image);
|
||||
CATCH;
|
||||
}
|
||||
|
||||
hsa_status_t hsa_amd_image_create(hsa_agent_t agent,
|
||||
@@ -309,6 +353,7 @@ hsa_status_t hsa_amd_image_create(hsa_agent_t agent,
|
||||
const hsa_amd_image_descriptor_t* image_layout,
|
||||
const void* image_data, hsa_access_permission_t access_permission,
|
||||
hsa_ext_image_t* image) {
|
||||
TRY;
|
||||
if (agent.handle == 0) {
|
||||
return HSA_STATUS_ERROR_INVALID_AGENT;
|
||||
}
|
||||
@@ -319,6 +364,7 @@ hsa_status_t hsa_amd_image_create(hsa_agent_t agent,
|
||||
|
||||
return ImageRuntime::instance()->CreateImageHandleWithLayout(
|
||||
agent, *image_descriptor, image_layout, image_data, access_permission, *image);
|
||||
CATCH;
|
||||
}
|
||||
|
||||
void LoadImage(core::ImageExtTableInternal* image_api,
|
||||
|
||||
Reference in New Issue
Block a user