Skip to content

Commit

Permalink
-paranoid flag enables convolution self-test
Browse files Browse the repository at this point in the history
  • Loading branch information
barnex committed Nov 7, 2015
1 parent 57f2d99 commit e0c3a28
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 9 deletions.
3 changes: 3 additions & 0 deletions cmd/mumax3/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ var (
flag_memprof = flag.Bool("memprof", false, "Recored gopprof memory profile")
flag_od = flag.String("o", "", "Override output directory")
flag_port = flag.String("http", ":35367", "Port to serve web gui")
flag_selftest = flag.Bool("paranoid", false, "Enable convolution self-test for cuFFT sanity.")
flag_silent = flag.Bool("s", false, "Silent") // provided for backwards compatibility
flag_sync = flag.Bool("sync", false, "Synchronize all CUDA calls (debug)")
flag_test = flag.Bool("test", false, "Cuda test (internal)")
Expand All @@ -51,6 +52,8 @@ func main() {
cuda.Synchronous = true
}

engine.TestDemag = *flag_selftest

// used by bootstrap launcher to test cuda
// successful exit means cuda was initialized fine
if *flag_test {
Expand Down
7 changes: 5 additions & 2 deletions cuda/conv_demag.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,15 @@ type DemagConvolution struct {
}

// Initializes a convolution to evaluate the demag field for the given mesh geometry.
func NewDemag(inputSize, PBC [3]int, kernel [3][3]*data.Slice) *DemagConvolution {
// Sanity-checked if test == true (slow-ish for large meshes).
func NewDemag(inputSize, PBC [3]int, kernel [3][3]*data.Slice, test bool) *DemagConvolution {
c := new(DemagConvolution)
c.inputSize = inputSize
c.realKernSize = kernel[X][X].Size()
c.init(kernel)
testConvolution(c, PBC, kernel)
if test {
testConvolution(c, PBC, kernel)
}
return c
}

Expand Down
9 changes: 4 additions & 5 deletions cuda/conv_selftest.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,12 @@ import (
// Compares FFT-accelerated convolution against brute-force on sparse data.
// This is not really needed but very quickly uncovers newly introduced bugs.
func testConvolution(c *DemagConvolution, PBC [3]int, realKern [3][3]*data.Slice) {
if PBC != [3]int{0, 0, 0} || prod(c.inputSize) > 512*512 {
// the brute-force method does not work for pbc,
// and for large simulations it gets just too slow.
util.Log("skipping convolution self-test")
if PBC != [3]int{0, 0, 0} {
// the brute-force method does not work for pbc.
util.Log("skipping convolution self-test for PBC")
return
}
//fmt.Print("convolution test ")
util.Log("convolution self-test...")
inhost := data.NewSlice(3, c.inputSize)
initConvTestInput(inhost.Vectors())
gpu := NewSlice(3, c.inputSize)
Expand Down
3 changes: 2 additions & 1 deletion engine/demag.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ var (
conv_ *cuda.DemagConvolution // does the heavy lifting and provides FFTM
DemagAccuracy = 6.0 // Demag accuracy (divide cubes in at most N^3 points)
CacheDir = "" // directory for kernel cache
TestDemag = false // enable convolution self-test
)

func init() {
Expand Down Expand Up @@ -112,7 +113,7 @@ func demagConv() *cuda.DemagConvolution {
SetBusy(true)
defer SetBusy(false)
kernel := mag.DemagKernel(Mesh().Size(), Mesh().PBC(), Mesh().CellSize(), DemagAccuracy, CacheDir)
conv_ = cuda.NewDemag(Mesh().Size(), Mesh().PBC(), kernel)
conv_ = cuda.NewDemag(Mesh().Size(), Mesh().PBC(), kernel, TestDemag)
}
return conv_
}
Expand Down
2 changes: 1 addition & 1 deletion test/run.bash
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ scripts=*.mx3

mumax3 -vet $scripts

mumax3 -failfast -cache /tmp -f -http "" $scripts;
mumax3 -paranoid -failfast -cache /tmp -f -http "" $scripts;

for g in *.go; do
if [ "$g" != "doc.go" ]; then
Expand Down

0 comments on commit e0c3a28

Please sign in to comment.