Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

BLAS-1 methods pass reversed views to oneMKL with a negative increment

クローズ
#712 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

関連するプルリクエストがすでにマージされています。

  • #724 @maleadt による — マージ済み

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
74/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
julia
領域
backend

調査の方向性

Start in lib/mkl/linalg.jl and lib/mkl/wrappers_blas.jl; compare the BLAS-1 methods and pointer/increment handling with LinearAlgebra's vec_pointer_stride behavior described in the issue. Check how non-contiguous multidimensional arrays reach these wrappers and where they can fall back to GPUArrays implementations. Done means reversed views and non-contiguous arrays produce correct results without writing outside the view; use the examples in the issue to verify.

索引モデルが issue の本文から書いたものです。

説明

The BLAS-1 methods in lib/mkl/linalg.jl (norm, dot, BLAS.asum, axpy!, axpby!, rmul!, rotate!, reflect!) forward any oneStridedArray to the wrappers in lib/mkl/wrappers_blas.jl, which pass pointer(x) with incx = stride(x, 1). With a reversed view, that increment is negative and the results are silently wrong:

using oneAPI, LinearAlgebra
x = oneArray(Float32[3, 4]); r = view(x, 2:-1:1); y = oneArray(Float32[1, 2])

norm(r)                    # 4.0, expected 5.0
dot(r, y)                  # 8.0, expected 10.0
LinearAlgebra.BLAS.asum(r) # 4.0, expected 7.0
axpy!(1f0, r, copy(y))     # [1, 6], expected [5, 5]
rmul!(r, 2f0); x           # [3, 8], expected [6, 8]

BLAS routines that accept a negative increment walk the vector backwards from its lowest address, while the pointer of a reversed view points at its first logical element, so they read and write the wrong memory.

The methods also accept non-contiguous arrays with more than one dimension, and the wrappers then treat them as length(x) elements with stride stride(x, 1). That gives wrong results and writes outside the view:

M = rand(Float32, 3, 2); dM = oneArray(M)
norm(view(dM, 1:2, :)) ≈ norm(M[1:2, :])   # false
rmul!(view(dM, 1:2, :), 2f0)               # scales M[3, 1] instead of M[2, 2]

LinearAlgebra handles negative strides in its BLAS wrappers: vec_pointer_stride passes the pointer to the lowest address together with the signed increment, and nrm2, asum and scal use abs(stride(x, 1)), since the order doesn't matter for them. The wrappers should only take strided vectors or dense arrays, with other arrays falling back to the GPUArrays implementations. The storage-level mul! has a similar problem for gemv and friends, which is #700.

Same issue in CUDA.jl: JuliaGPU/CUDA.jl#3410.

Reproduced with oneAPI.jl 2.9.2 on an Iris Xe, Julia 1.12.7. The BLAS-1 methods and wrappers are unchanged on main.

主要言語
Julia
スター
217
フォーク
37
平均マージ
1日 5時間
マージ済み PR(30日)
50

環境構築

このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

JuliaGPU/oneAPI.jl のほかの issue

JuliaGPU/oneAPI.jl の issue をすべて見る

似ている issue

Julia の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。