Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ast opencl fixes #771

Merged
merged 34 commits into from
Sep 26, 2022
Merged
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
8a09ff5
Added an expression equality checker class
sakehl Jun 20, 2022
1f3fe59
First version of translating SimplifiedNestedQuantifiers to new ast
sakehl Jun 24, 2022
abf4838
Unfold forall, small bugfix & refactor naming conventions
sakehl Aug 10, 2022
280d32b
Parblock without extra variables
sakehl Aug 10, 2022
f2e26a5
Add names of forall binders after rewriting
sakehl Aug 10, 2022
c5fdc5e
Take account equalities whilst simplifying quantifiers
sakehl Aug 15, 2022
73cd952
Small c file read fix & debug info print
sakehl Aug 17, 2022
71d9002
Merge remote-tracking branch 'utwente-fmt/ast' into ast-opencl-fixes
sakehl Aug 29, 2022
95b5df7
merge
sakehl Aug 29, 2022
4cd25a7
Added greater than/not zero information
sakehl Aug 30, 2022
f200d26
Smaller fixes
sakehl Aug 30, 2022
0dc703d
Improvements to nested quantifier check
sakehl Aug 30, 2022
aebc48b
Add better origin names of C files
sakehl Sep 5, 2022
fee6e7f
Added pointer_length and smaller fixes
sakehl Sep 5, 2022
f2938cb
GPU blocks should always be non empty encoded
sakehl Sep 5, 2022
dabf180
Single parblock required to be non-empty
sakehl Sep 5, 2022
6b8310b
Rearange transformation to work better with simplify nested quantifiers
sakehl Sep 5, 2022
d2e6a2b
Add bool to cuda.h and opencl.h
sakehl Sep 5, 2022
b70a7b4
Merge remote-tracking branch 'utwente-fmt/ast' into ast-opencl-fixes
sakehl Sep 5, 2022
4731347
Merge and warning fixes
sakehl Sep 5, 2022
800f3cc
Merge remote-tracking branch 'utwente-fmt/ast' into ast-opencl-fixes
sakehl Sep 6, 2022
e1db973
Add shared memory support
sakehl Sep 14, 2022
03fdf46
Merge branch 'ast-opencl-shared-mem' into ast-opencl-fixes
sakehl Sep 14, 2022
5bf3352
Merge remote-tracking branch 'utwente-fmt/ast' into ast-opencl-fixes
sakehl Sep 14, 2022
722e734
Some fixes to SimplifNestedQuantifiers to work with 'new' permissions
sakehl Sep 14, 2022
0565c7d
Added barriers with memory fences
sakehl Sep 19, 2022
a9c4e99
Changes based on pull request review
sakehl Sep 20, 2022
937e982
Merge remote-tracking branch 'utwente-fmt/ast' into ast-opencl-fixes
sakehl Sep 20, 2022
b348bad
Added analysis to decide if an expression remains constant
sakehl Sep 22, 2022
bbf3b2b
Added static shared memory
sakehl Sep 26, 2022
1b4296b
Safe specific kernel type as cuda or opencl
sakehl Sep 26, 2022
d3dc6c8
Merge branch 'ast-before-rename' into ast-opencl-fixes
sakehl Sep 26, 2022
aa199a0
Merge branch 'ast' into ast-opencl-fixes
pieter-bos Sep 26, 2022
061f7d9
Merge branch 'ast-opencl-fixes' of ssh://github.com/sakehl/vercors in…
pieter-bos Sep 26, 2022
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
3 changes: 3 additions & 0 deletions col/src/main/java/vct/col/ast/Node.scala
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,7 @@ final case class Length[G](arr: Expr[G])(val blame: Blame[ArrayNull])(implicit v
final case class Size[G](obj: Expr[G])(implicit val o: Origin) extends Expr[G] with SizeImpl[G]
final case class PointerBlockLength[G](pointer: Expr[G])(val blame: Blame[PointerNull])(implicit val o: Origin) extends Expr[G] with PointerBlockLengthImpl[G]
final case class PointerBlockOffset[G](pointer: Expr[G])(val blame: Blame[PointerNull])(implicit val o: Origin) extends Expr[G] with PointerBlockOffsetImpl[G]
final case class SharedMemSize[G](pointer: Expr[G])(implicit val o: Origin) extends Expr[G] with SharedMemSizeImpl[G]

final case class Cons[G](x: Expr[G], xs: Expr[G])(implicit val o: Origin) extends Expr[G] with ConsImpl[G]
final case class Head[G](xs: Expr[G])(val blame: Blame[SeqBoundFailure])(implicit val o: Origin) extends Expr[G] with HeadImpl[G]
Expand Down Expand Up @@ -633,6 +634,8 @@ sealed trait CStorageClassSpecifier[G] extends CDeclarationSpecifier[G] with CSt
final case class CTypedef[G]()(implicit val o: Origin) extends CStorageClassSpecifier[G] with CTypedefImpl[G]
final case class CExtern[G]()(implicit val o: Origin) extends CStorageClassSpecifier[G] with CExternImpl[G]
final case class CStatic[G]()(implicit val o: Origin) extends CStorageClassSpecifier[G] with CStaticImpl[G]
final case class GPULocal[G]()(implicit val o: Origin) extends CStorageClassSpecifier[G] with GPULocalImpl[G]
final case class GPUGlobal[G]()(implicit val o: Origin) extends CStorageClassSpecifier[G] with GPUGlobalImpl[G]

sealed trait CTypeSpecifier[G] extends CDeclarationSpecifier[G] with CTypeSpecifierImpl[G]
final case class CVoid[G]()(implicit val o: Origin) extends CTypeSpecifier[G] with CVoidImpl[G]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package vct.col.ast.temporaryimplpackage.lang

import vct.col.ast.GPUGlobal

trait GPUGlobalImpl[G] { this: GPUGlobal[G] =>

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package vct.col.ast.temporaryimplpackage.lang

import vct.col.ast.GPULocal

trait GPULocalImpl[G] {this: GPULocal[G] =>

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package vct.col.ast.temporaryimplpackage.lang

import vct.col.ast.{SharedMemSize, TInt, Type}

trait SharedMemSizeImpl[G] { this: SharedMemSize[G] =>
override def t: Type[G] = TInt()
}
361 changes: 361 additions & 0 deletions col/src/main/java/vct/col/ast/util/ExpressionEqualityCheck.scala

Large diffs are not rendered by default.

7 changes: 6 additions & 1 deletion col/src/main/java/vct/col/coerce/CoercingRewriter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ abstract class CoercingRewriter[Pre <: Generation]() extends Rewriter[Pre] with

e match {
case ApplyCoercion(_, _) =>
throw Unreachable("All instances of ApplyCoercion should be immediately rewritten by CoercingRewriter.disptach.")
throw Unreachable("All instances of ApplyCoercion should be immediately rewritten by CoercingRewriter.dispatch.")

case ActionApply(action, args) =>
ActionApply(action, coerceArgs(args, action.decl))
Expand Down Expand Up @@ -988,6 +988,11 @@ abstract class CoercingRewriter[Pre <: Generation]() extends Rewriter[Pre] with
val (right, TSet(rightT)) = set(ys)
val sharedElement = Types.leastCommonSuperType(leftT, rightT)
SetUnion(coerce(left, TSet(sharedElement)), coerce(right, TSet(sharedElement)))
case SharedMemSize(xs) =>
firstOk(e, s"Expected operand to be a pointer or array, but got ${xs.t}.",
SharedMemSize(array(xs)._1),
SharedMemSize(pointer(xs)._1),
)
case SilverBagSize(xs) =>
SilverBagSize(bag(xs)._1)
case SilverCurFieldPerm(obj, field) =>
Expand Down
2 changes: 2 additions & 0 deletions col/src/main/java/vct/col/feature/FeatureRainbow.scala
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,8 @@ class FeatureRainbow[G] {
case node: CStructAccess[G] => return Nil
case node: CStructDeref[G] => return Nil
case node: GpgpuCudaKernelInvocation[G] => return Nil
case node: LocalThreadId[G] => return Nil
case node: GlobalThreadId[G] => return Nil
case node: CPrimitiveType[G] => return Nil
case node: JavaName[G] => return Nil
case node: JavaImport[G] => return Nil
Expand Down
11 changes: 11 additions & 0 deletions col/src/main/java/vct/col/origin/Origin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,17 @@ case class ReadableOrigin(readable: Readable,
override def toString: String = f"$startText - $endText"
}

case class InterpretedOriginVariable(name: String, original: Origin)
extends InputOrigin {
override def preferredName: String = name

override def context: String = original.context

override def inlineContext: String = original.inlineContext

override def shortPosition: String = original.shortPosition
}

case class InterpretedOrigin(interpreted: Readable,
startLineIdx: Int, endLineIdx: Int,
cols: Option[(Int, Int)],
Expand Down
20 changes: 16 additions & 4 deletions col/src/main/java/vct/col/print/Printer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -633,9 +633,9 @@ case class Printer(out: Appendable,
case MapDisjoint(left, right) =>
(phrase("disjointMap(", left, ",", space, right, ")"), 100)
case Forall(bindings, triggers, body) =>
(phrase("(", "\\forall", space, phrase(bindings.map(NodePhrase):_*), "; true; ", body, ")"), 120)
(phrase("(", "\\forall", space, commas(bindings.map(NodePhrase)), "; true; ", body, ")"), 120)
case Exists(bindings, triggers, body) =>
(phrase("(", "\\exists", space, phrase(bindings.map(NodePhrase):_*), "; true; ", body, ")"), 120)
(phrase("(", "\\exists", space, commas(bindings.map(NodePhrase)), "; true; ", body, ")"), 120)
case ValidArray(arr, len) =>
(phrase("\\array(", arr, ",", space, len, ")"), 100)
case ValidMatrix(mat, w, h) =>
Expand All @@ -655,13 +655,15 @@ case class Printer(out: Appendable,
case JoinToken(thread) =>
(phrase("running", "(", thread, ")"), 100)
case Starall(bindings, triggers, body) =>
(phrase("(", "\\forall*", space, phrase(bindings.map(NodePhrase):_*), "; true; ", body, ")"), 120)
(phrase("(", "\\forall*", space, commas(bindings.map(NodePhrase)), "; true; ", body, ")"), 120)
case Star(left, right) =>
(phrase(assoc(40, left), space, "**", space, assoc(40, right)), 40)
case Wand(left, right) =>
(phrase(bind(30, left), space, "-*", space, assoc(30, right)), 30)
case Scale(scale, res) =>
(phrase("[", scale, "]", assoc(90, res)), 90)
case ScaleByParBlock(block, res) =>
(phrase("[", block.decl, "]", assoc(90, res)), 90)
case Perm(loc, perm) =>
(phrase("Perm(", loc, ",", space, perm, ")"), 100)
case PointsTo(loc, perm, value) =>
Expand Down Expand Up @@ -849,6 +851,10 @@ case class Printer(out: Appendable,
(phrase(assoc(100, arr), "[", index, "]"), 100)
case PointerSubscript(pointer, index) =>
(phrase(assoc(100, pointer), "[", index, "]"), 100)
case PointerBlockOffset(pointer) =>
(phrase("pointer_block(", pointer ,")"), 100)
case PointerBlockLength(pointer) =>
(phrase("block_length(", pointer ,")"), 100)
case Cons(x, xs) =>
(phrase(bind(87, x), space, "::", space, assoc(87, xs)), 87)
case Head(xs) =>
Expand Down Expand Up @@ -970,7 +976,6 @@ case class Printer(out: Appendable,
phrase(spaced(local.modifiers.map(NodePhrase)), space, local.t, space, javaDecls(local.decls))
case defn: CFunctionDefinition[_] =>
control(phrase(spaced(defn.specs.map(NodePhrase)), space, defn.declarator), defn.body)
case decl: CGlobalDeclaration[_] => decl
case ns: JavaNamespace[_] =>
phrase(
if(ns.pkg.nonEmpty) statement("package", space, ns.pkg.get) else phrase(),
Expand Down Expand Up @@ -1208,6 +1213,13 @@ case class Printer(out: Appendable,
case CSpecificationType(t) => say(t)
case CTypeQualifierDeclarationSpecifier(typeQual) => say(typeQual)
case CKernel() => say("__kernel")
case GPULocal() => say(syntax(
Cuda -> phrase("__shared__"),
OpenCL -> phrase("__local"),
))
case GPUGlobal() => say(syntax(
OpenCL -> phrase("__global"),
))
}

def printCTypeQualifier(node: CTypeQualifier[_]): Unit = node match {
Expand Down
11 changes: 10 additions & 1 deletion col/src/main/java/vct/col/util/AstBuildHelpers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -316,10 +316,13 @@ object AstBuildHelpers {
exprs.reduceOption(And(_, _)).getOrElse(tt)

def unfoldPredicate[G](p: AccountedPredicate[G]): Seq[Expr[G]] = p match {
case UnitAccountedPredicate(pred) => Seq(pred)
case UnitAccountedPredicate(pred) => unfoldStar(pred)
case SplitAccountedPredicate(left, right) => unfoldPredicate(left) ++ unfoldPredicate(right)
}

def filterPredicate[G](p: AccountedPredicate[G], f: Expr[G] => Boolean): AccountedPredicate[G] =
foldPredicate(unfoldPredicate(p).filter(f))(p.o)

def mapPredicate[G1, G2](p: AccountedPredicate[G1], f: Expr[G1] => Expr[G2]): AccountedPredicate[G2] = p match {
case UnitAccountedPredicate(pred) => UnitAccountedPredicate(f(pred))(p.o)
case SplitAccountedPredicate(left, right) => SplitAccountedPredicate(mapPredicate(left, f), mapPredicate(right, f))(p.o)
Expand Down Expand Up @@ -354,6 +357,12 @@ object AstBuildHelpers {
case SplitAccountedPredicate(left, right) => Star(foldStar(left), foldStar(right))
}

def foldPredicate[G](exprs: Seq[Expr[G]])(implicit o: Origin): AccountedPredicate[G] =
exprs
.map(e => UnitAccountedPredicate(e)(e.o))
.reduceOption[AccountedPredicate[G]](SplitAccountedPredicate(_, _))
.getOrElse(UnitAccountedPredicate(tt))

def foldOr[G](exprs: Seq[Expr[G]])(implicit o: Origin): Expr[G] =
exprs.reduceOption(Or(_, _)).getOrElse(ff)
}
2 changes: 2 additions & 0 deletions parsers/lib/antlr4/LangCParser.g4
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,8 @@ storageClassSpecifier
| '_Thread_local'
| 'auto'
| 'register'
| gpgpuLocalMemory
| gpgpuGlobalMemory
;

typeSpecifier
Expand Down
2 changes: 2 additions & 0 deletions parsers/lib/antlr4/LangGPGPULexer.g4
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ GPGPU_LOCAL_BARRIER: '__vercors_local_barrier__';
GPGPU_GLOBAL_BARRIER: '__vercors_global_barrier__';
GPGPU_KERNEL: '__vercors_kernel__';
GPGPU_ATOMIC: '__vercors_atomic__';
GPGPU_GLOBAL_MEMORY: '__global';
GPGPU_LOCAL_MEMORY: '__local';

GPGPU_CUDA_OPEN_EXEC_CONFIG: '<<<';
GPGPU_CUDA_CLOSE_EXEC_CONFIG: '>>>';
6 changes: 5 additions & 1 deletion parsers/lib/antlr4/LangGPGPUParser.g4
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,8 @@ gpgpuAtomicBlock
: valEmbedWith? GPGPU_ATOMIC compoundStatement valEmbedThen?
;

gpgpuKernelSpecifier: GPGPU_KERNEL;
gpgpuKernelSpecifier: GPGPU_KERNEL;

gpgpuLocalMemory: GPGPU_LOCAL_MEMORY;

gpgpuGlobalMemory: GPGPU_GLOBAL_MEMORY;
2 changes: 2 additions & 0 deletions parsers/lib/antlr4/SpecLexer.g4
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@ POINTER: '\\pointer';
POINTER_INDEX: '\\pointer_index';
POINTER_BLOCK_LENGTH: '\\pointer_block_length';
POINTER_BLOCK_OFFSET: '\\pointer_block_offset';
POINTER_LENGTH: '\\pointer_length';
SHARED_MEM_SIZE: '\\shared_mem_size';
VALUES: '\\values';
VCMP: '\\vcmp';
VREP: '\\vrep';
Expand Down
2 changes: 2 additions & 0 deletions parsers/lib/antlr4/SpecParser.g4
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ valPrimaryPermission
| '\\pointer_index' '(' langExpr ',' langExpr ',' langExpr ')' # valPointerIndex
| '\\pointer_block_length' '(' langExpr ')' # valPointerBlockLength
| '\\pointer_block_offset' '(' langExpr ')' # valPointerBlockOffset
| '\\pointer_length' '(' langExpr ')' # valPointerLength
;

valPrimaryBinder
Expand Down Expand Up @@ -253,6 +254,7 @@ valPrimary
| '\\type' '(' langType ')' # valTypeValue
| 'held' '(' langExpr ')' # valHeld
| LANG_ID_ESCAPE # valIdEscape
| '\\shared_mem_size' '(' langExpr ')' # valSharedMemSize
;

// Out spec: defined meaning: a language local
Expand Down
3 changes: 2 additions & 1 deletion parsers/src/main/java/vct/parsers/ColCParser.scala
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ case class ColCParser(override val originProvider: OriginProvider,
cc: Path,
systemInclude: Path,
otherIncludes: Seq[Path],
defines: Map[String, String]) extends Parser(originProvider, blameProvider) with LazyLogging {
defines: Map[String, String],
language: Language) extends Parser(originProvider, blameProvider) with LazyLogging {
sakehl marked this conversation as resolved.
Show resolved Hide resolved
def interpret(localInclude: Seq[Path], input: String, output: String): Process = {
var command = Seq(cc.toString, "-C", "-E")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ package vct.parsers
case object Language {
def fromFilename(filename: String): Option[Language] =
filename.split('.').last match {
case "cl" | "c" | "cu" => Some(C)
case "cl" | "c" => Some(C)
case "cu" => Some(CUDA)
case "i" => Some(InterpretedC)
case "java" => Some(Java)
case "pvl" => Some(PVL)
Expand All @@ -12,6 +13,7 @@ case object Language {
}

case object C extends Language
case object CUDA extends Language
case object InterpretedC extends Language
case object Java extends Language
case object PVL extends Language
Expand Down
9 changes: 5 additions & 4 deletions parsers/src/main/java/vct/parsers/ParseResult.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ import vct.col.ast.{GlobalDeclaration, VerificationContext}
import vct.col.util.ExpectedError

case object ParseResult {
def reduce[G](parses: Seq[ParseResult[G]]): ParseResult[G] =
def reduce[G](parses: Seq[(ParseResult[G], Option[Language])]): (ParseResult[G], Option[Language]) =
parses.reduceOption((l, r) => (l, r) match {
case (ParseResult(declsLeft, expectedLeft), ParseResult(declsRight, expectedRight)) =>
ParseResult(declsLeft ++ declsRight, expectedLeft ++ expectedRight)
}).getOrElse(ParseResult(Nil, Nil))
case ((ParseResult(declsLeft, expectedLeft), l1), (ParseResult(declsRight, expectedRight), l2)) =>
val lan = if(l1 == l2) l1 else None
(ParseResult(declsLeft ++ declsRight, expectedLeft ++ expectedRight), lan)
}).getOrElse((ParseResult(Nil, Nil), None))
}

case class ParseResult[G](decls: Seq[GlobalDeclaration[G]], expectedErrors: Seq[ExpectedError])
7 changes: 7 additions & 0 deletions parsers/src/main/java/vct/parsers/transform/CToCol.scala
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ case class CToCol[G](override val originProvider: OriginProvider, override val b
case StorageClassSpecifier3(_) => ??(storageClass)
case StorageClassSpecifier4(_) => ??(storageClass)
case StorageClassSpecifier5(_) => ??(storageClass)
case StorageClassSpecifier6(_) => GPULocal()
case StorageClassSpecifier7(_) => GPUGlobal()
}

def convert(implicit typeSpec: TypeSpecifierContext): CTypeSpecifier[G] = typeSpec match {
Expand Down Expand Up @@ -956,6 +958,10 @@ case class CToCol[G](override val originProvider: OriginProvider, override val b
case ValPointerIndex(_, _, ptr, _, idx, _, perm, _) => PermPointerIndex(convert(ptr), convert(idx), convert(perm))
case ValPointerBlockLength(_, _, ptr, _) => PointerBlockLength(convert(ptr))(blame(e))
case ValPointerBlockOffset(_, _, ptr, _) => PointerBlockOffset(convert(ptr))(blame(e))
case ValPointerLength(_, _, ptr, _) =>
val convertedPtr = convert(ptr)
val blameExpr = blame(e)
PointerBlockLength(convertedPtr)(blameExpr) - PointerBlockOffset(convertedPtr)(blameExpr)
sakehl marked this conversation as resolved.
Show resolved Hide resolved
}

def convert(implicit e: ValPrimaryBinderContext): Expr[G] = e match {
Expand Down Expand Up @@ -1033,6 +1039,7 @@ case class CToCol[G](override val originProvider: OriginProvider, override val b
case ValTypeValue(_, _, t, _) => TypeValue(convert(t))
case ValHeld(_, _, obj, _) => Held(convert(obj))
case ValIdEscape(text) => local(e, text.substring(1, text.length-1))
case ValSharedMemSize(_, _, ptr, _) => SharedMemSize(convert(ptr))
}

def convert(implicit e: ValExprContext): Expr[G] = e match {
Expand Down
Loading