Skip to content

Fix GPU detection in PerStoreFeatureNode#17593

Merged
yongwww merged 1 commit intoapache:mainfrom
moonquekes:main
Jan 19, 2025
Merged

Fix GPU detection in PerStoreFeatureNode#17593
yongwww merged 1 commit intoapache:mainfrom
moonquekes:main

Conversation

@moonquekes
Copy link
Copy Markdown
Contributor

Bug Description: Incorrect Assignment of is_gpu Property

Summary:
In the context of feature extraction using meta_schedule, the is_gpu property was incorrectly assigned by directly comparing the target kind name to "cuda". This approach is not only too specific but also potentially unsafe, as it does not account for different GPU types or handle cases where the target might be undefined.

Incorrect Code:

bool is_gpu = tune_context->target.value()->kind->name == "cuda";

bool is_gpu = tune_context->target.value()->kind->name == "cuda";

Problems with the Incorrect Code:

  1. Lack of Generality: Not all GPUs use CUDA (e.g., AMD GPUs may use ROCm or OpenCL).
  2. Specificity Issue: Even on NVIDIA hardware, the target kind name isn't guaranteed to be "cuda" and can vary based on library versions or configurations.

Correct Implementation:

auto& target_keys = tune_context->target.value()->keys;
bool is_gpu = std::find(target_keys.begin(), target_keys.end(), "gpu") != target_keys.end();

Explanation of Correct Code:
The corrected code checks if "gpu" exists within the list of keys associated with the target. This method is more robust because:

  • It correctly identifies any target that includes "gpu" in its keys, regardless of the underlying hardware or software platform.
  • It avoids potential null pointer dereferencing by not directly accessing kind->name.
  • It is more flexible and can accommodate various types of GPU targets without hardcoding specific names.

@moonquekes moonquekes changed the title Fix GPU detection in PerStoreFeatureNode(#17592) Fix GPU detection in PerStoreFeatureNode Jan 15, 2025
@moonquekes
Copy link
Copy Markdown
Contributor Author

hi,@Hzfengsy.
Please review the code I submitted, thanks!

Copy link
Copy Markdown
Member

@Hzfengsy Hzfengsy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix

@yongwww
Copy link
Copy Markdown
Member

yongwww commented Jan 15, 2025

@tvm-bot rerun

1 similar comment
@yongwww
Copy link
Copy Markdown
Member

yongwww commented Jan 18, 2025

@tvm-bot rerun

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants