RPP - Enhanced Handle Initialization and API Optimization#386
Conversation
Dineshbabu-Ravichandran
commented
Jan 15, 2025
- Added rppCreate and rppDestroy for handle initialization and destruction.
- Removed unused handle APIs and constructor functions.
…ndle_modification
r-abishek
left a comment
There was a problem hiding this comment.
@Dineshbabu-Ravichandran Please address comments.
All changes after addressing comments are okay except these 4 files for this PR:
- handle.hpp
- handleocl.cpp
- handlehost.cpp
- handlehip.cpp
| RPP_ERROR_INVALID_DST_DIMS = -24 | ||
| } RppStatus; | ||
|
|
||
| typedef enum |
There was a problem hiding this comment.
Please add docs something like:
/*! \brief RPP RppBackend type enums
* \ingroup group_rppdefs
*/
| /*! \brief Creates RPP handle for HOST and HIP batch processing. | ||
| * \details Function to create a RPP handle for a batch. To be called in the beginning to initialize the RPP environment. | ||
| * \param [in] handle A pointer to RPP handle of type <tt> \ref rppHandle_t</tt>. | ||
| * \param [in] nBatchSize Batch size. |
There was a problem hiding this comment.
The \param [in] needs to be added for all new arguments
| * \retval rppStatusUnsupportedOp | ||
| */ | ||
| extern "C" SHARED_PUBLIC rppStatus_t rppCreateWithBatchSize(rppHandle_t* handle, size_t nBatchSize, Rpp32u numThreads = 0); | ||
| extern "C" SHARED_PUBLIC rppStatus_t rppCreate(rppHandle_t* handle, size_t nBatchSize, void* numThreadsOrStream, RppBackend backend = RppBackend::RPP_HOST_BACKEND); |
There was a problem hiding this comment.
Are we sure none of the voxel hip kernels use openmp and hip streams? Is there any situation where we need both threads and streams? Pls verify
There was a problem hiding this comment.
Yes I verified , There is no constructor of handle that accepts stream and numThread at the same time and also there is no api named rppCreateWithStreamAndThread .
include/rpp.h
Outdated
| extern "C" SHARED_PUBLIC rppStatus_t rppCreate(rppHandle_t* handle); | ||
|
|
||
| /*! \brief Creates RPP handle for HOST batch processing. | ||
| /*! \brief Creates RPP handle for HOST and HIP batch processing. |
There was a problem hiding this comment.
"Creates RPP handle for HOST/HIP/OCL backend batch processing."
include/rpp.h
Outdated
|
|
||
| /*! \brief Destory RPP handle. | ||
| * \details Function to destroy a RPP handle. To be called in the end to break down the RPP environment. | ||
| /*! \brief Destory RPP HOST/GPU handle. |
There was a problem hiding this comment.
"Destroys RPP handle for HOST/HIP/OCL backend batch processing."
| return rpp::try_([&] { rpp_destroy_object(handle); }); | ||
| if(backend == RppBackend::RPP_HIP_BACKEND || backend == RppBackend::RPP_OCL_BACKEND) | ||
| { | ||
| #if GPU_SUPPORT |
There was a problem hiding this comment.
The #if GPU_SUPPORT could be outside with an else-if inside.
Also, why do we need a static_cast of a reinterpret_cast?
if(backend == RppBackend::RPP_HOST_BACKEND)
{
Rpp32u numThreads = *reinterpret_cast<Rpp32u*>(numThreadsOrStream);
return rpp::try_([&] { rpp::deref(handle) = new rpp::Handle(nBatchSize, numThreads); });
}
#if GPU_SUPPORT
else if ((backend == RppBackend::RPP_HIP_BACKEND) || (backend == RppBackend::RPP_OCL_BACKEND))
{
rppAcceleratorQueue_t deviceQueue = reinterpret_cast<rppAcceleratorQueue_t>(numThreadsOrStream);
return rpp::try_([&] { rpp::deref(handle) = new rpp::Handle(deviceQueue, nBatchSize); });
}
#endif // GPU_SUPPORT
else
{
return rppStatusNotImplemented;
}
The above is okay except please change the order of arguments in "new rpp::Handle" so that nBatchSize is always first. There is a discrepancy for host and device above.
There was a problem hiding this comment.
If I directly reinterpret_cast to Rpp32u . I am getting below error :
error: cast from pointer to smaller type 'Rpp32u' (aka 'unsigned int') loses information
33 | Rpp32u numThreads = (reinterpret_cast<Rpp32u>(numThreadsOrStream));
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated when compiling for gfx908.
I changed the argument order for HIP and OCL .
| return device; | ||
| } | ||
|
|
||
| void set_device(int id) |
There was a problem hiding this comment.
Reasons to remove these 5?
- set_device()
- set_default_device()
- create_stream()
- Handle::Handle(rppAcceleratorQueue_t stream) : impl(new HandleImpl())
- Handle::Handle() : impl(new HandleImpl())
- void Handle::SetStream(rppAcceleratorQueue_t streamID) const
There was a problem hiding this comment.
- set_device() function is used inside the set_default_device()
- set_default_device() and create_stream() is used in the default constructor of handle with no argument Handle::Handle() : impl(new HandleImpl())
- We are using the constructor of handle with batchsize and thread as a arguments and batchsize and stream as a arguments . SO I removed the remaining constructors (default constructor and constructor with only stream ).
- setStream() - not called. I searched through global search and removed it .
| impl->PreInitializeBufferCPU(); | ||
| } | ||
|
|
||
| Handle::Handle() : impl(new HandleImpl()) |
There was a problem hiding this comment.
Same on handlehost. Reasons to remove?
- Handle::Handle() : impl(new HandleImpl())
There was a problem hiding this comment.
- Same for the HOST handle constructor .
- I keep the handle constructor with batchsize and threadnum as a argument.
- So I removed the remaining constructor (default constructor).
| impl->PreInitializeBuffer(); | ||
| } | ||
|
|
||
| Handle::Handle(rppAcceleratorQueue_t stream) : impl(new HandleImpl()) |
There was a problem hiding this comment.
Same for the handleocl file. Reasons to remove?
- Handle::Handle(rppAcceleratorQueue_t stream) : impl(new HandleImpl())
- Handle::Handle() : impl(new HandleImpl())
- Handle::SetStream(rppAcceleratorQueue_t streamID) const
There was a problem hiding this comment.
Same for the OCL Constructor also
- Keep only constructor with batchSize and stream as a argument to constructor .
- Removed the remaining constructor (default constructor and constructor with stream as a argument )
- SetStream() is not called on any file . I searched via global search and removed it .
| { | ||
| Handle(); | ||
| Handle(size_t nBatchSize, Rpp32u numThreads = 0); | ||
| Handle(Handle&&) noexcept; |
There was a problem hiding this comment.
Same comment for changes in this file
There was a problem hiding this comment.
I removed the declaration of the removed functions on handlehost , handlehip and handleocl file on handle file .