<commit_before>module Kernel.GPU.GatherGrid
  ( prepare
  , createGrid
  , grid
  , degrid
  ) where

import Data.Word
import Foreign.C
import Foreign.Ptr
import Foreign.Marshal.Array ( advancePtr, withArray )
import Foreign.Storable ( peek, sizeOf )
import Kernel.GPU.Common

import Data
import Vector

import qualified Kernel.GPU.NvidiaDegrid as Nvidia


{-
import Control.Monad
import Data.Function ( on )
import Data.List
import Data.Word
import Foreign.Storable ( sizeOf )

import Data
import Kernel.GPU.Common as CUDA
import qualified Kernel.GPU.NvidiaDegrid as Nvidia
import Vector
-}

foreign import ccall bin ::
     CInt         -- # of points
  -> Double       -- scale
  -> Double       -- wstep
  -> Ptr CxDouble -- Vis ptr
  -> Ptr UVW      -- UVWs ptr
  -> Ptr CInt     -- GCF supports ptr
  -> CInt         -- grid size
  -> IO (HostPtr ())

fromVec :: Vector a -> Ptr a
fromVec (CVector _ p) = castPtr p
fromVec _ = error "Wrong CPU vector location."

prepare :: GridPar -> Vis -> GCFSet -> IO (Vis, GCFSet)
prepare gridp vis gcfSet = withArray gcfSupps $ \sp -> do
    binned <- bin
                (fi numOfPoints)
                scale
                wstep
                (fromVec $ visData vis)
                (fromVec $ visPositions vis)
                (advancePtr sp maxWPlane)
                (fi grSize)
    sizeInBytes <- peek (castPtr $ useHostPtr binned) :: IO CInt
    return (vis{visBinData = HostVector (fromIntegral sizeInBytes) binned}, gcfSet)
  where
    fi = fromIntegral
    numOfPoints = visTimesteps vis * length (visBaselines vis)
    gcfp = gcfsPar gcfSet<commit_msg>Forgot to remove some cruft.<commit_after>module Kernel.GPU.GatherGrid
  ( prepare
  , createGrid
  , grid
  , degrid
  ) where

import Data.Word
import Foreign.C
import Foreign.Ptr
import Foreign.Marshal.Array ( advancePtr, withArray )
import Foreign.Storable ( peek, sizeOf )
import Kernel.GPU.Common

import Data
import Vector

import qualified Kernel.GPU.NvidiaDegrid as Nvidia

foreign import ccall bin ::
     CInt         -- # of points
  -> Double       -- scale
  -> Double       -- wstep
  -> Ptr CxDouble -- Vis ptr
  -> Ptr UVW      -- UVWs ptr
  -> Ptr CInt     -- GCF supports ptr
  -> CInt         -- grid size
  -> IO (HostPtr ())

fromVec :: Vector a -> Ptr a
fromVec (CVector _ p) = castPtr p
fromVec _ = error "Wrong CPU vector location."

prepare :: GridPar -> Vis -> GCFSet -> IO (Vis, GCFSet)
prepare gridp vis gcfSet = withArray gcfSupps $ \sp -> do
    binned <- bin
                (fi numOfPoints)
                scale
                wstep
                (fromVec $ visData vis)
                (fromVec $ visPositions vis)
                (advancePtr sp maxWPlane)
                (fi grSize)
    sizeInBytes <- peek (castPtr $ useHostPtr binned) :: IO CInt
    return (vis{visBinData = HostVector (fromIntegral sizeInBytes) binned}, gcfSet)
  where
    fi = fromIntegral
    numOfPoints = visTimesteps vis * length (visBaselines vis)
    gcfp = gcfsPar gcfSet
{'fraction_non_alphanumeric': 0.08794137241838774, 'fraction_numerical': 0.0, 'mean_word_length': 2.2535211267605635, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4656688', 'n_tokens_mistral': 972, 'n_tokens_neox': 931, 'n_words': 298}