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

about the document of conditional use #689

Closed
norci opened this issue Jan 31, 2021 · 1 comment
Closed

about the document of conditional use #689

norci opened this issue Jan 31, 2021 · 1 comment

Comments

@norci
Copy link
Contributor

norci commented Jan 31, 2021

in file docs/src/installation/conditional.md

What about a generated function?
https://docs.julialang.org/en/v1/manual/metaprogramming/#Generated-functions

@generated function to_gpu_or_not_to_gpu(x::AbstractArray)
    if CUDA.functional()
        return :(CuArray(x))
    else
        return :(x)
    end
end

function __init__()
    to_gpu_or_not_to_gpu(ones(2))
end

I'm not sure if this code is better?

@norci norci added the bug Something isn't working label Jan 31, 2021
@maleadt maleadt removed the bug Something isn't working label Feb 1, 2021
@maleadt
Copy link
Member

maleadt commented Feb 1, 2021

You cannot use complicated stateful functionality like that in a generated function.
https://docs.julialang.org/en/v1/base/base/#Base.@generated

@maleadt maleadt closed this as completed Feb 1, 2021
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

No branches or pull requests

2 participants