Skip to content

Commit

Permalink
No sequences with get_id
Browse files Browse the repository at this point in the history
  • Loading branch information
sakehl committed Dec 8, 2023
1 parent aa5bdca commit fd441e3
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 8 deletions.
1 change: 1 addition & 0 deletions src/col/vct/col/typerules/CoercionUtils.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ case object CoercionUtils {
case (TResource(), TResourceVal()) => CoerceResourceResourceVal()
case (TResourceVal(), TResource()) => CoerceResourceValResource()
case (TBool(), TResource()) => CoerceBoolResource()
case (TBool(), TResourceVal()) => CoercionSequence(Seq(CoerceBoolResource(), CoerceResourceResourceVal()))

case (_, TAnyValue()) => CoerceSomethingAnyValue(source)

Expand Down
38 changes: 30 additions & 8 deletions src/rewrite/vct/rewrite/lang/LangCPPToCol.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package vct.rewrite.lang
import com.typesafe.scalalogging.LazyLogging
import hre.util.{FuncTools, ScopedStack}
import vct.col.ast._
import vct.col.ast.util.ExpressionEqualityCheck.isConstantInt
import vct.col.origin._
import vct.col.ref.Ref
import vct.col.resolve.NotApplicable
Expand Down Expand Up @@ -650,7 +651,13 @@ case class LangCPPToCol[Pre <: Generation](rw: LangSpecificToCol[Pre]) extends L
LiteralSeq[Post](TInt(), rangeIndexFields.map(f => Deref[Post](currentThis.get, f.ref)(SYCLAccessorRangeIndexFieldInsufficientReferencePermissionBlame(inv))))
case "sycl::accessor::get_range" => throw NotApplicable(inv)
case "sycl::range::get" => (classInstance, args) match {
case (Some(seq: LiteralSeq[Post]), Seq(arg)) => SeqSubscript(seq, rw.dispatch(arg))(SYCLRequestedRangeIndexOutOfBoundsBlame(seq, arg)) // Range coming from calling get_range() on an accessor
case (Some(seq: LiteralSeq[Post]), Seq(arg)) =>
isConstantInt(arg) match {
case Some(i) if 0<= i && i < seq.values.size => return seq.values(i.toInt)
case _ =>
}

SeqSubscript(seq, rw.dispatch(arg))(SYCLRequestedRangeIndexOutOfBoundsBlame(seq, arg)) // Range coming from calling get_range() on an accessor
case _ => throw NotApplicable(inv)
}

Expand Down Expand Up @@ -1083,17 +1090,32 @@ case class LangCPPToCol[Pre <: Generation](rw: LangSpecificToCol[Pre]) extends L
}

private def getSimpleWorkItemId(inv: CPPInvocation[Pre], level: KernelScopeLevel) (implicit o: Origin) : Expr[Post] = {
val givenValueLambda: Ref[Post, Procedure[Post]] => Seq[(Ref[Post, Variable[Post]], Expr[Post])] = procedureRef =>
Seq((procedureRef.decl.contract.givenArgs.head.ref, LiteralSeq(TInt(), currentDimensions(level).map(iterVar => iterVar.variable.get))))

getSYCLWorkItemIdOrRange(inv, givenValueLambda)
val dim = inv.args match {
case Seq(dim) => dim
case _ => ???
}
isConstantInt(dim) match {
case Some(i) if 0<= i && i < currentDimensions(level).size => currentDimensions(level)(i.toInt).variable.get
case _ =>
}

// // Fallback if we cannot solve it to an int
// SeqSubscript[Post](LiteralSeq(TInt(), currentDimensionIterVars(level).map(iterVar => iterVar.variable.get).toSeq), rw.dispatch(inv.args.head))(SYCLItemMethodSeqBoundFailureBlame(inv))
}

private def getSimpleWorkItemRange(inv: CPPInvocation[Pre], level: KernelScopeLevel)(implicit o: Origin): Expr[Post] = {
val givenValueLambda: Ref[Post, Procedure[Post]] => Seq[(Ref[Post, Variable[Post]], Expr[Post])] = procedureRef =>
Seq((procedureRef.decl.contract.givenArgs.head.ref, LiteralSeq(TInt(), currentDimensions(level).map(iterVar => iterVar.to))))
val dim = inv.args match {
case Seq(dim) => dim
case _ => ???
}
isConstantInt(dim) match {
case Some(i) if 0<= i && i < currentDimensions(level).size => currentDimensions(level)(i.toInt).variable.get
case _ =>
}

getSYCLWorkItemIdOrRange(inv, givenValueLambda)
// // Fallback if we cannot solve it to an int
// SeqSubscript[Post](LiteralSeq(TInt(), currentDimensionIterVars(level).map(iterVar => iterVar.to).toSeq), rw.dispatch(inv.args.head))(SYCLItemMethodSeqBoundFailureBlame(inv))
// Seq((procedureRef.decl.contract.givenArgs.head.ref, LiteralSeq(TInt(), currentDimensions(level).map(iterVar => iterVar.to))))
}

private def getSimpleWorkItemLinearId(inv: CPPInvocation[Pre], level: KernelScopeLevel)(implicit o: Origin): Expr[Post] = {
Expand Down

0 comments on commit fd441e3

Please sign in to comment.