Skip to content
Snippets Groups Projects
Commit ea58be46 authored by Richard Angersbach's avatar Richard Angersbach Committed by Richard Angersbach
Browse files

Encapsulate cuda device count and property getters and add corresponding IVs

(cherry picked from commit a1ded09b)
parent 146b0ea2
Branches
No related tags found
No related merge requests found
......@@ -33,22 +33,12 @@ object CUDA_AddGlobals extends NoTraversalStrategy("Extend globals for CUDA") {
val initFunc = globals.functions.find(_.name == "initGlobals").get.asInstanceOf[IR_Function]
initFunc.body ++= ListBuffer[IR_Statement](
IR_VariableDeclaration(IR_IntegerDatatype, "deviceCount", 0),
"cudaGetDeviceCount(&deviceCount)",
IR_Assert(IR_Lower(Knowledge.cuda_deviceId, "deviceCount"),
ListBuffer("\"Invalid device id (\"", Knowledge.cuda_deviceId, "\") must be smaller than the number of devices (\"", "deviceCount", "\")\""),
IR_FunctionCall(IR_ExternalFunctionReference("exit"), 1)),
s"cudaSetDevice(${ Knowledge.cuda_deviceId })"
)
// get device count
initFunc.body ++= CUDA_DeviceCount.setup()
// print device info (name)
if (!Knowledge.testing_enabled) {
initFunc.body ++= ListBuffer[IR_Statement](
"cudaDeviceProp devProp",
s"cudaGetDeviceProperties(&devProp, ${ Knowledge.cuda_deviceId })",
IR_RawPrint("\"Using CUDA device \"", Knowledge.cuda_deviceId, "\": \"", "devProp.name", "std::endl"))
}
if (!Knowledge.testing_enabled)
initFunc.body ++= CUDA_DeviceProperties.setup()
// set L1 cache and shared memory configuration for this device
if (Knowledge.cuda_useSharedMemory)
......
package exastencils.parallelization.api.cuda
import scala.collection.mutable.ListBuffer
import exastencils.base.ir._
import exastencils.base.ir.IR_ImplicitConversion._
import exastencils.baseExt.ir.IR_UnduplicatedVariable
import exastencils.config.Knowledge
import exastencils.util.ir.IR_RawPrint
object CUDA_DeviceCount {
def setup() : ListBuffer[IR_Statement] = {
val deviceCount = CUDA_DeviceCount()
ListBuffer[IR_Statement](
IR_FunctionCall(IR_ExternalFunctionReference("cudaGetDeviceCount"), IR_AddressOf(deviceCount)),
IR_Assert(IR_Lower(Knowledge.cuda_deviceId, deviceCount),
ListBuffer("\"Invalid device id (\"", Knowledge.cuda_deviceId, "\") must be smaller than the number of devices (\"", deviceCount, "\")\""),
IR_FunctionCall(IR_ExternalFunctionReference("exit"), 1)),
s"cudaSetDevice(${ Knowledge.cuda_deviceId })"
)
}
}
case class CUDA_DeviceCount() extends IR_UnduplicatedVariable {
override def resolveName() : String = "deviceCount"
override def resolveDatatype() : IR_Datatype = IR_IntegerDatatype
override def resolveDefValue() : Option[IR_Expression] = Some(IR_IntegerConstant(-1))
}
object CUDA_DeviceProperties {
def setup() : ListBuffer[IR_Statement] = {
val deviceProp = CUDA_DeviceProperties()
val acc = IR_VariableAccess(deviceProp.resolveName(), deviceProp.resolveDatatype())
ListBuffer[IR_Statement](
IR_FunctionCall(IR_ExternalFunctionReference("cudaGetDeviceProperties"), IR_AddressOf(deviceProp), s"${ Knowledge.cuda_deviceId }"),
IR_RawPrint("\"Using CUDA device \"", Knowledge.cuda_deviceId, "\": \"", IR_MemberAccess(acc, "name"), "std::endl"))
}
}
case class CUDA_DeviceProperties() extends IR_UnduplicatedVariable {
override def resolveName() : String = "devProp"
override def resolveDatatype() : IR_Datatype = IR_SpecialDatatype("cudaDeviceProp")
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment