Skip to content
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

Add helper functions to query properties of the lowered Target (#8192) #8359

Merged
merged 5 commits into from
Aug 1, 2024

Conversation

steven-johnson
Copy link
Contributor

No description provided.

//@{
Expr target_arch_is(Target::Arch arch);
Expr target_os_is(Target::OS os);
Expr target_has_feature(Target::Feature feat);
Copy link
Contributor

Choose a reason for hiding this comment

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

This one should perhaps get a big warning that this does not check runtime-features of the CPU or device, but uses the compile-time target. I know it says that in the doc above, but I feel like many people will get fooled by their wrong intuition. It's especially tricky, as it returns an Expr and not a bool, so it gives off a runtime-vibe.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@steven-johnson
Copy link
Contributor Author

This could be expanded to more of the Target API, but I stopped here; some other possibilities would be

bool target_supports_device_api(DeviceAPI device)
bool target_supports_type(const Type &t, DeviceAPI device)

Copy link
Member

@abadams abadams left a comment

Choose a reason for hiding this comment

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

This would address my use-case

@steven-johnson steven-johnson merged commit 1872788 into main Aug 1, 2024
19 checks passed
@steven-johnson steven-johnson deleted the srj/target_is branch August 1, 2024 16:15
@mcourteaux
Copy link
Contributor

@abadams Is there a way to get the device type of the enclosing loop for a given expression?

Context: I'm working on the fast_atan, and it seems that LLVM has a good version of atan already implemented for CUDA akin to what the fast-version would be. So, I'd like to just select the default atan instrinsic if the code will be run on a CUDA device. This would involve checking the device type of the enclosing loop. Turning that into a compile-time constant bool expression, would allow putting this into a select(), similar to this PR.

@steven-johnson
Copy link
Contributor Author

Is there a way to get the device type of the enclosing loop for a given expression?

No, but it seems like it would be pretty simple to add, in the same manner of the helpers I just added. Feel free to open a PR to do so (it may be a little while before I can get to it).

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