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

Rewriting the SYCL encoding #1311

Draft
wants to merge 11 commits into
base: dev
Choose a base branch
from
Draft
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
4 changes: 3 additions & 1 deletion examples/concepts/sycl/dataAccessors/AccessorInNDRange.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include <sycl/sycl.hpp>

/*@
requires \pointer(a, 10, write);
context \pointer(a, 10, write);
*/
void test(int* a) {
sycl::queue myQueue;
Expand All @@ -28,6 +28,8 @@ void test(int* a) {
);
} // Leaving scope, which destroys aBuffer, which waits on the kernel to terminate as it uses aBuffer

//@ assert (\forall int i; 0 <= i && i < 10 ==> a[i] == a[sycl::linearize2(i/5, i%5, 2,5)]);

//@ assert (\forall int i; i >= 0 && i < 10; a[i] == 10);

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#include <sycl/sycl.hpp>
/*

This example is obsolete. Due to fixes in the scoping, the missing annotation here is not needed anymore.
I call it, "missing by design"
*/
/*@
requires \pointer(a, 12, write);
*/
Expand All @@ -17,6 +21,8 @@ void test(int* a) {
/*@
requires 1 < a_accessor.get_range().get(0);
requires 2 < a_accessor.get_range().get(1);
requires (\forall* int x = 0 .. a_accessor.get_range().get(0), int y = 0 .. a_accessor.get_range().get(1), int z = 0 .. a_accessor.get_range().get(2);
Perm(a_accessor[x][y][z], read));
*/
[=] (sycl::item<1> it) { // Bound requirement for the 3rd index is missing, so cannot verify
int a = a_accessor[1][2][1];
Expand Down
13 changes: 11 additions & 2 deletions res/universal/res/cpp/sycl/sycl.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
namespace sycl {

namespace h {
/*@
ensures (a>0 && b>0) ==> \result > 0;
ensures \result == a*b;
pure int mul(int a, int b) = a*b;

*/
}

namespace event {
void wait();
}
Expand Down Expand Up @@ -27,7 +36,7 @@ namespace sycl {
requires id0 >= 0 && id0 < r0 && id1 >= 0 && id1 < r1;
requires r0 > 0 && r1 > 0;
ensures \result == sycl::linearize2formula(id0, id1, r1);
ensures \result >= 0 && \result < r0 * r1;
ensures \result >= 0 && \result < sycl::h::mul(r0,r1);
ensures (\forall int ida0, int ida1;
ida0 >= 0 && ida0 < r0 &&
ida1 >= 0 && ida1 < r1 &&
Expand All @@ -36,7 +45,7 @@ namespace sycl {
);
pure int linearize2(int id0, int id1, int r0, int r1);

pure int linearize2formula(int id0, int id1, int r1) = id1 + (id0 * r1);
pure int linearize2formula(int id0, int id1, int r1) = id1 + sycl::h::mul(id0, r1);

requires id0 >= 0 && id0 < r0 && id1 >= 0 && id1 < r1 && id2 >= 0 && id2 < r2;
requires r0 > 0 && r1 > 0 && r2 > 0;
Expand Down
24 changes: 24 additions & 0 deletions src/col/vct/col/ast/lang/sycl/SYCLTBufferImpl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ trait SYCLTBufferImpl[G] extends SYCLTBufferOps[G] {
new Variable[G](TPointer(this.typ))(o.where(name = "hostData"))
val sizeVar = new Variable[G](TCInt())(o.where(name = "size"))
val indexVar = new Variable[G](TCInt())(o.where(name = "i"))
val indexVar2 = new Variable[G](TCInt())(o.where(name = "i"))
val copyHostdataToBufferBlame = PanicBlame(
"The generated method 'copy_hostData_to_buffer' should not throw any errors."
)
Expand Down Expand Up @@ -150,6 +151,29 @@ trait SYCLTBufferImpl[G] extends SYCLTBufferOps[G] {
WritePerm(),
copyHostdataToBufferBlame,
),
Forall(
bindings = Seq(indexVar2),
triggers = Seq(
Seq(ArraySubscript(result, Local[G](indexVar2.ref))(
copyHostdataToBufferBlame
))
),
body =
(Local[G](indexVar2.ref) >= c_const(0) &&
Local[G](indexVar2.ref) < Local[G](sizeVar.ref)) ==> Eq(
PointerSubscript(
Local[G](hostDataVar.ref),
Local[G](indexVar2.ref),
)(copyHostdataToBufferBlame),
Old[G](
PointerSubscript(
Local[G](hostDataVar.ref),
Local[G](indexVar2.ref),
)(copyHostdataToBufferBlame),
None
)(copyHostdataToBufferBlame)
),
),
Forall(
bindings = Seq(indexVar),
triggers = Seq(
Expand Down
1 change: 0 additions & 1 deletion src/col/vct/col/resolve/lang/CPP.scala
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,6 @@ case object CPP {
getBaseTypeFromSpecs(returnedSpecs)
case x => x
}

}

def paramsFromDeclarator[G](declarator: CPPDeclarator[G]): Seq[CPPParam[G]] =
Expand Down
4 changes: 1 addition & 3 deletions src/col/vct/col/typerules/CoercionUtils.scala
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@ case object CoercionUtils {
case (TResource(), TResourceVal()) => CoerceResourceResourceVal()
case (TResourceVal(), TResource()) => CoerceResourceValResource()
case (TBool(), TResource()) => CoerceBoolResource()
case (TBool(), TResourceVal()) =>
CoercionSequence(Seq(CoerceBoolResource(), CoerceResourceResourceVal()))

case (TBool(), TResourceVal()) => CoercionSequence(Seq(CoerceBoolResource(), CoerceResourceResourceVal()))
case (_, TAnyValue()) => CoerceSomethingAnyValue(source)

case (source @ TOption(innerSource), target @ TOption(innerTarget)) =>
Expand Down
3 changes: 3 additions & 0 deletions src/parsers/antlr4/SpecLexer.g4
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ NEVER: EOF '=';
// Must be able to contain identifiers from any frontend, so it's fine to over-approximate valid identifiers a bit.
LANG_ID_ESCAPE: '`' ~[`]+ '`';

VAL_PrependOp : '+:';
VAL_AppendOp : ':+';

VAL_RESOURCE: 'resource';
VAL_PROCESS: 'process';
VAL_FRAC: 'frac';
Expand Down
4 changes: 2 additions & 2 deletions src/parsers/antlr4/SpecParser.g4
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ valImpOp: '-*' | '==>';
valAndOp: '**';
valInOp: '\\in';
valMulOp: '\\';
valPrependOp : '::';
valAppendOp : '++'; // postfix issues? maybe disable in spec - no side effects?
valPrependOp : '+:';
valAppendOp : ':+'; // postfix issues? maybe disable in spec - no side effects?
valPostfix
: '[' '..' langExpr ']'
| '[' langExpr '..' langExpr? ']'
Expand Down
Loading
Loading