Skip to content

Commit

Permalink
Create cuda context once for all cuda tests
Browse files Browse the repository at this point in the history
All cuda tests succeed, even with go version 1.10 or higher.
This commit solves issue mumax#224
  • Loading branch information
JeroenMulkers committed Mar 20, 2019
1 parent 2cf5c9a commit 71b1016
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 5 deletions.
2 changes: 0 additions & 2 deletions cuda/buffer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import "testing"

// In case of memory leak, this will crash
func TestBuffer(t *testing.T) {
Init(0)
m1 := [3]int{2, 1024, 2048}
m2 := [3]int{4, 1024, 2048}
a := Buffer(3, m1)
Expand All @@ -24,7 +23,6 @@ func TestBuffer(t *testing.T) {
}

func BenchmarkBuffer(b *testing.B) {
Init(0)
b.StopTimer()
m := [3]int{2, 1024, 2048}
a := Buffer(3, m)
Expand Down
12 changes: 12 additions & 0 deletions cuda/init_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package cuda

import (
"github.com/mumax/3/cuda/cu"
)

// needed for all other tests.
func init() {
cu.Init(0)
ctx := cu.CtxCreate(cu.CTX_SCHED_AUTO, 0)
cu.CtxSetCurrent(ctx)
}
1 change: 0 additions & 1 deletion cuda/reduce_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
var in1, in2, in3 *data.Slice

func initTest() {
Init(0)
if in1 != nil {
return
}
Expand Down
2 changes: 0 additions & 2 deletions cuda/slice_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
)

func TestSlice(t *testing.T) {
Init(0)
N0, N1, N2 := 2, 4, 8
m := [3]int{N0, N1, N2}
N := N0 * N1 * N2
Expand Down Expand Up @@ -42,7 +41,6 @@ func TestSlice(t *testing.T) {
}

func TestCpy(t *testing.T) {
Init(0)
N0, N1, N2 := 2, 4, 32
N := N0 * N1 * N2
mesh := [3]int{N0, N1, N2}
Expand Down

0 comments on commit 71b1016

Please sign in to comment.