-
Notifications
You must be signed in to change notification settings - Fork 39
Add flagcx event type for device event creation #275
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
base: main
Are you sure you want to change the base?
Conversation
Summary of ChangesHello @mikethegoblin, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request enhances the Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
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.
Code Review
This pull request introduces a new enum flagcxEventType_t to control event creation properties, specifically for enabling or disabling timing. The changes are propagated through the adaptor layer and to the call sites.
I've found a few issues:
- A critical bug in
hip_adaptor.ccwhere an assignment is used instead of a comparison. - A compilation error in
mlu_adaptor.ccdue to a typo. - The new
eventTypeparameter is ignored incann_adaptor.cc.
Additionally, I've suggested a minor refactoring for conciseness in several of the CUDA-like adaptors. Please review the comments for details.
|
@gemini-code-assist please review this pull request |
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.
Code Review
This pull request introduces a new enum flagcxEventType_t to specify whether an event should be created with timing capabilities enabled or disabled. This is a valuable optimization, as events used purely for synchronization can be created more efficiently. The changes are consistently applied across all device adaptors and their respective call sites in the C++ code. The logic for selecting the appropriate event creation flags is correct in all instances. I've found one critical issue in the Python wrapper where a new type is used without being defined, which would lead to a runtime error.
|
@gemini-code-assist please review this pull request in detail |
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.
Code Review
This pull request introduces a flagcxEventType_t enum to differentiate between event creation types, primarily for enabling or disabling timing information. The change is consistently applied across all device adaptors and their call sites. My review includes two main points: a suggestion to improve code safety and clarity in all adaptor implementations of eventCreate by avoiding a potentially brittle C-style cast, and a recommendation to add comments to the new enum definition to make its purpose clearer for future maintenance.
| DEVCHECK(aclrtCreateEventWithFlag((aclrtEvent *)(*event), ACL_EVENT_SYNC)); | ||
| const unsigned int flags = | ||
| (eventType == flagcxEventDefault) ? ACL_EVENT_TIME_LINE : ACL_EVENT_SYNC; | ||
| DEVCHECK(aclrtCreateEventWithFlag((aclrtEvent *)(*event), flags)); |
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 cast (aclrtEvent *)(*event) is unsafe as it relies on the memory layout of struct flagcxEvent. A safer and more explicit approach is to take the address of the base member directly. This avoids potential issues if the struct definition changes in the future.
DEVCHECK(aclrtCreateEventWithFlag(&((*event)->base), flags));| const unsigned int flags = (eventType == flagcxEventDefault) | ||
| ? cudaEventDefault | ||
| : cudaEventDisableTiming; | ||
| DEVCHECK(cudaEventCreateWithFlags((cudaEvent_t *)(*event), flags)); |
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 cast (cudaEvent_t *)(*event) is unsafe as it relies on the memory layout of struct flagcxEvent. A safer and more explicit approach is to take the address of the base member directly. This avoids potential issues if the struct definition changes in the future.
DEVCHECK(cudaEventCreateWithFlags(&((*event)->base), flags));| const unsigned int flags = (eventType == flagcxEventDefault) | ||
| ? cudaEventDefault | ||
| : cudaEventDisableTiming; | ||
| DEVCHECK(cudaEventCreateWithFlags((cudaEvent_t *)(*event), flags)); |
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 cast (cudaEvent_t *)(*event) is unsafe as it relies on the memory layout of struct flagcxEvent. A safer and more explicit approach is to take the address of the base member directly. This avoids potential issues if the struct definition changes in the future.
| DEVCHECK(cudaEventCreateWithFlags((cudaEvent_t *)(*event), flags)); | |
| DEVCHECK(cudaEventCreateWithFlags(&((*event)->base), flags)); |
flagcx/adaptor/device/hip_adaptor.cc
Outdated
| const unsigned int flags = (eventType == flagcxEventDefault) | ||
| ? hipEventDefault | ||
| : hipEventDisableTiming; | ||
| DEVCHECK(hipEventCreateWithFlags((hipEvent_t *)(*event), flags)); |
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 cast (hipEvent_t *)(*event) is unsafe as it relies on the memory layout of struct flagcxEvent. A safer and more explicit approach is to take the address of the base member directly. This avoids potential issues if the struct definition changes in the future.
| DEVCHECK(hipEventCreateWithFlags((hipEvent_t *)(*event), flags)); | |
| DEVCHECK(hipEventCreateWithFlags(&((*event)->base), flags)); |
| const unsigned int flags = (eventType == flagcxEventDefault) | ||
| ? cudaEventDefault | ||
| : cudaEventDisableTiming; | ||
| DEVCHECK(cudaEventCreateWithFlags((cudaEvent_t *)(*event), flags)); |
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 cast (cudaEvent_t *)(*event) is unsafe as it relies on the memory layout of struct flagcxEvent. A safer and more explicit approach is to take the address of the base member directly. This avoids potential issues if the struct definition changes in the future.
| DEVCHECK(cudaEventCreateWithFlags((cudaEvent_t *)(*event), flags)); | |
| DEVCHECK(cudaEventCreateWithFlags(&((*event)->base), flags)); |
| const unsigned int flags = (eventType == flagcxEventDefault) | ||
| ? cudaEventDefault | ||
| : cudaEventDisableTiming; | ||
| DEVCHECK(cudaEventCreateWithFlags((cudaEvent_t *)(*event), flags)); |
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 cast (cudaEvent_t *)(*event) is unsafe as it relies on the memory layout of struct flagcxEvent. A safer and more explicit approach is to take the address of the base member directly. This avoids potential issues if the struct definition changes in the future.
| DEVCHECK(cudaEventCreateWithFlags((cudaEvent_t *)(*event), flags)); | |
| DEVCHECK(cudaEventCreateWithFlags(&((*event)->base), flags)); |
| DEVCHECK(mcEventCreateWithFlags((mcEvent_t *)(*event), mcEventDisableTiming)); | ||
| const unsigned int flags = | ||
| (eventType == flagcxEventDefault) ? mcEventDefault : mcEventDisableTiming; | ||
| DEVCHECK(mcEventCreateWithFlags((mcEvent_t *)(*event), flags)); |
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 cast (mcEvent_t *)(*event) is unsafe as it relies on the memory layout of struct flagcxEvent. A safer and more explicit approach is to take the address of the base member directly. This avoids potential issues if the struct definition changes in the future.
| DEVCHECK(mcEventCreateWithFlags((mcEvent_t *)(*event), flags)); | |
| DEVCHECK(mcEventCreateWithFlags(&((*event)->base), flags)); |
flagcx/adaptor/device/mlu_adaptor.cc
Outdated
| const unsigned int flags = (eventType == flagcxEventDefault) | ||
| ? CNRT_NOTIFIER_DEFAULT | ||
| : CNRT_NOTIFIER_DISABLE_TIMING_ALL; | ||
| DEVCHECK(cnrtNotifierCreateWithFlags((cnrtNotifier_t *)(*event), flags)); |
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 cast (cnrtNotifier_t *)(*event) is unsafe as it relies on the memory layout of struct flagcxEvent. A safer and more explicit approach is to take the address of the base member directly. This avoids potential issues if the struct definition changes in the future.
DEVCHECK(cnrtNotifierCreateWithFlags(&((*event)->base), flags));| const unsigned int flags = (eventType == flagcxEventDefault) | ||
| ? musaEventDefault | ||
| : musaEventDisableTiming; | ||
| DEVCHECK(musaEventCreateWithFlags((musaEvent_t *)(*event), flags)); |
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 cast (musaEvent_t *)(*event) is unsafe as it relies on the memory layout of struct flagcxEvent. A safer and more explicit approach is to take the address of the base member directly. This avoids potential issues if the struct definition changes in the future.
| DEVCHECK(musaEventCreateWithFlags((musaEvent_t *)(*event), flags)); | |
| DEVCHECK(musaEventCreateWithFlags(&((*event)->base), flags)); |
|
@gemini-code-assist please review this pull request in details |
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.
Code Review
This pull request introduces a flagcxEventType_t enum to allow for more granular control over device event creation, specifically to enable or disable timing. The changes are consistently applied across all device adaptors, mapping the generic event type to the correct device-specific flags. Call sites have been updated to use the new functionality, enabling timing for profiler events in timer.h and disabling it for internal synchronization events in group.cc, launch_kernel.h, and transport.cc for better performance. The refactoring of event handle access from a C-style cast to accessing a base member of the event struct is also a good improvement for type safety and code clarity. Overall, this is a well-executed and beneficial change.
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
flagcxEventType_tto distinguish the types of event to be created