Optimized GPU implementation of the MATLAB sort function
sorts the elements of B
= gpucoder.sort(A
)A
in ascending order. The sort operation is
performed on the GPU with the help of Thrust library. Thrust is a C++ template
library for CUDA® and is shipped with CUDA toolkit. The sorted output in B
has the same type
and size as A
. If A
is a vector,
gpucoder.sort(A)
sorts the elements of A in ascending order.
If A
is a matrix, gpucoder.sort(A)
sorts each
column of A in ascending order. If A
is an N-dimensional array,
gpucoder.sort(A)
sorts along the first non-singleton
dimension.
has the optional argument B
= gpucoder.sort(A
,dim
)dim
that specifies the dimension along
which the sort operation is performed.
has the optional argument B
= gpucoder.sort(A
,direction
)direction
that specifies the sort
direction. direction
can take one of two values:
'ascend'
- Sorts in the ascending order. This is
the default option
'descend'
- Sorts in the descending order.
[
returns a sort index B
,I
] = gpucoder.sort(A
,...)I
which specifies how the elements of
A
were rearranged to obtain the sorted output
B
.
If A
is a vector, then B =
A(I)
.
If A
is an m-by-n matrix and dim =
1
, then
for j = 1:n B(:,j) = A(I(:,j),j); end
The sort ordering is stable. Namely, when more than one element has the same value, the order of the equal elements is preserved in the sorted output B and the indices I relating to equal elements are ascending.
When gpucoder.sort
is called from MATLAB®, it uses the built-in sort
function.
gpucoder.sort
does not support complex numbers.
gpucoder.sort
does not support
'MissingPlacement'
and
'ComparisonMethod'
name-value pairs supported by the MATLAB
sort
function.
codegen
| coder.gpu.constantMemory
| coder.gpu.kernel
| coder.gpu.kernelfun
| gpucoder.reduce
| gpucoder.stencilKernel