Ticket #20 (closed defect: fixed)

Opened 4 years ago

Last modified 4 years ago

Code generation for nested tuple projection fails

Reported by: seanl Owned by: tmcdonell
Priority: major Milestone:
Component: CUDA backend Version: 0.7.1.0
Keywords: Cc:

Description (last modified by tmcdonell) (diff)

The CUDA backend appears to be failing when generating the code for the following function, producing the error message, "*** Exception: Prelude.(!!): index too large":

{-# LANGUAGE ScopedTypeVariables #-}

module Main where

import Data.Array.Accelerate                (Acc, Exp, Vector)
import qualified Data.Array.Accelerate      as Acc
import qualified Data.Array.Accelerate.CUDA as CUDA

test :: Vector ((Float, Int), Double) -> Acc (Vector ((Float, Int), Double))
test xs =
  let xs' = Acc.use xs
  in flip Acc.map xs' $ \x ->
    let (a', c :: Exp Double)          = Acc.untuple x
        (a :: Exp Float, b :: Exp Int) = Acc.untuple a'
    in  Acc.tuple (Acc.tuple (a + 1, b + 2), c + 3)

main :: IO ()
main =
  let input = Acc.fromList 10 (zip (zip [0..9] [1..10]) [2..11])
  in
  print =<< CUDA.run (test input)

Change History

Changed 4 years ago by seanl

  • version set to 0.7.1.0

Changed 4 years ago by seanl

The problem is that

codeGenExp (AST.Prj idx e) = unit . (!! prjToInt idx) . reverse <$> codeGenExp e

always returns a singleton list even when the tuple element is another tuple.

Changed 4 years ago by seanl

Another potential problem related to this issue is that prjToInt does not accommodate the cases with nested tuples correctly.

For example, given

((Int, Int), (Float, Int), (Double, Double))

the following CUDA struct is created currently with the CUDA backend

struct {
  int f;
  int e;
  float d;
  int c;
  double b;
  double a;
}

(SuccTupIdx ZeroTupIdx) is supposed to project the tuple element in the middle (Float, Int), however, prjToInt (SuccTupIdx ZeroTupIdx) seems to be returning 1, which leads to the incorrect projection and double b is projected from the CUDA struct.

Changed 4 years ago by tmcdonell

  • description modified (diff)

Changed 4 years ago by tmcdonell

  • description modified (diff)

Changed 4 years ago by tmcdonell

  • summary changed from The projection of a nested tuple failed to Code generation for nested tuple projection fails

Changed 4 years ago by tmcdonell

  • status changed from new to assigned

Changed 4 years ago by tmcdonell

  • status changed from assigned to closed
  • resolution set to fixed
Mon Aug 16 11:07:16 EST 2010  Trevor L. McDonell <tmcdonell@cse.unsw.edu.au>
  * fix code generation for tuples
Note: See TracTickets for help on using tickets.