-
Notifications
You must be signed in to change notification settings - Fork 787
Change PI_CALL syntax from PI_CALL(pi, ...Args) to PI_CALL(pi)(...Args); #843
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Change PI_CALL syntax from PI_CALL(pi, ...Args) to PI_CALL(pi)(...Args); #843
Conversation
review only the last commit. |
Some cleaning of comments is needed. |
It would be nice if you put rationale for such changes in the commit message. |
@@ -86,13 +86,13 @@ template <typename AllocatorT> class SYCLMemObjT : public SYCLMemObjI { | |||
|
|||
RT::PiMem Mem = pi::cast<RT::PiMem>(MInteropMemObject); | |||
RT::PiContext Context = nullptr; | |||
PI_CALL(RT::piMemGetInfo, Mem, CL_MEM_CONTEXT, sizeof(Context), &Context, | |||
nullptr); | |||
RT::piCheckResult(PI_CALL_NOCHECK(piMemGetInfo)( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks...kind of strange: what so specific is being done by piCheckResult
that cannot be done by regular PI_CALL
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we even need piCheckResult. We should write error specific result checking for each pi invocation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was a mistake. I think it may have happened because of the changes being done in stages.In some intermediate stage I have chosen PI_CALL_RESULT for some reason and then changed it to this directly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we even need piCheckResult. We should write error specific result checking for each pi invocation.
Are you saying at each PI_CALL site, we should check the error return code and perform an action appropriately?
The usage of piCheckResult() API or in PI_CALL, means that the site of call only wants to check if a PI_SUCCESS is received and it throws a runtime_error.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@romanovvlad Please confirm if i understood you correct/addressed your concern.
sycl/include/CL/sycl/detail/pi.hpp
Outdated
if (PI_TRACE_ENABLED) { | ||
std::cout << "---> " << m_FnName << "("; | ||
printArgs(args...); | ||
} | ||
|
||
auto r = m_FnPtr(args...); | ||
PiResult r = m_FnPtr(args...); | ||
|
||
if (m_TraceEnabled) { | ||
if (PI_TRACE_ENABLED) { | ||
std::cout << ") ---> "; | ||
std::cout << (print(r), "") << std::endl; | ||
} | ||
return r; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, +2 getenv
calls on each PI API call, right? I guess this is some kind of overkill and definitely will affect performance
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changed the code.
sycl/include/CL/sycl/detail/pi.hpp
Outdated
#define _PI_API(api) \ | ||
template <> \ | ||
Trace<decltype(&::api), \ | ||
(offsetof(_pi_plugin::FunctionPointers, api))>::Trace(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the implementation missing here (might be further below)?
Is this specialization required? Might it work to declare the constructor inside the Trace
class as Trace() = default;
(and declaring the function pointer inside the class as follows FnType m_FnPtr = nullptr;
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The implementation is in pi.cpp
I'm sorry I didn't understand your suggestion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bjoernknafla Can you explain your suggestion again?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added suggested changes to commit#5
@@ -86,13 +86,13 @@ template <typename AllocatorT> class SYCLMemObjT : public SYCLMemObjI { | |||
|
|||
RT::PiMem Mem = pi::cast<RT::PiMem>(MInteropMemObject); | |||
RT::PiContext Context = nullptr; | |||
PI_CALL(RT::piMemGetInfo, Mem, CL_MEM_CONTEXT, sizeof(Context), &Context, | |||
nullptr); | |||
RT::piCheckResult(PI_CALL_NOCHECK(piMemGetInfo)( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was a mistake. I think it may have happened because of the changes being done in stages.In some intermediate stage I have chosen PI_CALL_RESULT for some reason and then changed it to this directly.
@@ -86,13 +86,13 @@ template <typename AllocatorT> class SYCLMemObjT : public SYCLMemObjI { | |||
|
|||
RT::PiMem Mem = pi::cast<RT::PiMem>(MInteropMemObject); | |||
RT::PiContext Context = nullptr; | |||
PI_CALL(RT::piMemGetInfo, Mem, CL_MEM_CONTEXT, sizeof(Context), &Context, | |||
nullptr); | |||
RT::piCheckResult(PI_CALL_NOCHECK(piMemGetInfo)( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we even need piCheckResult. We should write error specific result checking for each pi invocation.
Are you saying at each PI_CALL site, we should check the error return code and perform an action appropriately?
The usage of piCheckResult() API or in PI_CALL, means that the site of call only wants to check if a PI_SUCCESS is received and it throws a runtime_error.
sycl/include/CL/sycl/detail/pi.hpp
Outdated
if (PI_TRACE_ENABLED) { | ||
std::cout << "---> " << m_FnName << "("; | ||
printArgs(args...); | ||
} | ||
|
||
auto r = m_FnPtr(args...); | ||
PiResult r = m_FnPtr(args...); | ||
|
||
if (m_TraceEnabled) { | ||
if (PI_TRACE_ENABLED) { | ||
std::cout << ") ---> "; | ||
std::cout << (print(r), "") << std::endl; | ||
} | ||
return r; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changed the code.
sycl/include/CL/sycl/detail/pi.hpp
Outdated
#define _PI_API(api) \ | ||
template <> \ | ||
Trace<decltype(&::api), \ | ||
(offsetof(_pi_plugin::FunctionPointers, api))>::Trace(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The implementation is in pi.cpp
I'm sorry I didn't understand your suggestion.
@smaslov-intel Please check the changes. |
@smaslov-intel Please check the clang-format changes. |
Is it possible to just alter the clang-format at a much lower directory? It seems no one alters the 'root' version ever in community. BUT, I suspect you could add sometihng at the /sycl/include level. |
Yes. I can do that. There is no .clang-format file in sycl folder. |
If it'll work, I think just the root 'sycl' directory would be fine. |
1000107
to
be01470
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mostly looks good to me, just rather minor suggestions.
sycl/include/CL/sycl/detail/pi.hpp
Outdated
// TODO: Absorb this utility in Trace Class | ||
template <typename Exception> inline void piCheckThrow(PiResult pi_result) { | ||
template <typename Exception = cl::sycl::runtime_error> | ||
inline void piCheckResult(PiResult pi_result) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we decided to not prepend with "pi" utilities in "pi" namespace, so this would be just checkResult, or maybe better check PiResult
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
sycl/include/CL/sycl/detail/pi.hpp
Outdated
template <typename... Args> PiResult operator()(Args... args) { | ||
if (m_TraceEnabled) | ||
bool enableTrace = PI_TRACE_ENABLED; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is still a getenv() per each PI call, which is redundant. Please make this a static member of the class and initialize just once.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
sycl/include/CL/sycl/detail/pi.hpp
Outdated
|
||
template <typename FnType> class Trace { | ||
template <typename FnType, size_t FnOffset> class Trace { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add comments about what this class is doing, and I think it should be named "Call", and not "Trace" as this is its primary functionality. Also a good place to explain in comment what the template arguments are for.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed to CallPi.
sycl/include/CL/sycl/detail/pi.hpp
Outdated
bool Trace<FnType>::m_TraceEnabled = (std::getenv("SYCL_PI_TRACE") != nullptr); | ||
template <typename FnType, size_t FnOffset, | ||
typename Exception = cl::sycl::runtime_error> | ||
class TraceCheck : private Trace<FnType, FnOffset> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TraceCheck -> CallAndCheck
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changed to CallPiAndCheck
std::cout << ") ---> "; | ||
std::cout << (print(r), "") << std::endl; | ||
} | ||
return r; | ||
} | ||
}; | ||
|
||
template <typename FnType> | ||
bool Trace<FnType>::m_TraceEnabled = (std::getenv("SYCL_PI_TRACE") != nullptr); | ||
template <typename FnType, size_t FnOffset, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the header, please explain the interface here, i.e. what the exception argument stands for, and what the class is for
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done. Please see if it looks good.
sycl/include/CL/sycl/detail/pi.hpp
Outdated
RT::initialize(); \ | ||
RT::piCheckResult(PI_TRACE(pi)(__VA_ARGS__)); \ | ||
} | ||
#define PI_ASSERT(cond, msg) RT::assertion((cond), "assert: " msg); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why do we need this macro?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in Pi::Cast. Moved it closer to the API.
|
||
#define PI_TRACE_ONLY(func) RT::Trace<decltype(func)>(func, #func) | ||
namespace RT = cl::sycl::detail::pi; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest to rename RT to PI (not in this change-set please)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure. One change-set just for formatting and Naming.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And one for the version and version handshaking.
sycl/plugins/opencl/pi_opencl.cpp
Outdated
const char SupportedVersion[] = "1.1"; | ||
#define STRING_HELPER(a) #a | ||
#define STRINGIZE(a,b) STRING_HELPER(a.b) | ||
const char SupportedVersion[] = STRINGIZE(_PI_H_VERSION_MAJOR,_PI_H_VERSION_MINOR); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since the arguments are defined in pi.h why not define the string there too? And then you don't need to repeat stringizing utilities here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wanted to define a PI_H_VERSION_STRING macro, which uses _PI_H_VERSION_MAJOR, _PI_H_VERSION_MINOR.
but then I didn't want to define the STRINGIZE macros in the .cpp file.
I have made some changes. Let me know what you think.
be01470
to
caa1506
Compare
Rebase and conflict resolution. |
@smaslov-intel Please check the changes done. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
sycl/include/CL/sycl/detail/pi.hpp
Outdated
// FnOffset- Offset to the Function Pointer in the piPlugin::FunctionPointers | ||
// structure.Used to differentiate between APIs with same pointer type, Eg: | ||
// piDeviceRelease and piDeviceRetain. Differentiation needed to avoid | ||
// duplicate instantiation of class in pi.cpp. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please clarify that this is really a stability issue, i.e. you cannot do different template specializations for different PI interfaces (having same type) without this
sycl/source/detail/pi.cpp
Outdated
template <> \ | ||
CallPi<decltype(&::api), \ | ||
(offsetof(pi_plugin::FunctionPointers, api))>::CallPi() { \ | ||
template <> CallPi<decltype(&::api)>::CallPi() { \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
where had the offset parameter gone?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry about that. I changed the code to check the exact error message I get; changed it back. tested it, but during final cleaning of the code included the wrong PiCall Definition.
datastructure with all function pointers. Extension to this will allow us to bind multiple plugins. Signed-off-by: Garima Gupta <[email protected]>
PI_CALL( or PI_CALL_RESULT( and other required changes. Signed-off-by: Garima Gupta <[email protected]>
to PI_CALL(pi)(...Args); Required extension of Trace class. Changed the syntax at all call sites. Signed-off-by: Garima Gupta <[email protected]>
Signed-off-by: Garima Gupta <[email protected]>
Signed-off-by: Garima Gupta <[email protected]>
Changed the clang-format config file to consider PI_CALL/PI_CALL_THROW/PI_CALL_NOCHECK as typenames instead of being functions. Signed-off-by: Garima Gupta <[email protected]>
Signed-off-by: Garima Gupta <[email protected]>
introduced during rebase-conflict resolution. Bug fix in unittests/pi/PlatformTest.cpp. Signed-off-by: Garima Gupta <[email protected]>
Signed-off-by: Garima Gupta <[email protected]>
Signed-off-by: Garima Gupta <[email protected]>
Rectified merge conflict issues. Signed-off-by: Garima Gupta <[email protected]>
ac5617f
to
f8480a0
Compare
rebased, resolved merge conflict issues. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Looks good to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. A few minor comments.
sycl/include/CL/sycl/detail/pi.hpp
Outdated
// Template Arguments: | ||
// FnType - Type of Function pointer to the PI API. | ||
// FnOffset- Offset to the Function Pointer in the piPlugin::FunctionPointers | ||
// structure. Used to differentiate between APIs with same pointer type, Eg: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// structure. Used to differentiate between APIs with same pointer type, Eg: | |
// structure. Used to differentiate between APIs with same pointer type, E.g.: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done.
sycl/include/CL/sycl/detail/pi.hpp
Outdated
// structure. Used to differentiate between APIs with same pointer type, Eg: | ||
// piDeviceRelease and piDeviceRetain. Differentiation needed to avoid | ||
// redefinition error during explicit specialization of class in pi.cpp. | ||
// Members: Initialiaed in default constructor in Class Template Specialization. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// Members: Initialiaed in default constructor in Class Template Specialization. | |
// Members: Initialized in default constructor in Class Template Specialization. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done.
sycl/include/CL/sycl/detail/pi.hpp
Outdated
// Template Arguments: | ||
// FnType, FnOffset - for CallPi Class. | ||
// Exception - The type of exception to throw if PiResult of a call is not | ||
// PI_SUCCESS. default is cl::sycl::runtime_error. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// PI_SUCCESS. default is cl::sycl::runtime_error. | |
// PI_SUCCESS. Default value is cl::sycl::runtime_error. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done.
sycl/include/CL/sycl/detail/pi.hpp
Outdated
// To check the result use checkPiResult. | ||
// Usage: | ||
// PiResult Err = PI_CALL_NOCHECK(pi)(args); | ||
// RT::checkPiResult(Err); <- Checks Result and throws a runtime error |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// RT::checkPiResult(Err); <- Checks Result and throws a runtime error | |
// RT::checkPiResult(Err); <- Checks Result and throws a runtime_error |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done.
sycl/plugins/opencl/pi_opencl.cpp
Outdated
// PI interface supports lower version of PI. | ||
// TODO: Take appropriate actions. | ||
return PI_INVALID_OPERATION; | ||
} else { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please, don't use else
after return
.
https://llvm.org/docs/CodingStandards.html#don-t-use-else-after-a-return
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think Bjoern suggested this too. I forgot to do the change.
sycl/include/CL/sycl/detail/pi.hpp
Outdated
#define PI_CALL_NOCHECK(pi) \ | ||
RT::CallPi<decltype(&::pi), (offsetof(pi_plugin::FunctionPointers, pi))>() | ||
|
||
// Use this macro to call the API, trace the call, check the return and throw a |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think "throw a Exception" should be either "throw an Exception" or "throw the Exception".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done.
Signed-off-by: Garima Gupta <[email protected]>
@bader Please approve and merge. |
Changes done: