Skip to content

Make setscalar GPU-friendly#52

Merged
blegat merged 2 commits intomainfrom
bl/setscalar
May 6, 2026
Merged

Make setscalar GPU-friendly#52
blegat merged 2 commits intomainfrom
bl/setscalar

Conversation

@blegat
Copy link
Copy Markdown
Owner

@blegat blegat commented May 6, 2026

On CPU, it makes no difference:

using BenchmarkTools

function _setindex1!(x, v, i)
    x[i] = v
    return
end

function _setindex2!(x, v, i)
    I = reshape(i:i, ())
    view(x, I) .= v
    return
end

function _setindex3!(x, v, i)
    I = i:i
    view(x, I) .= v
    return
end

function setindex_bench()
    x = rand(10)
    i = 3
    v = 2.0
    @btime _setindex1!($x, $v, $i)
    @btime _setindex2!($x, $v, $i)
    @btime _setindex3!($x, $v, $i)
end

setindex_bench()
setindex_bench()
setindex_bench()
setindex_bench()

gives

  2.075 ns (0 allocations: 0 bytes)
  2.091 ns (0 allocations: 0 bytes)
  2.046 ns (0 allocations: 0 bytes)

  1.937 ns (0 allocations: 0 bytes)
  2.089 ns (0 allocations: 0 bytes)
  2.089 ns (0 allocations: 0 bytes)

  2.050 ns (0 allocations: 0 bytes)
  2.048 ns (0 allocations: 0 bytes)
  2.085 ns (0 allocations: 0 bytes)

  2.088 ns (0 allocations: 0 bytes)
  2.047 ns (0 allocations: 0 bytes)
  2.046 ns (0 allocations: 0 bytes)

But since CUDA disallow scalar indexing, this is a way to make CUDA not complain without needed to write CUDA.@allowscalar.

@codecov
Copy link
Copy Markdown

codecov Bot commented May 6, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.88%. Comparing base (94ef9e2) to head (eca4231).

Additional details and impacted files
@@           Coverage Diff           @@
##             main      #52   +/-   ##
=======================================
  Coverage   89.87%   89.88%           
=======================================
  Files          23       23           
  Lines        2845     2847    +2     
=======================================
+ Hits         2557     2559    +2     
  Misses        288      288           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@blegat blegat merged commit 59f0d97 into main May 6, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant