-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
54 changed files
with
1,375 additions
and
216 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
...n/scala/spn_compiler/backend/software/ast/extensions/cpp/value/CPPAddressOfOperator.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package spn_compiler.backend.software.ast.extensions.cpp.value | ||
|
||
import spn_compiler.backend.software.ast.nodes.reference.ASTReference | ||
import spn_compiler.backend.software.ast.nodes.types.{ASTType, ArrayType} | ||
import spn_compiler.backend.software.ast.nodes.value.ASTValue | ||
|
||
class CPPAddressOfOperator private[ast](val ref : ASTReference) extends ASTValue { | ||
override def getType: ASTType = ArrayType(ref.getType) | ||
} | ||
|
||
object CPPAddressOfOperator { | ||
|
||
def unapply(arg: CPPAddressOfOperator): Option[ASTReference] = Some(arg.ref) | ||
|
||
} |
13 changes: 13 additions & 0 deletions
13
...main/scala/spn_compiler/backend/software/ast/extensions/cpp/value/CPPSizeOfOperator.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package spn_compiler.backend.software.ast.extensions.cpp.value | ||
|
||
import spn_compiler.backend.software.ast.nodes.reference.ASTReference | ||
import spn_compiler.backend.software.ast.nodes.types.{ASTType, IntegerType} | ||
import spn_compiler.backend.software.ast.nodes.value.ASTValue | ||
|
||
class CPPSizeOfOperator private[ast](val ref : ASTReference) extends ASTValue { | ||
override def getType: ASTType = IntegerType | ||
} | ||
|
||
object CPPSizeOfOperator { | ||
def unapply(arg: CPPSizeOfOperator): Option[ASTReference] = Some(arg.ref) | ||
} |
38 changes: 38 additions & 0 deletions
38
src/main/scala/spn_compiler/backend/software/ast/extensions/cuda/CUDAASTBuilder.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package spn_compiler.backend.software.ast.extensions.cuda | ||
|
||
import spn_compiler.backend.software.ast.construct.ASTBuilder | ||
import spn_compiler.backend.software.ast.extensions.cuda.function.CUDAFunction | ||
import spn_compiler.backend.software.ast.extensions.cuda.function.CUDAFunction.CUDAFunctionScope | ||
import spn_compiler.backend.software.ast.extensions.cuda.statement.{CUDADim3Init, CUDAKernelInvocation} | ||
import spn_compiler.backend.software.ast.nodes.function.ASTFunctionParameter | ||
import spn_compiler.backend.software.ast.nodes.types.{ASTType, IntegerType} | ||
import spn_compiler.backend.software.ast.nodes.value.ASTValue | ||
import spn_compiler.backend.software.ast.nodes.value.constant.ASTConstant | ||
import spn_compiler.backend.software.ast.nodes.variable.ASTVariable | ||
|
||
trait CUDAASTBuilder extends ASTBuilder { | ||
|
||
def dim3(variable : ASTVariable, | ||
x : ASTValue = new ASTConstant(IntegerType, 1), | ||
y : ASTValue = new ASTConstant(IntegerType, 1), | ||
z : ASTValue = new ASTConstant(IntegerType, 1)) : CUDADim3Init = | ||
new CUDADim3Init(variable, x, y, z) | ||
|
||
def invokeKernel(gridLayout : ASTValue, blockLayout : ASTValue, kernel : CUDAFunction, | ||
params : ASTValue*) : CUDAKernelInvocation = | ||
new CUDAKernelInvocation(gridLayout, blockLayout, kernel, params:_*) | ||
|
||
/** | ||
* Define a local (i.e. defined in this module) function. | ||
* @param name Name of the function. | ||
* @param returnType Return type of the function. | ||
* @param parameters [[ASTFunctionParameter]]s as formal parameters of the function. | ||
* @return [[CUDAFunction]] with given name, return type and formal parameters. | ||
*/ | ||
def defineLocalCUDAFunction(scope : CUDAFunctionScope, name : String, returnType : ASTType, | ||
parameters : ASTFunctionParameter*) : CUDAFunction = { | ||
val func = new CUDAFunction(scope, name, returnType, parameters:_*) | ||
localFunctions += func | ||
func | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
src/main/scala/spn_compiler/backend/software/ast/extensions/cuda/CUDAModule.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package spn_compiler.backend.software.ast.extensions.cuda | ||
|
||
import spn_compiler.backend.software.ast.nodes.function.ASTFunction | ||
import spn_compiler.backend.software.ast.nodes.module.ASTModule | ||
import spn_compiler.backend.software.ast.nodes.statement.variable.ASTVariableDeclaration | ||
import spn_compiler.backend.software.ast.nodes.types.StructType | ||
|
||
class CUDAModule(name : String) extends ASTModule(name) with CUDAASTBuilder | ||
|
||
object CUDAModule { | ||
def unapply(arg: CUDAModule): Option[(String, List[StructType], List[ASTVariableDeclaration], List[ASTFunction])] = | ||
Some(arg.name, arg.structTypes.toList, arg.globalVariables.toList, arg.localFunctions.toList) | ||
} |
20 changes: 20 additions & 0 deletions
20
src/main/scala/spn_compiler/backend/software/ast/extensions/cuda/function/CUDAFunction.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package spn_compiler.backend.software.ast.extensions.cuda.function | ||
|
||
import spn_compiler.backend.software.ast.extensions.cuda.function.CUDAFunction.CUDAFunctionScope | ||
import spn_compiler.backend.software.ast.nodes.function.{ASTFunction, ASTFunctionParameter} | ||
import spn_compiler.backend.software.ast.nodes.types.ASTType | ||
|
||
class CUDAFunction private[ast](val scope : CUDAFunctionScope, name : String, returnType : ASTType, | ||
params : ASTFunctionParameter*) extends ASTFunction(name, returnType, params:_*) | ||
|
||
object CUDAFunction { | ||
|
||
sealed abstract class CUDAFunctionScope(val prefix : String) | ||
case object Host extends CUDAFunctionScope("__host__") | ||
case object Global extends CUDAFunctionScope("__global__") | ||
case object Device extends CUDAFunctionScope("__device__") | ||
|
||
def unapplySeq(func : CUDAFunction) : Option[(CUDAFunctionScope, String, ASTType, Seq[ASTFunctionParameter])] = | ||
Some(func.scope, func.name, func.returnType, func.getParameters.seq) | ||
|
||
} |
57 changes: 57 additions & 0 deletions
57
src/main/scala/spn_compiler/backend/software/ast/extensions/cuda/predef/CUDAPredef.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package spn_compiler.backend.software.ast.extensions.cuda.predef | ||
|
||
import spn_compiler.backend.software.ast.extensions.cuda.predef.CUDAMemCpyKind.{Device2Device, Device2Host, Host2Device, Host2Host} | ||
import spn_compiler.backend.software.ast.nodes.function.ASTExternalFunction | ||
import spn_compiler.backend.software.ast.nodes.types._ | ||
import spn_compiler.backend.software.ast.nodes.value.constant.ASTConstant | ||
import spn_compiler.backend.software.ast.nodes.variable.ASTVariable | ||
|
||
case object CUDADim3Type extends StructType("dim3", List(("x", IntegerType), ("y", IntegerType), ("z", IntegerType))) | ||
|
||
case object CUDAGridDim extends ASTVariable(CUDADim3Type, "gridDim") | ||
|
||
case object CUDAGridID extends ASTVariable(CUDADim3Type, "gridIdx") | ||
|
||
case object CUDABlockDim extends ASTVariable(CUDADim3Type, "blockDim") | ||
|
||
case object CUDABlockID extends ASTVariable(CUDADim3Type, "blockIdx") | ||
|
||
case object CUDAThreadID extends ASTVariable(CUDADim3Type, "threadIdx") | ||
|
||
|
||
|
||
object CUDAMemCpyKind { | ||
sealed trait CUDACopyDirection extends EnumBaseType | ||
case object Host2Host extends CUDACopyDirection { | ||
override def toString: String = "cudaMemcpyHostToHost" | ||
} | ||
case object Host2Device extends CUDACopyDirection { | ||
override def toString: String = "cudaMemcpyHostToDevice" | ||
} | ||
|
||
case object Device2Host extends CUDACopyDirection { | ||
override def toString: String = "cudaMemcpyDeviceToHost" | ||
} | ||
case object Device2Device extends CUDACopyDirection { | ||
override def toString: String = "cudaMemcpyDeviceToDevice" | ||
} | ||
val enumType = new EnumType[CUDACopyDirection](Host2Host, Host2Device, Device2Host, Device2Device) | ||
} | ||
|
||
sealed abstract class CUDAMemCpyKind(val kind : CUDAMemCpyKind.CUDACopyDirection) | ||
extends ASTConstant(CUDAMemCpyKind.enumType, kind) | ||
case object CUDAMemCpyHostToHost extends CUDAMemCpyKind(Host2Host) | ||
case object CUDAMemCpyHostToDevice extends CUDAMemCpyKind(Host2Device) | ||
case object CUDAMemCpyDeviceToHost extends CUDAMemCpyKind(Device2Host) | ||
case object CUDAMemCpyDeviceToDevice extends CUDAMemCpyKind(Device2Device) | ||
|
||
case object CUDAMemCpy extends ASTExternalFunction("cuda.h", "cudaMemcpy", | ||
IntegerType, ArrayType(VoidType), ArrayType(VoidType), IntegerType, CUDAMemCpyKind.enumType) | ||
|
||
case object CUDAMalloc extends ASTExternalFunction("cuda.h", "cudaMalloc", IntegerType, | ||
ArrayType(ArrayType(VoidType)), IntegerType) | ||
|
||
case object CUDAFree extends ASTExternalFunction("cuda.h", "cudaFree", IntegerType, | ||
ArrayType(VoidType)) | ||
|
||
|
Oops, something went wrong.