Skip to content

Commit

Permalink
Merge pull request #1512 from DBDuncan/duncan/fix_pi_mem_leak
Browse files Browse the repository at this point in the history
[Bindless][Exp] Remove phMem argument from bindless image creation functions
  • Loading branch information
kbenzie authored May 17, 2024
2 parents b7c8930 + bbb04b6 commit 056d653
Show file tree
Hide file tree
Showing 15 changed files with 19 additions and 121 deletions.
6 changes: 0 additions & 6 deletions include/ur_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -7551,7 +7551,6 @@ urBindlessImagesImageFreeExp(
/// - ::UR_RESULT_ERROR_INVALID_NULL_POINTER
/// + `NULL == pImageFormat`
/// + `NULL == pImageDesc`
/// + `NULL == phMem`
/// + `NULL == phImage`
/// - ::UR_RESULT_ERROR_INVALID_CONTEXT
/// - ::UR_RESULT_ERROR_INVALID_VALUE
Expand All @@ -7566,7 +7565,6 @@ urBindlessImagesUnsampledImageCreateExp(
ur_exp_image_mem_handle_t hImageMem, ///< [in] handle to memory from which to create the image
const ur_image_format_t *pImageFormat, ///< [in] pointer to image format specification
const ur_image_desc_t *pImageDesc, ///< [in] pointer to image description
ur_mem_handle_t *phMem, ///< [out] pointer to handle of image object created
ur_exp_image_handle_t *phImage ///< [out] pointer to handle of image object created
);

Expand All @@ -7590,7 +7588,6 @@ urBindlessImagesUnsampledImageCreateExp(
/// - ::UR_RESULT_ERROR_INVALID_NULL_POINTER
/// + `NULL == pImageFormat`
/// + `NULL == pImageDesc`
/// + `NULL == phMem`
/// + `NULL == phImage`
/// - ::UR_RESULT_ERROR_INVALID_CONTEXT
/// - ::UR_RESULT_ERROR_INVALID_VALUE
Expand All @@ -7607,7 +7604,6 @@ urBindlessImagesSampledImageCreateExp(
const ur_image_format_t *pImageFormat, ///< [in] pointer to image format specification
const ur_image_desc_t *pImageDesc, ///< [in] pointer to image description
ur_sampler_handle_t hSampler, ///< [in] sampler to be used
ur_mem_handle_t *phMem, ///< [out] pointer to handle of image object created
ur_exp_image_handle_t *phImage ///< [out] pointer to handle of image object created
);

Expand Down Expand Up @@ -10708,7 +10704,6 @@ typedef struct ur_bindless_images_unsampled_image_create_exp_params_t {
ur_exp_image_mem_handle_t *phImageMem;
const ur_image_format_t **ppImageFormat;
const ur_image_desc_t **ppImageDesc;
ur_mem_handle_t **pphMem;
ur_exp_image_handle_t **pphImage;
} ur_bindless_images_unsampled_image_create_exp_params_t;

Expand All @@ -10723,7 +10718,6 @@ typedef struct ur_bindless_images_sampled_image_create_exp_params_t {
const ur_image_format_t **ppImageFormat;
const ur_image_desc_t **ppImageDesc;
ur_sampler_handle_t *phSampler;
ur_mem_handle_t **pphMem;
ur_exp_image_handle_t **pphImage;
} ur_bindless_images_sampled_image_create_exp_params_t;

Expand Down
2 changes: 0 additions & 2 deletions include/ur_ddi.h
Original file line number Diff line number Diff line change
Expand Up @@ -1523,7 +1523,6 @@ typedef ur_result_t(UR_APICALL *ur_pfnBindlessImagesUnsampledImageCreateExp_t)(
ur_exp_image_mem_handle_t,
const ur_image_format_t *,
const ur_image_desc_t *,
ur_mem_handle_t *,
ur_exp_image_handle_t *);

///////////////////////////////////////////////////////////////////////////////
Expand All @@ -1535,7 +1534,6 @@ typedef ur_result_t(UR_APICALL *ur_pfnBindlessImagesSampledImageCreateExp_t)(
const ur_image_format_t *,
const ur_image_desc_t *,
ur_sampler_handle_t,
ur_mem_handle_t *,
ur_exp_image_handle_t *);

///////////////////////////////////////////////////////////////////////////////
Expand Down
12 changes: 0 additions & 12 deletions include/ur_print.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14318,12 +14318,6 @@ inline std::ostream &operator<<(std::ostream &os, [[maybe_unused]] const struct
ur::details::printPtr(os,
*(params->ppImageDesc));

os << ", ";
os << ".phMem = ";

ur::details::printPtr(os,
*(params->pphMem));

os << ", ";
os << ".phImage = ";

Expand Down Expand Up @@ -14374,12 +14368,6 @@ inline std::ostream &operator<<(std::ostream &os, [[maybe_unused]] const struct
ur::details::printPtr(os,
*(params->phSampler));

os << ", ";
os << ".phMem = ";

ur::details::printPtr(os,
*(params->pphMem));

os << ", ";
os << ".phImage = ";

Expand Down
6 changes: 0 additions & 6 deletions scripts/core/exp-bindless-images.yml
Original file line number Diff line number Diff line change
Expand Up @@ -435,9 +435,6 @@ params:
- type: "const $x_image_desc_t*"
name: pImageDesc
desc: "[in] pointer to image description"
- type: $x_mem_handle_t*
name: phMem
desc: "[out] pointer to handle of image object created"
- type: $x_exp_image_handle_t*
name: phImage
desc: "[out] pointer to handle of image object created"
Expand Down Expand Up @@ -475,9 +472,6 @@ params:
- type: $x_sampler_handle_t
name: hSampler
desc: "[in] sampler to be used"
- type: $x_mem_handle_t*
name: phMem
desc: "[out] pointer to handle of image object created"
- type: $x_exp_image_handle_t*
name: phImage
desc: "[out] pointer to handle of image object created"
Expand Down
22 changes: 2 additions & 20 deletions source/adapters/cuda/image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urBindlessImagesImageFreeExp(
UR_APIEXPORT ur_result_t UR_APICALL urBindlessImagesUnsampledImageCreateExp(
ur_context_handle_t hContext, ur_device_handle_t hDevice,
ur_exp_image_mem_handle_t hImageMem, const ur_image_format_t *pImageFormat,
const ur_image_desc_t *pImageDesc, ur_mem_handle_t *phMem,
[[maybe_unused]] const ur_image_desc_t *pImageDesc,
ur_exp_image_handle_t *phImage) {
UR_ASSERT((hContext->getDevice()->get() == hDevice->get()),
UR_RESULT_ERROR_INVALID_CONTEXT);
Expand Down Expand Up @@ -523,15 +523,6 @@ UR_APIEXPORT ur_result_t UR_APICALL urBindlessImagesUnsampledImageCreateExp(
UR_CHECK_ERROR(cuSurfObjectCreate(&surface, &image_res_desc));
*phImage = (ur_exp_image_handle_t)surface;

auto urMemObj = std::unique_ptr<ur_mem_handle_t_>(new ur_mem_handle_t_{
hContext, (CUarray)hImageMem, surface, pImageDesc->type});

if (urMemObj == nullptr) {
return UR_RESULT_ERROR_OUT_OF_HOST_MEMORY;
}

*phMem = urMemObj.release();

} catch (ur_result_t Err) {
return Err;
} catch (...) {
Expand All @@ -545,7 +536,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urBindlessImagesSampledImageCreateExp(
ur_context_handle_t hContext, ur_device_handle_t hDevice,
ur_exp_image_mem_handle_t hImageMem, const ur_image_format_t *pImageFormat,
const ur_image_desc_t *pImageDesc, ur_sampler_handle_t hSampler,
ur_mem_handle_t *phMem, ur_exp_image_handle_t *phImage) {
ur_exp_image_handle_t *phImage) {
UR_ASSERT((hContext->getDevice()->get() == hDevice->get()),
UR_RESULT_ERROR_INVALID_CONTEXT);

Expand Down Expand Up @@ -611,15 +602,6 @@ UR_APIEXPORT ur_result_t UR_APICALL urBindlessImagesSampledImageCreateExp(
UR_CHECK_ERROR(
urTextureCreate(hSampler, pImageDesc, image_res_desc, phImage));

auto urMemObj = std::unique_ptr<ur_mem_handle_t_>(new ur_mem_handle_t_{
hContext, (CUarray)hImageMem, (CUtexObject)*phImage, hSampler,
pImageDesc->type});

if (urMemObj == nullptr) {
return UR_RESULT_ERROR_OUT_OF_HOST_MEMORY;
}

*phMem = urMemObj.release();
} catch (ur_result_t Err) {
return Err;
} catch (...) {
Expand Down
2 changes: 0 additions & 2 deletions source/adapters/hip/image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ UR_APIEXPORT ur_result_t UR_APICALL urBindlessImagesUnsampledImageCreateExp(
[[maybe_unused]] ur_exp_image_mem_handle_t hImageMem,
[[maybe_unused]] const ur_image_format_t *pImageFormat,
[[maybe_unused]] const ur_image_desc_t *pImageDesc,
[[maybe_unused]] ur_mem_handle_t *phMem,
[[maybe_unused]] ur_exp_image_handle_t *phImage) {
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
}
Expand All @@ -71,7 +70,6 @@ UR_APIEXPORT ur_result_t UR_APICALL urBindlessImagesSampledImageCreateExp(
[[maybe_unused]] const ur_image_format_t *pImageFormat,
[[maybe_unused]] const ur_image_desc_t *pImageDesc,
[[maybe_unused]] ur_sampler_handle_t hSampler,
[[maybe_unused]] ur_mem_handle_t *phMem,
[[maybe_unused]] ur_exp_image_handle_t *phImage) {
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
}
Expand Down
14 changes: 4 additions & 10 deletions source/adapters/level_zero/image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -656,13 +656,12 @@ UR_APIEXPORT ur_result_t UR_APICALL urBindlessImagesImageFreeExp(
UR_APIEXPORT ur_result_t UR_APICALL urBindlessImagesUnsampledImageCreateExp(
ur_context_handle_t hContext, ur_device_handle_t hDevice,
ur_exp_image_mem_handle_t hImageMem, const ur_image_format_t *pImageFormat,
const ur_image_desc_t *pImageDesc, ur_mem_handle_t *phMem,
ur_exp_image_handle_t *phImage) {
const ur_image_desc_t *pImageDesc, ur_exp_image_handle_t *phImage) {
std::shared_lock<ur_shared_mutex> Lock(hContext->Mutex);

UR_ASSERT(hContext && hDevice && hImageMem,
UR_RESULT_ERROR_INVALID_NULL_HANDLE);
UR_ASSERT(pImageFormat && pImageDesc && phMem && phImage,
UR_ASSERT(pImageFormat && pImageDesc && phImage,
UR_RESULT_ERROR_INVALID_NULL_POINTER);

ZeStruct<ze_image_desc_t> ZeImageDesc;
Expand All @@ -687,11 +686,8 @@ UR_APIEXPORT ur_result_t UR_APICALL urBindlessImagesUnsampledImageCreateExp(
UrImage->ZeImage, &ZeImage));
ZE2UR_CALL(zeContextMakeImageResident,
(hContext->ZeContext, hDevice->ZeDevice, ZeImage));
UR_CALL(createUrMemFromZeImage(hContext, ZeImage, /*OwnZeMemHandle*/ true,
ZeImageDesc, phMem));
} else {
ZeImage = UrImage->ZeImage;
*phMem = nullptr;
}
} else if (MemAllocProperties.type == ZE_MEMORY_TYPE_DEVICE) {
ze_image_pitched_exp_desc_t PitchedDesc;
Expand All @@ -710,8 +706,6 @@ UR_APIEXPORT ur_result_t UR_APICALL urBindlessImagesUnsampledImageCreateExp(
&ZeImageDesc, &ZeImage));
ZE2UR_CALL(zeContextMakeImageResident,
(hContext->ZeContext, hDevice->ZeDevice, ZeImage));
UR_CALL(createUrMemFromZeImage(hContext, ZeImage, /*OwnZeMemHandle*/ true,
ZeImageDesc, phMem));
} else {
return UR_RESULT_ERROR_INVALID_VALUE;
}
Expand Down Expand Up @@ -741,10 +735,10 @@ UR_APIEXPORT ur_result_t UR_APICALL urBindlessImagesSampledImageCreateExp(
ur_context_handle_t hContext, ur_device_handle_t hDevice,
ur_exp_image_mem_handle_t hImageMem, const ur_image_format_t *pImageFormat,
const ur_image_desc_t *pImageDesc, ur_sampler_handle_t hSampler,
ur_mem_handle_t *phMem, ur_exp_image_handle_t *phImage) {
ur_exp_image_handle_t *phImage) {

UR_CALL(urBindlessImagesUnsampledImageCreateExp(
hContext, hDevice, hImageMem, pImageFormat, pImageDesc, phMem, phImage));
hContext, hDevice, hImageMem, pImageFormat, pImageDesc, phImage));

struct combined_sampled_image_handle {
uint64_t RawImageHandle;
Expand Down
2 changes: 0 additions & 2 deletions source/adapters/native_cpu/image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ UR_APIEXPORT ur_result_t UR_APICALL urBindlessImagesUnsampledImageCreateExp(
[[maybe_unused]] ur_exp_image_mem_handle_t hImageMem,
[[maybe_unused]] const ur_image_format_t *pImageFormat,
[[maybe_unused]] const ur_image_desc_t *pImageDesc,
[[maybe_unused]] ur_mem_handle_t *phMem,
[[maybe_unused]] ur_exp_image_handle_t *phImage) {
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
}
Expand All @@ -71,7 +70,6 @@ UR_APIEXPORT ur_result_t UR_APICALL urBindlessImagesSampledImageCreateExp(
[[maybe_unused]] const ur_image_format_t *pImageFormat,
[[maybe_unused]] const ur_image_desc_t *pImageDesc,
[[maybe_unused]] ur_sampler_handle_t hSampler,
[[maybe_unused]] ur_mem_handle_t *phMem,
[[maybe_unused]] ur_exp_image_handle_t *phImage) {
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
}
Expand Down
11 changes: 2 additions & 9 deletions source/adapters/null/ur_nullddi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4292,7 +4292,6 @@ __urdlllocal ur_result_t UR_APICALL urBindlessImagesUnsampledImageCreateExp(
const ur_image_format_t
*pImageFormat, ///< [in] pointer to image format specification
const ur_image_desc_t *pImageDesc, ///< [in] pointer to image description
ur_mem_handle_t *phMem, ///< [out] pointer to handle of image object created
ur_exp_image_handle_t
*phImage ///< [out] pointer to handle of image object created
) try {
Expand All @@ -4303,12 +4302,9 @@ __urdlllocal ur_result_t UR_APICALL urBindlessImagesUnsampledImageCreateExp(
d_context.urDdiTable.BindlessImagesExp.pfnUnsampledImageCreateExp;
if (nullptr != pfnUnsampledImageCreateExp) {
result = pfnUnsampledImageCreateExp(hContext, hDevice, hImageMem,
pImageFormat, pImageDesc, phMem,
phImage);
pImageFormat, pImageDesc, phImage);
} else {
// generic implementation
*phMem = reinterpret_cast<ur_mem_handle_t>(d_context.get());

*phImage = reinterpret_cast<ur_exp_image_handle_t>(d_context.get());
}

Expand All @@ -4328,7 +4324,6 @@ __urdlllocal ur_result_t UR_APICALL urBindlessImagesSampledImageCreateExp(
*pImageFormat, ///< [in] pointer to image format specification
const ur_image_desc_t *pImageDesc, ///< [in] pointer to image description
ur_sampler_handle_t hSampler, ///< [in] sampler to be used
ur_mem_handle_t *phMem, ///< [out] pointer to handle of image object created
ur_exp_image_handle_t
*phImage ///< [out] pointer to handle of image object created
) try {
Expand All @@ -4340,11 +4335,9 @@ __urdlllocal ur_result_t UR_APICALL urBindlessImagesSampledImageCreateExp(
if (nullptr != pfnSampledImageCreateExp) {
result =
pfnSampledImageCreateExp(hContext, hDevice, hImageMem, pImageFormat,
pImageDesc, hSampler, phMem, phImage);
pImageDesc, hSampler, phImage);
} else {
// generic implementation
*phMem = reinterpret_cast<ur_mem_handle_t>(d_context.get());

*phImage = reinterpret_cast<ur_exp_image_handle_t>(d_context.get());
}

Expand Down
2 changes: 0 additions & 2 deletions source/adapters/opencl/image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ UR_APIEXPORT ur_result_t UR_APICALL urBindlessImagesUnsampledImageCreateExp(
[[maybe_unused]] ur_exp_image_mem_handle_t hImageMem,
[[maybe_unused]] const ur_image_format_t *pImageFormat,
[[maybe_unused]] const ur_image_desc_t *pImageDesc,
[[maybe_unused]] ur_mem_handle_t *phMem,
[[maybe_unused]] ur_exp_image_handle_t *phImage) {
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
}
Expand All @@ -71,7 +70,6 @@ UR_APIEXPORT ur_result_t UR_APICALL urBindlessImagesSampledImageCreateExp(
[[maybe_unused]] const ur_image_format_t *pImageFormat,
[[maybe_unused]] const ur_image_desc_t *pImageDesc,
[[maybe_unused]] ur_sampler_handle_t hSampler,
[[maybe_unused]] ur_mem_handle_t *phMem,
[[maybe_unused]] ur_exp_image_handle_t *phImage) {
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
}
Expand Down
11 changes: 4 additions & 7 deletions source/loader/layers/tracing/ur_trcddi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4606,7 +4606,6 @@ __urdlllocal ur_result_t UR_APICALL urBindlessImagesUnsampledImageCreateExp(
const ur_image_format_t
*pImageFormat, ///< [in] pointer to image format specification
const ur_image_desc_t *pImageDesc, ///< [in] pointer to image description
ur_mem_handle_t *phMem, ///< [out] pointer to handle of image object created
ur_exp_image_handle_t
*phImage ///< [out] pointer to handle of image object created
) {
Expand All @@ -4618,14 +4617,13 @@ __urdlllocal ur_result_t UR_APICALL urBindlessImagesUnsampledImageCreateExp(
}

ur_bindless_images_unsampled_image_create_exp_params_t params = {
&hContext, &hDevice, &hImageMem, &pImageFormat,
&pImageDesc, &phMem, &phImage};
&hContext, &hDevice, &hImageMem, &pImageFormat, &pImageDesc, &phImage};
uint64_t instance = context.notify_begin(
UR_FUNCTION_BINDLESS_IMAGES_UNSAMPLED_IMAGE_CREATE_EXP,
"urBindlessImagesUnsampledImageCreateExp", &params);

ur_result_t result = pfnUnsampledImageCreateExp(
hContext, hDevice, hImageMem, pImageFormat, pImageDesc, phMem, phImage);
hContext, hDevice, hImageMem, pImageFormat, pImageDesc, phImage);

context.notify_end(UR_FUNCTION_BINDLESS_IMAGES_UNSAMPLED_IMAGE_CREATE_EXP,
"urBindlessImagesUnsampledImageCreateExp", &params,
Expand All @@ -4645,7 +4643,6 @@ __urdlllocal ur_result_t UR_APICALL urBindlessImagesSampledImageCreateExp(
*pImageFormat, ///< [in] pointer to image format specification
const ur_image_desc_t *pImageDesc, ///< [in] pointer to image description
ur_sampler_handle_t hSampler, ///< [in] sampler to be used
ur_mem_handle_t *phMem, ///< [out] pointer to handle of image object created
ur_exp_image_handle_t
*phImage ///< [out] pointer to handle of image object created
) {
Expand All @@ -4658,14 +4655,14 @@ __urdlllocal ur_result_t UR_APICALL urBindlessImagesSampledImageCreateExp(

ur_bindless_images_sampled_image_create_exp_params_t params = {
&hContext, &hDevice, &hImageMem, &pImageFormat,
&pImageDesc, &hSampler, &phMem, &phImage};
&pImageDesc, &hSampler, &phImage};
uint64_t instance = context.notify_begin(
UR_FUNCTION_BINDLESS_IMAGES_SAMPLED_IMAGE_CREATE_EXP,
"urBindlessImagesSampledImageCreateExp", &params);

ur_result_t result =
pfnSampledImageCreateExp(hContext, hDevice, hImageMem, pImageFormat,
pImageDesc, hSampler, phMem, phImage);
pImageDesc, hSampler, phImage);

context.notify_end(UR_FUNCTION_BINDLESS_IMAGES_SAMPLED_IMAGE_CREATE_EXP,
"urBindlessImagesSampledImageCreateExp", &params,
Expand Down
Loading

0 comments on commit 056d653

Please sign in to comment.