-
Notifications
You must be signed in to change notification settings - Fork 272
Add p-norm functionality. #688
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
Changes from all commits
9180f52
e424e01
1e34822
fcc1c26
11dd2ac
f23d649
c04d918
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -37,6 +37,16 @@ end | |
| LinearAlgebra.norm(x::DenseCuArray{<:CublasFloat}) = nrm2(x) | ||
| LinearAlgebra.BLAS.asum(x::StridedCuArray{<:CublasFloat}) = asum(length(x), x) | ||
|
|
||
| function LinearAlgebra.norm(x::DenseCuArray{<:CublasFloat}, p::Integer) | ||
| if p==1 | ||
| return CUBLAS.asum(length(x),x) | ||
| elseif p==2 | ||
| return LinearAlgebra.norm(x) | ||
| else | ||
| return LinearAlgebra.tr(LinearAlgebra.Diagonal(abs.(x))^p)^(1/p) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The problem is that these operations are implemented using CUBLAS, so are themselves restricted to the types CUBLAS supports (plain, basic C types). Ideally we'd have something more generic. What about #84 (comment), is that not valid or slower?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Such a generic versions could also go into GPUArrays.jl, while a specialized version for CUBLAS-supported types could live in CUDA.jl.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @maleadt Could you elaborate on the types CUBLAS does not support?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
If you look at the CUBLAS docs, you'll see it's a C library that only supports a limited set of element types. That's why we have type unions like CUBLASFloat in CUDA.jl |
||
| end | ||
| end | ||
|
|
||
| function LinearAlgebra.axpy!(alpha::Number, x::StridedCuArray{T}, y::StridedCuArray{T}) where T<:CublasFloat | ||
| length(x)==length(y) || throw(DimensionMismatch("axpy arguments have lengths $(length(x)) and $(length(y))")) | ||
| axpy!(length(x), alpha, x, y) | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.