You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I suggest creating a vkFFT_Error module, where VkFFTResult type definition and getVkFFTErrorString(...) function would be moved. Plus the module would contain new macros VKFFT_CHECK(...) and VKFFT_CHECK_RESULT(...).
The idea is that the library could use a error handling machanism base on goto. Here is the original code:
And here is the proposed error handling mechanism. It creates broken and brokenNoDelete labels that are used when an error occures. The benefit is that the code is more readible and you needn't to write deleteVkFFT each time.
However I think that we can take this idea further and define those 2 macros. In each function a resFFT variable shall be defined as it will be used to pass the error code.
The first one can be used to assert a boolean expression. In case it evaluates to false the resFFT variable is set to vkfftResult error and it jumps to the specified lable where the resources should be released.
The second checks an expression that returns a VkFFTResult. It is first evaluated into a temporary variable and if the expression was unsuccessful, it sets up the resFFT variable and jumps to the label.
#defineVKFFT_CHECK(boolExpr, label, vkfftResult) \
do { \
if (!(boolExpr)) { \
resFFT = (vkfftResult); \
goto label; \
} \
} while (0)
#defineVKFFT_CHECK_RESULT(vkfftExpr, label) \
do { \
VkFFTResult _resFFT = (vkfftExpr); \
if (_resFFT != VKFFT_SUCCESS) { \
resFFT = _resFFT; \
goto label; \
} \
} while (0)
The example rewritten using those macros would be like:
I think that this change would shorten the code very much and will also improve the overall code quality. Plus we can define macros for backend's error values like VKFFT_CHECK_RESULT_CUDA or VKFFT_CHECK_RESULT_HIP.
The text was updated successfully, but these errors were encountered:
Sorry, I don't see how this shortens code significantly. It adds many jumps and often the VKFFT_CHECK and VKFFT_CHECK_RESULT behavior is different from the proposed base function - sometimes they have to also clear local resources. I also feel like using goto will raise quite some red flags in people's eyes. I personally like it when everything is located nearby so having an additional line but avoiding full file jumps is fine by me. If more people decide that your approach is better we can come back to discussing it in the future.
Hi,
I suggest creating a
vkFFT_Error
module, whereVkFFTResult
type definition andgetVkFFTErrorString(...)
function would be moved. Plus the module would contain new macrosVKFFT_CHECK(...)
andVKFFT_CHECK_RESULT(...)
.The idea is that the library could use a error handling machanism base on
goto
. Here is the original code:And here is the proposed error handling mechanism. It creates
broken
andbrokenNoDelete
labels that are used when an error occures. The benefit is that the code is more readible and you needn't to writedeleteVkFFT
each time.However I think that we can take this idea further and define those 2 macros. In each function a
resFFT
variable shall be defined as it will be used to pass the error code.false
theresFFT
variable is set tovkfftResult
error and it jumps to the specified lable where the resources should be released.VkFFTResult
. It is first evaluated into a temporary variable and if the expression was unsuccessful, it sets up theresFFT
variable and jumps to thelabel
.The example rewritten using those macros would be like:
I think that this change would shorten the code very much and will also improve the overall code quality. Plus we can define macros for backend's error values like
VKFFT_CHECK_RESULT_CUDA
orVKFFT_CHECK_RESULT_HIP
.The text was updated successfully, but these errors were encountered: