Skip to content

Commit

Permalink
update cuda tests for -sync flag, comment out unified slice
Browse files Browse the repository at this point in the history
  • Loading branch information
barnex committed Nov 7, 2013
1 parent 7b5d1cd commit 1f3aea8
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 18 deletions.
2 changes: 1 addition & 1 deletion cuda/buffer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
)

func init() {
Init(0, "auto")
Init(0, "auto", false)
}

func TestBuffer(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion cuda/reduce_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ func initTest() {
return
}
LockThread()
Init(0, "auto")
Init(0, "auto", false)
{
inh1 := make([]float32, 1000)
for i := range inh1 {
Expand Down
15 changes: 6 additions & 9 deletions cuda/slice.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ func NewSlice(nComp int, m *data.Mesh) *data.Slice {
}

// Make a GPU Slice with nComp components each of size length.
func NewUnifiedSlice(nComp int, m *data.Mesh) *data.Slice {
return newSlice(nComp, m, cu.MemAllocHost, data.UnifiedMemory)
}
//func NewUnifiedSlice(nComp int, m *data.Mesh) *data.Slice {
// return newSlice(nComp, m, cu.MemAllocHost, data.UnifiedMemory)
//}

func newSlice(nComp int, m *data.Mesh, alloc func(int64) unsafe.Pointer, memType int8) *data.Slice {
data.EnableGPU(memFree, cu.MemFreeHost, memCpy, memCpyDtoH, memCpyHtoD)
Expand Down Expand Up @@ -47,16 +47,13 @@ func memCpyHtoD(dst, src unsafe.Pointer, bytes int64) {
}

func memCpy(dst, src unsafe.Pointer, bytes int64) {
if synchronous { // debug
Sync()
}
Sync()
cu.MemcpyAsync(cu.DevicePtr(uintptr(dst)), cu.DevicePtr(uintptr(src)), bytes, stream0)
if synchronous { // debug
Sync()
}
Sync()
}

// Memset sets the Slice's components to the specified values.
// To be carefully used on unified slice (need sync)
func Memset(s *data.Slice, val ...float32) {
if synchronous { // debug
Sync()
Expand Down
12 changes: 6 additions & 6 deletions cuda/slice_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
)

func init() {
Init(0, "auto")
Init(0, "auto", false)
}

func TestSlice(t *testing.T) {
Expand Down Expand Up @@ -93,18 +93,18 @@ func TestSliceHost(t *testing.T) {
N0, N1, N2 := 1, 10, 10
c := 1e-6
m := data.NewMesh(N0, N1, N2, c, c, c)
a := NewUnifiedSlice(3, m)
a := NewSlice(3, m)
defer a.Free()

b := a.Host()
b := a.HostCopy().Host()
if b[0][0] != 0 || b[1][42] != 0 || b[2][99] != 0 {
t.Fail()
t.Error("slice not inited to zero")
}

Memset(a, 1, 2, 3)
b = a.Host()
b = a.HostCopy().Host()
if b[0][0] != 1 || b[1][42] != 2 || b[2][99] != 3 {
t.Fail()
t.Error("slice memset")
}
}

Expand Down
1 change: 0 additions & 1 deletion data/slice.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
)

// Slice is like a [][]float32, but may be stored in GPU or host memory.
// TODO: unified memory is not used anymore, can be removed. Then we can split cuda.Slice and data.Slice?
type Slice struct {
ptr_ [MAX_COMP]unsafe.Pointer // keeps data local // TODO: rm (premature optimization)
ptrs []unsafe.Pointer // points into ptr_
Expand Down

0 comments on commit 1f3aea8

Please sign in to comment.