# Symmetric view of sparse matrix CUDA.jl

**URL:** https://discourse.julialang.org/t/symmetric-view-of-sparse-matrix-cuda-jl/123811
**Category:** GPU
**Tags:** gpu, linearalgebra, cudajl
**Created:** [December 13, 2024, 1:32pm UTC](https://discourse.julialang.org/t/symmetric-view-of-sparse-matrix-cuda-jl/123811 "2024-12-13T13:32:46Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![victor\_vhrn](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/victor_vhrn/32/214016_2.png) [@victor\_vhrn](https://discourse.julialang.org/u/victor_vhrn)
#### Post date: [December 13, 2024, 1:32pm UTC](https://discourse.julialang.org/t/symmetric-view-of-sparse-matrix-cuda-jl/123811/1 "2024-12-13T13:32:46Z")

</div>

What is the best way of adapting Symmetric to the GPU? Can it be done? Should it be done?

I currently have the following function `Aadj` which I would like to create a GPU version of:

```julia
using CUDA
using CUDA.CUSPARSE
using LinearAlgebra
using SparseArrays

n = 5
m = 6

Es = [1, 1, 2, 2, 3, 4]
Ed = [2, 3, 3, 5, 4, 5]

M = sparse(Es, Ed, ones(Float64, m), n, n)
p = 4 * ones(m)
Aadj = p::AbstractVector -> (M.nzval .= p ./ 2; Symmetric(M))
R = Aadj(p)

```

The trivial attempt below fails because of getindex (The Symmetric view tries to iterate over M’s elements right?):

```julia
M_d = CuSparseMatrixCSC(M)
p_d = CuArray(p)
Aadj_GPU = p_d::CuArray -> (M_d.nzVal .= p_d ./ 2; Symmetric(M_d))
R = Aadj_GPU(p_d)

```
