Skip to content
Merged
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
25 changes: 24 additions & 1 deletion OpenCL/src/main/scala/com/thoughtworks/compute/OpenCL.scala
Original file line number Diff line number Diff line change
Expand Up @@ -929,7 +929,7 @@ object OpenCL {
checkBuildErrorCode(None, clBuildProgram(handle, null, options, null, NULL))
}

def build(): Unit = build("")
def build()(implicit witness: Witness.Aux[Owner]): Unit = build(witness.value.defaultProgramOptions)

def monadicClose = UnitContinuation.delay {
OpenCL.checkErrorCode(clReleaseProgram(handle))
Expand Down Expand Up @@ -1113,11 +1113,34 @@ object OpenCL {
}
}

/** A plug-in of Tensors to suppress warnings during compiling a OpenCL kernel for non-AMD platforms. */
trait SuppressWarnings extends OpenCL {
@transient
private lazy val _defaultProgramOptions = {
if (platformCapabilities.cl_amd_compile_options) {
// AMD SDK does not support -w flag in OpenCL specification.
super.defaultProgramOptions
} else {
super.defaultProgramOptions + " -w"
}
}

override protected def defaultProgramOptions: CharSequence = _defaultProgramOptions
}

trait UnsafeMathOptimizations extends OpenCL {
private lazy val _defaultProgramOptions = super.defaultProgramOptions + " -cl-unsafe-math-optimizations"

abstract override protected def defaultProgramOptions: CharSequence = _defaultProgramOptions
}

}

trait OpenCL extends MonadicCloseable[UnitContinuation] with DefaultCloseable {
import OpenCL._

protected def defaultProgramOptions: CharSequence = ""

protected def createKernels(program: Program): Seq[Kernel] = {
val stack = stackPush()
try {
Expand Down
34 changes: 6 additions & 28 deletions Tensors/src/main/scala/com/thoughtworks/compute/Tensors.scala
Original file line number Diff line number Diff line change
Expand Up @@ -41,26 +41,6 @@ object Tensors {

private final val MaxWorkItemDimensions = 3

/** A plug-in of Tensors to suppress warnings during compiling a OpenCL kernel for non-AMD platforms. */
trait SuppressWarnings extends Tensors {
@transient
private lazy val _openclCompilerFlags = {
if (platformCapabilities.cl_amd_compile_options) {
// AMD SDK does not support -w flag in OpenCL specification.
super.openclCompilerFlags
} else {
super.openclCompilerFlags + " -w"
}
}

override protected def openclCompilerFlags: String = _openclCompilerFlags
}

trait UnsafeMathOptimizations extends Tensors {
private lazy val _openclCompilerFlags = super.openclCompilerFlags + " -cl-unsafe-math-optimizations"
override protected def openclCompilerFlags: String = _openclCompilerFlags
}

trait TensorBuilder[Data] {
type Element
def flatten(a: Data): Seq[Element]
Expand Down Expand Up @@ -320,8 +300,6 @@ trait Tensors extends OpenCL {

protected def hashSourceCode: Fastring

protected def openclCompilerFlags: String = ""

protected object PlusPrograms extends MonoidPrograms {
def append(leftHandSide: Fastring, rightHandSide: Fastring): Fastring = fast"(($leftHandSide) + ($rightHandSide))"
def zero: Fastring = fast"0.0f"
Expand Down Expand Up @@ -368,7 +346,7 @@ trait Tensors extends OpenCL {
}
}
""")
program.build(openclCompilerFlags)
program.build()
program
}

Expand Down Expand Up @@ -409,7 +387,7 @@ trait Tensors extends OpenCL {
}
}
""")
program.build(openclCompilerFlags)
program.build()
program
}
}
Expand Down Expand Up @@ -446,7 +424,7 @@ trait Tensors extends OpenCL {
buffer[i * 2 + 1] = z1;
}
""")
program.build(openclCompilerFlags)
program.build()
program
}

Expand All @@ -460,7 +438,7 @@ trait Tensors extends OpenCL {
buffer[i] = hash(i ^ seed) / 4294967296.0f;
}
""")
program.build(openclCompilerFlags)
program.build()
program
}

Expand Down Expand Up @@ -1049,7 +1027,7 @@ trait Tensors extends OpenCL {
/**
* @group delayed
*/
def transpose: TransformedTensor = { permute(shape.indices.reverse.toArray)}
def transpose: TransformedTensor = { permute(shape.indices.reverse.toArray) }

/**
* @group delayed
Expand Down Expand Up @@ -1216,7 +1194,7 @@ trait Tensors extends OpenCL {
}

val program = createProgramWithSource(sourceCode)
program.build(openclCompilerFlags)
program.build()

val compiledKernel = new CompiledKernel {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ object benchmarks {

trait BenchmarkTensors
extends StrictLogging
with Tensors.UnsafeMathOptimizations
with Tensors.SuppressWarnings
with OpenCL.UnsafeMathOptimizations
with OpenCL.SuppressWarnings
with OpenCL.LogContextNotification
with OpenCL.UseAllDevicesByType
with OpenCL.GlobalExecutionContext
Expand Down
2 changes: 1 addition & 1 deletion cpu/src/main/scala/com/thoughtworks/compute/cpu.scala
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ import org.lwjgl.opencl.CL10.CL_DEVICE_TYPE_CPU
*/
object cpu
extends StrictLogging
with Tensors.UnsafeMathOptimizations
with OpenCL.UnsafeMathOptimizations
with OpenCL.LogContextNotification
with OpenCL.GlobalExecutionContext
with OpenCL.CommandQueuePool
Expand Down
2 changes: 1 addition & 1 deletion gpu/src/main/scala/com/thoughtworks/compute/gpu.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import com.typesafe.scalalogging.StrictLogging
*/
object gpu
extends StrictLogging
with Tensors.UnsafeMathOptimizations
with OpenCL.UnsafeMathOptimizations
with OpenCL.LogContextNotification
with OpenCL.GlobalExecutionContext
with OpenCL.CommandQueuePool
Expand Down