-
Notifications
You must be signed in to change notification settings - Fork 66
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
How to handle user defined functions? #55
Comments
LoopVectorization evaluates your code using But, as a limitation, that means any functions you call will have to accept Another limitation is that LoopVectorization's optimizer only understands a few functions. If anything reasonably generic is missing, please let me know and I can add it. That said, you can manually tell it what to do, eg, unroll by 2 (anything 1-4 will probably be pretty good, above that probably wont be worth it; above 8 will probably be bad): function gen_sincos!(sins, coss, phases)
@avx unroll=2 for i = 1:2500
first_bit_sign = get_first_bit_sign(phases[i])
second_bit_sign = get_second_bit_sign(phases[i])
quarter_angle = get_quarter_angle(phases[i])
A = calc_A(quarter_angle)
B = calc_B(quarter_angle)
coss[i] = second_bit_sign * (first_bit_sign * A + B)
sins[i] = second_bit_sign * (A - first_bit_sign * B)
end
end Because it is assuming each of these functions is expensive, it should be deciding on It would also definitely be worth looking into if there is some way to figure out the cost of user-defined functions. If manually specifying the unroll (or
You can write: using LoopVectorization: SVec
function calc_A(x::Union{Int16,SVec{<:Any,Int16}})
...
end
function calc_A(x::Union{Int32,SVec{<:Any,Int32}})
...
end or, if you're making a lot of definitions, it may be cleaner to define type aliases ( using LoopVectorization: SVec
const VInt16 = Union{Int16,SVec{<:Any,Int16}}
const VInt32 = Union{Int32,SVec{<:Any,Int32}}
const VInt64 = Union{Int64,SVec{<:Any,Int64}}
function calc_A(x::VInt32)
...
end
function calc_B(x::VInt32)
...
end
function calc_C(x::VInt32)
...
end Perhaps I should define these type aliases myself? What would be the best name? |
Thank you for detailed insights!
Sounds like a good option. |
I get the following error
where
calc_A
is a user defined function. Do I need to implementcalc_A(::VectorizationBase.SVec{16,Int16})
myself? Why isn't there an error for the other user defined functions? My first guess was because they are inlined, butcalc_A
should be inlined, too.Here is the code for that:
EDIT: Alright I found the solution myself: If I write
function calc_A(x)
instead offunction calc_A(x::Int16)
, it will work. So should I omit the declaration ofx
? What if I have a different function forx::Int32
?The text was updated successfully, but these errors were encountered: