# GPU - CLArrays, GPUArrays - Extract a Matrix from an Array

**URL:** <https://discourse.julialang.org/t/gpu-clarrays-gpuarrays-extract-a-matrix-from-an-array/23741>\
**Category:** GPU\
**Created:** [May 1, 2019, 5:11pm UTC](https://discourse.julialang.org/t/gpu-clarrays-gpuarrays-extract-a-matrix-from-an-array/23741 "2019-05-01T17:11:57Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![MatsMor](https://avatars.discourse-cdn.com/v4/letter/m/ecccb3/32.png) [@MatsMor](https://discourse.julialang.org/u/MatsMor)\
**Post date:** [May 1, 2019, 5:11pm UTC](https://discourse.julialang.org/t/gpu-clarrays-gpuarrays-extract-a-matrix-from-an-array/23741/1 "2019-05-01T17:11:57Z")

</div>

Hi all,

I am new with GPU programming (and therefore CLArrays and GPUArrays). I am building a simple kernel using those 2 packages and I need to extract an entire row (or any sub-matrix) of a very large Array (call it A) and perform some operations (sums, min, max…)

Here is an extremely simplified version of my code. Notice that I want to grab all the elements of the Array A on one specific dimension and then do some basic computations.

```julia
   using CLArrays
   using GPUArrays

function Example_Reduction(x_points::Int64, y_points::Int64)

A = rand(x_points,y_points,10)
CL_A = CLArray{Float32,3}(A)
CL_A_sub = CLArray{Float32,2}((x_points,y_points))

tmp_indices = zeros(size(k_grid,1),size(b_grid,1))
CL_grid_kb = CLArray(Array{Float32,2}(tmp_indices));

gpu_call(CL_grid_kb, (CL_grid_kb, CL_A, CL_A_sub)) do state, CL_grid_kb, CL_A, CL_A_sub
                                  
idx2 = @cartesianidx CL_grid_kb
i_k = idx2[1]
i_b = idx2[2]

# CL_A_sub[i_k,i_b] = CL_A[i_k,i_b,1] #<This works
 CL_A_sub[i_k,i_b] = minimum(CL_A[i_k,i_b,:]) #<This does not work
# CL_A_sub[i_k,i_b] = sum(CL_A[i_k,i_b,:]) #<This does not work

return
end

return Array{Float64,2}(CL_A_sub)
end

A_sub = Example_Reduction(30,20)

```

The code breaks down whenever I try to extract many elements of A (i.e., CL\_A[i\_k,i\_b,:]). This is the output that I get:

```julia
LoadError: AssertionError: Found non concrete return type: Union{}

```

As a workaround I have created a loop to extract the desired elements of the Array A and perform the desired operations. This is working just fine in the meantime, but it is certainly not the most efficient solution… Any ideas on what is the most efficient solution here?

FYI: I am on Windows 10, using AMD Radeon RX 570.

Thanks a lot!

---

<div class="post-metadata">

**Author:** ![jpsamaroo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jpsamaroo/32/46804_2.png) [@jpsamaroo](https://discourse.julialang.org/u/jpsamaroo)\
**Post date:** [May 1, 2019, 6:13pm UTC](https://discourse.julialang.org/t/gpu-clarrays-gpuarrays-extract-a-matrix-from-an-array/23741/2 "2019-05-01T18:13:43Z")

</div>

If you don’t mind, could you please read the following post and then edit your post to match its recommendations:

> [@Please read: make it easier to help you](https://discourse.julialang.org/t/psa-make-it-easier-to-help-you/14757):
>
> Welcome to the Julia Discourse! We are enthusiastic about helping Julia programmers, both beginner and experienced. This public service announcement (PSA) outlines best practices when asking for help. Following these points makes it easier for us to help you and more likely you’ll get a prompt, useful answer. Keywords are highlighted to make it easier to refer to specific points. Choose a descriptive title that captures the key part of your question, eg “plots with multiple axes” instead of …

Specifically, having a MWE of what you’re trying to do would be very helpful. All I know is that a return type of `Union{}` means that your kernel throws an error somewhere, but without an MWE I couldn’t tell you where that is.

Also, CLArrays is broken right now; what OS and GPU are you trying to do GPGPU computing with?

---

<div class="post-metadata">

**Author:** ![MatsMor](https://avatars.discourse-cdn.com/v4/letter/m/ecccb3/32.png) [@MatsMor](https://discourse.julialang.org/u/MatsMor)\
**Post date:** [May 1, 2019, 9:07pm UTC](https://discourse.julialang.org/t/gpu-clarrays-gpuarrays-extract-a-matrix-from-an-array/23741/3 "2019-05-01T21:07:05Z")

</div>

Thanks for the feedback. I have updated the post based on the guidelines.
