Skip to content

Commit

Permalink
Merge pull request #138 from dpanfilyonok/fix
Browse files Browse the repository at this point in the history
Fix generic to private space conversion
  • Loading branch information
gsvgit authored May 7, 2022
2 parents e154939 + a2874aa commit b6bd6e9
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/Brahma.FSharp.OpenCL.Translator/Body.fs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,11 @@ module rec Body =
| _ -> return! Type.translate var.Type
}

return VarDecl(varType, newName, Some body)
let varDecl = VarDecl(varType, newName, Some body)
if varType :? RefType<Lang> then
varDecl.SpaceModifier <- Some AddressSpaceQualifier.Private

return varDecl
}

let private translateListOfArgs (args: Expr list) =
Expand Down Expand Up @@ -630,7 +634,6 @@ module rec Body =
let! res = translate inExpr |> State.using clearContext
let! sb = State.gets (fun context -> context.VarDecls)


match res with
| :? StatementBlock<Lang> as s -> sb.AddRange s.Statements
| _ -> sb.Add(res :?> Statement<_>)
Expand Down
20 changes: 20 additions & 0 deletions tests/Brahma.FSharp.Tests/ExecutionTests/CompilationTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,25 @@ module Helpers =

Utils.filesAreEqual targetPath expectedPath

let simpleTests context = [
let inline checkCode command outFile expected = checkCode context command outFile expected
testCase "Pointers to private values should be explicitly private" <| fun () ->
let command =
<@
fun (k: Range1D) (a: int clarray) ->
let x (a: int) =
a + 1

let mutable s = 1
let mutable s = 2
let s1 = x s

a.[0] <- s1
@>

checkCode command "GenericSpace.gen" "GenericSpace.cl"
]

type SimpleUnion =
| SimpleOne
| SimpleTwo of int
Expand Down Expand Up @@ -143,6 +162,7 @@ let unionTests context =

let tests context =
[
testList "Simple tests" << simpleTests
testList "Union Compile tests" << unionTests
]
|> List.map (fun testFixture -> testFixture context)
Expand Down
10 changes: 10 additions & 0 deletions tests/Brahma.FSharp.Tests/ExecutionTests/Expected/GenericSpace.cl
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
int x (private int a1)
{return (a1 + 1) ;}
int s1UnitFunc (private int * s2Ref)
{return x (* (s2Ref)) ;}
__kernel void brahmaKernel (__global int * a)
{int s = 1 ;
int s2 = 2 ;
__private int * s2Ref = & s2 ;
int s1 = s1UnitFunc (s2Ref) ;
a [0] = s1 ;}

0 comments on commit b6bd6e9

Please sign in to comment.