Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ThisBuild / scalaVersion := "2.13.3"
ThisBuild / scalaVersion := "2.13.16"
ThisBuild / organization := "org.rise-lang"

lazy val commonSettings = Seq(
Expand Down
2 changes: 1 addition & 1 deletion lib/arithexpr
2 changes: 1 addition & 1 deletion lib/executor
4 changes: 2 additions & 2 deletions meta/src/main/scala/meta/parser/DPIA/Decl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ object Decl {
final case class Type(typeAST: meta.parser.DPIA.Type.AST) extends KindOrType
}

def PrimitiveDeclarations[_: P]: P[Seq[AST.PrimitiveDeclaration]] =
def PrimitiveDeclarations[$: P]: P[Seq[AST.PrimitiveDeclaration]] =
P(Start ~ PrimitiveDeclaration.rep(1) ~ End)

def PrimitiveDeclaration[_: P]: P[AST.PrimitiveDeclaration] = {
def PrimitiveDeclaration[$: P]: P[AST.PrimitiveDeclaration] = {
import scalaparse.Scala.TrailingCommaOps
def ScalaParams: P[(Int, Int)] = {
P("{" ~ Index ~
Expand Down
2 changes: 1 addition & 1 deletion meta/src/main/scala/meta/parser/DPIA/Kind.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ object Kind {
case class VariadicKind(n: String, kind: AST) extends AST
}

def Kind[_: P]: P[AST] = {
def Kind[$: P]: P[AST] = {
def OnlyKind: P[AST] = P(rise.Kind.Kind.map(AST.RiseKind) | "access".!.map(_ => AST.Access))

OnlyKind | (Identifier ~ "*" ~ OnlyKind).map(AST.VariadicKind.tupled)
Expand Down
2 changes: 1 addition & 1 deletion meta/src/main/scala/meta/parser/DPIA/Type.scala
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ object Type {
}
}

def PhraseType[_: P]: P[AST] = {
def PhraseType[$: P]: P[AST] = {
def DataType: P[rise.Type.AST] = rise.Type.DataType.DataType

def AccessType: P[Access.AST] = P(
Expand Down
2 changes: 1 addition & 1 deletion meta/src/main/scala/meta/parser/Nat.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ object Nat {
case class Sum(id: Identifier, from: AST, upTo: AST, body: AST) extends AST
}

def Nat[_: P]: P[AST] = {
def Nat[$: P]: P[AST] = {
def CompOrNat: P[AST] = {
def CompOp: P[String] = P("<".! | ">".!)
P(AddSubOrNat ~ (CompOp ~/ AddSubOrNat).rep).map(asBinaryOpOrNat)
Expand Down
4 changes: 2 additions & 2 deletions meta/src/main/scala/meta/parser/rise/Decl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ object Decl {
typeSignature: Type.AST) extends AST
}

def PrimitiveDeclarations[_: P]: P[Seq[AST.PrimitiveDeclaration]] =
def PrimitiveDeclarations[$: P]: P[Seq[AST.PrimitiveDeclaration]] =
P(Start ~ PrimitiveDeclaration.rep(1) ~ End)

def PrimitiveDeclaration[_: P]: P[AST.PrimitiveDeclaration] = {
def PrimitiveDeclaration[$: P]: P[AST.PrimitiveDeclaration] = {
def ScalaParams: P[(Int, Int)] = {
import scalaparse.Scala.TrailingCommaOps
P("(" ~ Index ~
Expand Down
2 changes: 1 addition & 1 deletion meta/src/main/scala/meta/parser/rise/Kind.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ object Kind {
case object MatrixLayout extends AST
}

def Kind[_: P]: P[AST] = P(
def Kind[$: P]: P[AST] = P(
"data".!.map(_ => AST.Data) |
"address".!.map(_ => AST.Address) |
"nat2nat".!.map(_ => AST.Nat2Nat) |
Expand Down
38 changes: 19 additions & 19 deletions meta/src/main/scala/meta/parser/rise/Type.scala
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ object Type {
}
}

def TypeSignature[_: P]: P[AST] = {
def TypeSignature[$: P]: P[AST] = {
def DepFunType: P[AST.DepFunType] =
P("(" ~ IdentifierKindPair ~ ")" ~ "->" ~/ TypeSignature).map(AST.DepFunType.tupled)

Expand All @@ -79,31 +79,31 @@ object Type {
P(DepFunType | VariadicDepFunType | ImplicitDepFunType | FunType | VariadicFunType | LeftTypeSignature)
}

def TypeIdentifier[_: P]: P[AST.Identifier] = P(Identifier).map(AST.Identifier)
def TypeIdentifier[$: P]: P[AST.Identifier] = P(Identifier).map(AST.Identifier)

def IdentifierKindPair[_: P]: P[(AST.Identifier, Kind.AST)] =
def IdentifierKindPair[$: P]: P[(AST.Identifier, Kind.AST)] =
P(Identifier.map(AST.Identifier) ~ ":" ~ Kind.Kind)

def UnrolledTypeIdentifier[_: P]: P[AST.UnrolledIdentifier] =
def UnrolledTypeIdentifier[$: P]: P[AST.UnrolledIdentifier] =
P("*" ~ Identifier).map(AST.UnrolledIdentifier)

object DataType {
def ScalarType[_: P]: P[AST.ScalarType] =
def ScalarType[$: P]: P[AST.ScalarType] =
P("bool".! | "int".! |
"i8".! | "i16".! | "i32".! | "i64".! |
"u8".! | "u16".! | "u32".! | "u64".! |
"f16".! | "f32".! | "f64".!).map(AST.ScalarType)

def NatType[_: P]: P[AST.NatType.type] = P("natType").map(_ => AST.NatType)
def NatType[$: P]: P[AST.NatType.type] = P("natType").map(_ => AST.NatType)

def OpaqueType[_: P]: P[AST.OpaqueType] = P( "\"" ~~ Identifier ~~ "\"" ).map(AST.OpaqueType)
def OpaqueType[$: P]: P[AST.OpaqueType] = P( "\"" ~~ Identifier ~~ "\"" ).map(AST.OpaqueType)

def IndexType[_: P]: P[AST.IndexType] = P("idx[" ~ Nat.Nat ~ "]").map(AST.IndexType)
def IndexType[$: P]: P[AST.IndexType] = P("idx[" ~ Nat.Nat ~ "]").map(AST.IndexType)

def VectorType[_: P]: P[AST.VectorType] =
def VectorType[$: P]: P[AST.VectorType] =
P("vec[" ~ DataType ~ "," ~ Nat.Nat ~ "]").map(t => AST.VectorType(t._2, t._1))

def FragmentType[_: P]: P[AST.FragmentType] = {
def FragmentType[$: P]: P[AST.FragmentType] = {
def FragmentKind: P[Fragment.AST] =
P(("fragment." ~~ (
"ACC".!.map(_ => Fragment.AST.ACC) |
Expand All @@ -122,34 +122,34 @@ object Type {
"," ~ MatrixLayoutKind ~ "]").map(AST.FragmentType.tupled)
}

def ManagedBufferType[_: P]: P[AST.ManagedBufferType] =
def ManagedBufferType[$: P]: P[AST.ManagedBufferType] =
P("managed[" ~ DataType ~ "]").map(AST.ManagedBufferType)

def DepArrayType[_: P]: P[AST.DepArrayType] =
def DepArrayType[$: P]: P[AST.DepArrayType] =
P(Nat.Nat ~ ".." ~/ NatToData).map(AST.DepArrayType.tupled)

def ArrayType[_: P]: P[AST.ArrayType] =
def ArrayType[$: P]: P[AST.ArrayType] =
P(Nat.Nat ~ "." ~~ !"." ~/ DataType).map(AST.ArrayType.tupled)

def DepPairType[_: P]: P[AST.DepPairType] =
def DepPairType[$: P]: P[AST.DepPairType] =
P("(" ~ IdentifierKindPair ~ "**" ~/ DataType ~ ")").map(AST.DepPairType.tupled)

def NatToDataApply[_: P]: P[AST.NatToDataApply] =
def NatToDataApply[$: P]: P[AST.NatToDataApply] =
P(NatToData ~ "(" ~ Nat.Nat ~ ")").map(AST.NatToDataApply.tupled)

def PairType[_: P]: P[AST.PairType] =
def PairType[$: P]: P[AST.PairType] =
P("(" ~ NoCut(DataType) ~ "," ~/ DataType ~ ")").map(AST.PairType.tupled)

def DataType[_: P]: P[AST] =
def DataType[$: P]: P[AST] =
P(ScalarType | NatType | OpaqueType | IndexType | VectorType | FragmentType |
ManagedBufferType | DepArrayType | ArrayType | DepPairType | NatToDataApply |
PairType | UnrolledTypeIdentifier | TypeIdentifier | ("(" ~ DataType ~ ")"))

def TypeName[_: P]: P[Unit] =
def TypeName[$: P]: P[Unit] =
P(ScalarType | NatType | "idx" | "vec" | "fragment" | "matrixLayout")
}

def NatToData[_: P]: P[AST] = {
def NatToData[$: P]: P[AST] = {
def NatToDataLambda: P[AST.NatToDataLambda] =
P("(" ~ IdentifierKindPair.filter(_._2 == Kind.AST.Nat).map(_._1) ~
"|->" ~/ DataType.DataType ~ ")").map(AST.NatToDataLambda.tupled)
Expand Down
2 changes: 1 addition & 1 deletion meta/src/main/scala/meta/parser/shared/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import fastparse.ScalaWhitespace._
import fastparse._

package object shared {
def Identifier[_: P]: P[String] = {
def Identifier[$: P]: P[String] = {
def Keywords: P[Unit] =
P(( "def" |
(rise.Kind.Kind: P[Unit]) | rise.Type.DataType.TypeName |
Expand Down
8 changes: 4 additions & 4 deletions src/main/scala/apps/cameraPipeline.scala
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ object cameraPipeline {
(lf32(1.0f) / kelvin - lf32(1.0f / 3200)) / lf32(1.0f / 7000 - 1.0f / 3200)
(
zipND(2)(matrix_3200, matrix_7000) |>
map(map(fun(p => p._1 * alpha + p._2 * (lf32(1.0f) - alpha)))) >>
map(map(fun(p => p.`1` * alpha + p.`2` * (lf32(1.0f) - alpha)))) >>
map(map(fun(v => cast(v * lf32(256.0f)) :: i16))) // Q8.8 fixed point
) |> fun(matrix =>
input |> transpose >>
Expand Down Expand Up @@ -380,11 +380,11 @@ object cameraPipeline {
blur121(u8)(u16)),
unsharp => {
letImage(mapImage(zipImage(plane, unsharp), fun(p =>
(cast(p._1) :: i16) - (cast(p._2) :: i16)
(cast(p.`1`) :: i16) - (cast(p.`2`) :: i16)
)), mask => {
mapImage(zipImage(plane, mask), fun(p =>
u8_sat(i16)((cast(p._1) :: i16)
+ (p._2 * (cast(strength_x32) :: i16)) / li16(32))
u8_sat(i16)((cast(p.`1`) :: i16)
+ (p.`2` * (cast(strength_x32) :: i16)) / li16(32))
)).expr
})
}))
Expand Down
4 changes: 2 additions & 2 deletions src/main/scala/apps/convolution.scala
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ object convolution {

private val dotElemWeightsSeq = fun((weights, elem) =>
oclReduceSeqUnroll(AddressSpace.Private)(fun((acc, pair) => {
val pixel = pair._1
val weight = pair._2
val pixel = pair.`1`
val weight = pair.`2`
acc + (pixel * weight)
}))(lf32(0.0f))(zip(join(elem))(weights)))

Expand Down
52 changes: 26 additions & 26 deletions src/main/scala/apps/gemmTensor.scala
Original file line number Diff line number Diff line change
Expand Up @@ -48,20 +48,20 @@ object gemmTensor {

zip
(bT |> split(nTileFrag))
(aRowsC._2 |> transpose |> split(nTileFrag)) |> // n/nTileFrag.(nTileFrag.k.f16, nTileFrag.mTileFrag.f32)
(aRowsC.`2` |> transpose |> split(nTileFrag)) |> // n/nTileFrag.(nTileFrag.k.f16, nTileFrag.mTileFrag.f32)
mapWarp(0)(fun(bColumnsTCT =>

zip
(transpose(aRowsC._1) |> split(kTileFrag))
(transpose(bColumnsTCT._1) |> split(kTileFrag)) |> // k/kTileFrag.(kTile.mTileFrag.f16 x kTile.nTile.f16)
(transpose(aRowsC.`1`) |> split(kTileFrag))
(transpose(bColumnsTCT.`1`) |> split(kTileFrag)) |> // k/kTileFrag.(kTile.mTileFrag.f16 x kTile.nTile.f16)

oclReduceSeq(AddressSpace.Private)(fun((cTile, abTiles) =>
tensorMMA(
abTiles._1 |> transpose |> asFragment |> toPrivate,
abTiles._2 |> asFragment |> toPrivate,
abTiles.`1` |> transpose |> asFragment |> toPrivate,
abTiles.`2` |> asFragment |> toPrivate,
cTile)))

(bColumnsTCT._2 |>
(bColumnsTCT.`2` |>
transpose |>
asFragment |> toPrivate |>
mapFragment(fun(x => x * (beta / alpha)))) |>
Expand Down Expand Up @@ -107,48 +107,48 @@ object gemmTensor {

zip
(bT |> split(nTileBlock))
(aRowsBlockC._2 |> transpose |> split(nTileBlock)) |>
(aRowsBlockC.`2` |> transpose |> split(nTileBlock)) |>
mapBlock(0)(fun(bColumnsTBlockCT => // (nTileBlock.k.f16, nTileBlock.mTileBlock.f32)

zip
(aRowsBlockC._1 |> split(mTileWarp))
(bColumnsTBlockCT._2 |> transpose |> split(mTileWarp)) |>
(aRowsBlockC.`1` |> split(mTileWarp))
(bColumnsTBlockCT.`2` |> transpose |> split(mTileWarp)) |>
mapThreads(1)(fun(aRowsWarpC => // (mTileWarp.k.f16, mTileWarp.nTileBlock.f32)

zip
(bColumnsTBlockCT._1 |> split(nTileWarp))
(aRowsWarpC._2 |> transpose |> split(nTileWarp)) |>
(bColumnsTBlockCT.`1` |> split(nTileWarp))
(aRowsWarpC.`2` |> transpose |> split(nTileWarp)) |>
mapWarp(0)(fun(bColumnsTWarpCT => // (nTileWarp.k.f16, nTileWarp.mTileWarp.f32)

zip
(aRowsWarpC._1 |> transpose |> split(kTileFrag))
(bColumnsTWarpCT._1 |> transpose |> split(kTileFrag)) |>
(aRowsWarpC.`1` |> transpose |> split(kTileFrag))
(bColumnsTWarpCT.`1` |> transpose |> split(kTileFrag)) |>
// k/kTileFrag.(kTileFrag.mTileWarp.f16, kTileFrag.nTileWarp.f16)

oclReduceSeq(AddressSpace.Private)(fun((cFrags, abTilesWarp) =>

//Load tiles of a-matrix into fragments
let(toPrivate(
abTilesWarp._1 |> transpose |> split(mTileFrag) |>
abTilesWarp.`1` |> transpose |> split(mTileFrag) |>
mapSeqUnroll(fun(aFragTile =>
aFragTile |> asFragment))))
be(aFrags => // mTileWarp/mTileFrag.WmmaAMatrix

//Load tiles of b-matrix into fragments
let(toPrivate(
abTilesWarp._2 |> transpose |> split(nTileFrag) |>
abTilesWarp.`2` |> transpose |> split(nTileFrag) |>
mapSeqUnroll(fun(bFragTileT =>
bFragTileT |> transpose |> asFragment))))
be(bFrags => // nTileWarp/nTileFrag.WmmaBMatrix

//Do matrix multiplication and accumulate with tensor cores
zip(aFrags)(cFrags) |>
mapSeqUnroll(fun(acFrags =>
zip(bFrags)(acFrags._2) |>
zip(bFrags)(acFrags.`2`) |>
mapSeqUnroll(fun(bcFrags =>
tensorMMA(acFrags._1, bcFrags._1, bcFrags._2)))))))))
tensorMMA(acFrags.`1`, bcFrags.`1`, bcFrags.`2`)))))))))

(bColumnsTWarpCT._2 |> transpose |> split(mTileFrag) |>
(bColumnsTWarpCT.`2` |> transpose |> split(mTileFrag) |>
mapSeq(fun(cTiles =>
cTiles |> transpose |> split(nTileFrag) |>
mapSeq(fun(cTileFragT =>
Expand Down Expand Up @@ -270,14 +270,14 @@ object gemmTensor {
oclReduceSeq(AddressSpace.Private)(fun((cFragsBlock, aTbTileBlock) =>

//Load aTile and bTile to shared memory
let(aTbTileBlock._1 |>
let(aTbTileBlock.`1` |>
transpose |>
copyMatrix(config.mTileBlock, config.kTileBlock, 8) |>
toSharedWithPadding(config.kTileBlock, 8))
be(aTile =>

//Load bTile transposed to shared memory
let(aTbTileBlock._2 |>
let(aTbTileBlock.`2` |>
transpose |>
copyMatrix(config.nTileBlock, config.kTileBlock, 8) |>
toSharedWithPadding(config.kTileBlock, 8))
Expand All @@ -289,9 +289,9 @@ object gemmTensor {

mapWarp(fun(abWarpC =>
warpMMA(
abWarpC._1._1,
abWarpC._1._2,
abWarpC._2 |> split(config.nNumberOfFragsWarp)) |>
abWarpC.`1`.`1`,
abWarpC.`1`.`2`,
abWarpC.`2` |> split(config.nNumberOfFragsWarp)) |>

mapSeq(mapSeq(fun(x => x))))) |>
join |>
Expand Down Expand Up @@ -464,9 +464,9 @@ object gemmTensor {

blockGEMM(
alpha, beta,
aRowsBlockBColumnBlockCTileBlock._1._1, //aRowsBlockBColumnBlockCTileBlock._1._1
aRowsBlockBColumnBlockCTileBlock._1._2, //aRowsBlockBColumnBlockCTileBlock._1._2
aRowsBlockBColumnBlockCTileBlock._2) |> //mTileBlock.nTilcblock.f32
aRowsBlockBColumnBlockCTileBlock.`1`.`1`, //aRowsBlockBColumnBlockCTileBlock.`1`.`1`
aRowsBlockBColumnBlockCTileBlock.`1`.`2`, //aRowsBlockBColumnBlockCTileBlock.`1`.`2`
aRowsBlockBColumnBlockCTileBlock.`2`) |> //mTileBlock.nTilcblock.f32
transpose)) |> //m/mTileBlock*n/nTileBlock.nTileBlock.mTilcblock.f32
join |> //m/mTileBlock*n.mTilcblock.f32
split(n) |> //m/mTileBlock.n.mTilcblock.f32
Expand Down
Loading
Loading