diff options
author | Tom Smeding <tom@tomsmeding.com> | 2024-05-26 14:59:06 +0200 |
---|---|---|
committer | Tom Smeding <tom@tomsmeding.com> | 2024-05-26 14:59:22 +0200 |
commit | 5d3e5c2d001e5724629b7d4e2d88f7bb8ebc6c59 (patch) | |
tree | 00bcaa4152d7054b06c947eee364db3c15e570dc /src/Data | |
parent | e80b2593edc3d216905279ebcfa797593a1efbfc (diff) |
Benchmark with haskell num ops via mutable vectorsexper-hs-numops
Conclusions:
- orthotope zipWith (+) -> zipWithT: 26.9 ms ± 1.6 ms
- Data.Vector.Storable.zipWith (+): 10.1 ms ± 945 μs
- hsaddDoubleVV (this commit): 1.52 ms ± 49 μs
- cbits/arith.c: 1.29 ms ± 116 μs
- hmatrix: 1.25 ms ± 49 μs
Diffstat (limited to 'src/Data')
-rw-r--r-- | src/Data/Array/Nested/Internal/Arith.hs | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/src/Data/Array/Nested/Internal/Arith.hs b/src/Data/Array/Nested/Internal/Arith.hs index 07d5d8a..042c9d0 100644 --- a/src/Data/Array/Nested/Internal/Arith.hs +++ b/src/Data/Array/Nested/Internal/Arith.hs @@ -6,9 +6,10 @@ {-# LANGUAGE TypeOperators #-} {-# LANGUAGE ViewPatterns #-} {-# OPTIONS_GHC -fplugin GHC.TypeLits.KnownNat.Solver #-} +-- {-# OPTIONS_GHC -ddump-simpl -ddump-to-file -ddump-file-prefix=Arith #-} module Data.Array.Nested.Internal.Arith where -import Control.Monad (forM, guard) +import Control.Monad (forM, forM_, guard) import qualified Data.Array.Internal as OI import qualified Data.Array.Internal.RankedG as RG import qualified Data.Array.Internal.RankedS as RS @@ -309,8 +310,26 @@ instance NumElt Float where numEltSum1Inner = sum1VectorFloat numEltProduct1Inner = product1VectorFloat +hsaddDoubleSV :: Double -> VS.Vector Double -> VS.Vector Double +hsaddDoubleSV = error "unimplemented" + +{-# NOINLINE hsaddDoubleVV #-} +hsaddDoubleVV :: VS.Vector Double -> VS.Vector Double -> VS.Vector Double +-- hsaddDoubleVV = VS.zipWith (+) +hsaddDoubleVV v1 v2 = unsafePerformIO $ do + let n = min (VS.length v1) (VS.length v2) + dest <- VSM.unsafeNew n + forM_ [0 .. n - 1] $ \i -> do + VSM.write dest i (v1 VS.! i + v2 VS.! i) + VS.unsafeFreeze dest + instance NumElt Double where - numEltAdd = addVectorDouble + numEltAdd = \sn -> liftVEltwise2 sn $ \cases + (Left x) (Left y) -> VS.singleton (x + y) + (Left x) (Right vy) -> hsaddDoubleSV x vy + (Right vx) (Left y) -> hsaddDoubleSV y vx + (Right vx) (Right vy) -> hsaddDoubleVV vx vy + -- numEltAdd = addVectorDouble numEltSub = subVectorDouble numEltMul = mulVectorDouble numEltNeg = negVectorDouble |