forked from feiwang3311/Lantern
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Let
BackendCudnn
extend BackendCublas
.
Rationale here: feiwang3311#8 (comment) - Move GPU test utilities to `LanternFunSuite`. - Improve CUDA/cuBLAS/cuDNN error messages. - Example: "cuBLAS error occurred: 7 (lantern-snippet.cpp:150)" - Add cuDNN test.
- Loading branch information
Showing
5 changed files
with
104 additions
and
51 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,24 @@ | ||
package lantern | ||
|
||
import org.scalatest.FunSuite | ||
import org.scalactic.source | ||
import org.scalatest.{FunSuite, Tag} | ||
|
||
class LanternFunSuite extends FunSuite { | ||
def runTest(driver: LanternDriver[String, Unit]) { | ||
driver.eval("dummy") | ||
} | ||
|
||
// TODO: Edit this function to actually detect whether GPU codegen is possible. | ||
// One idea: check for: | ||
// - The existence of cuBLAS header files (<cuda_runtime.h>, <cublas_v2.h>). | ||
// - The existence of a GPU (perhaps run `nvidia-smi`). | ||
def isGPUAvailable = false | ||
|
||
// Utility function wrapping `test` that checks whether GPU is available. | ||
def testGPU(testName: String, testTags: Tag*)(testFun: => Any /* Assertion */)(implicit pos: source.Position) { | ||
if (isGPUAvailable) | ||
test(testName, testTags: _*)(testFun)(pos) | ||
else | ||
ignore(testName, testTags: _*)(testFun)(pos) | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package lantern | ||
|
||
import org.scala_lang.virtualized.virtualize | ||
import org.scala_lang.virtualized.SourceContext | ||
|
||
import scala.collection.{Seq => NSeq} | ||
|
||
class TestCudnn extends LanternFunSuite { | ||
testGPU("vector-vector-dot") { | ||
val vvdot = new LanternDriverCudnn[String, Unit] { | ||
backend = new BackendCudnn | ||
|
||
@virtualize | ||
def snippet(x: Rep[String]): Rep[Unit] = { | ||
val length = 2 | ||
val v1 = Tensor.fromData(NSeq(4), 1, 2, 3, 4) | ||
val v2 = Tensor.fromData(NSeq(4), -1, -2, -3, -4) | ||
val expected = Tensor.fromData(NSeq(1), -30) | ||
Tensor.assertEqual(v1.dot(v2), expected) | ||
} | ||
} | ||
runTest(vvdot) | ||
} | ||
|
||
testGPU("matrix-vector-dot") { | ||
val mvdot = new LanternDriverCudnn[String, Unit] { | ||
backend = new BackendCudnn | ||
|
||
@virtualize | ||
def snippet(x: Rep[String]): Rep[Unit] = { | ||
val m = Tensor.fromData(NSeq(2, 4), 1, 2, 3, 4, 5, 6, 7, 8) | ||
val v = Tensor.fromData(NSeq(4), -1, -2, -3, -4) | ||
val expected = Tensor.fromData(NSeq(2), -30, -70) | ||
Tensor.assertEqual(m.dot(v), expected) | ||
} | ||
} | ||
runTest(mvdot) | ||
} | ||
|
||
testGPU("matrix-matrix-dot") { | ||
val mmdot = new LanternDriverCudnn[String, Unit] { | ||
backend = new BackendCudnn | ||
|
||
@virtualize | ||
def snippet(x: Rep[String]): Rep[Unit] = { | ||
// Note: it's better to test with non-square matrices. | ||
val m1 = Tensor.fromData(NSeq(2, 3), 1, 2, 3, 4, 5, 6) | ||
val m2 = Tensor.fromData(NSeq(3, 2), 2, 3, 4, 5, 6, 7) | ||
val expected = Tensor.fromData(NSeq(2, 2), 28, 34, 64, 79) | ||
Tensor.assertEqual(m1.dot(m2), expected) | ||
} | ||
} | ||
runTest(mmdot) | ||
} | ||
} |