Add warning to documentation of fromPtrs#7
Open
tomsmeding wants to merge 1 commit intoAccelerateHS:masterfrom
Open
Add warning to documentation of fromPtrs#7tomsmeding wants to merge 1 commit intoAccelerateHS:masterfrom
tomsmeding wants to merge 1 commit intoAccelerateHS:masterfrom
Conversation
In accelerate 1.3, code that should have been dead-code eliminated, but was not, may be executed at runtime while nothing waits for it. The fact that this is possible makes fromPtrs essentially impossible to use safely.
Member
Author
|
Reproduction for the issue in question: {-# LANGUAGE RankNTypes #-}
module FromPtrsUnsafe where
import qualified Data.Array.Accelerate as A
import Data.Array.Accelerate.Array.Unique (newUniqueArray)
import qualified Data.Array.Accelerate.Representation.Array as R
import Data.Array.Accelerate.Sugar.Array (Array(..))
import Data.Array.Accelerate.Test.NoFib.Base
import Control.Monad
import Foreign
import Test.Tasty
import Test.Tasty.HUnit
-- Source: reduced from https://github.com/LCSB-BioCore/remotesom/blob/516581a3e2973a5561a08b0abcffbb9d7afb261e/Numeric/RemoteSOM.hs
somIter :: A.Acc (A.Matrix Float) -> A.Acc (A.Matrix Float) -> A.Acc (A.Matrix Float)
somIter points som =
let A.I2 ptsn _ = A.shape points
A.I2 somn dim = A.shape som
closest = A.generate (A.I1 ptsn) $ \_ -> 0
A.T2 s _s = A.T2
(A.permute
(+)
(A.I2 somn dim `A.fill` A.constant (0 :: Float))
(\(A.I2 pix dimi) -> A.Just_ $ A.I2 (closest A.! A.I1 pix) dimi)
points)
(A.permute
(+)
(A.I2 somn dim `A.fill` A.constant (0 :: Float))
(\(A.I2 pix dimi) -> A.Just_ $ A.I2 (closest A.! A.I1 pix) dimi)
(A.map (\x -> x * x) points))
in s
test_fromPtrsUnsafe :: RunN -> TestTree
test_fromPtrsUnsafe runN = testCase "fromPtrsUnsafe" $ do
let ptsn = 200000
dim = 128
pointsbuf <- mallocBytes (ptsn * dim * sizeOf (undefined :: Float))
forM_ [0 .. ptsn*dim - 1] $ \i ->
pokeElemOff pointsbuf i 0.0
pointsUA <- newUniqueArray =<< newForeignPtr_ pointsbuf
let points = Array (R.Array (((), ptsn), dim) pointsUA)
let som = A.fromFunction (A.Z A.:. 400 A.:. dim) (\_ -> 0.0)
let res = runN somIter points som
when (res /= A.fromFunction (A.Z A.:. 400 A.:. dim) (\_ -> 0.0)) $
assertFailure "unequal"
free pointsbuf |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
In accelerate 1.3, code that should have been dead-code eliminated, but was not, may be executed at runtime while nothing waits for it. The fact that this is possible makes fromPtrs essentially impossible to use safely.