コード例 #1
0
ファイル: perf_chol.go プロジェクト: hrautila/matops
func main() {
	flag.Parse()
	runtime.GOMAXPROCS(nWorker)
	matops.NumWorkers(nWorker)
	rand.Seed(time.Now().UnixNano())
	matops.BlockingParams(MB, NB, VPsize)

	uplo := matrix.Lower
	if testUpper {
		uplo = matrix.Upper
	}
	_ = uplo

	var ok bool
	var reftm, tm time.Duration

	if singleTest {
		A := newMatrix(N)
		Ac := A.Copy()

		if check {
			ok, tm, reftm = runCheck(A, KB)
			if verbose {
				fmt.Fprintf(os.Stderr, "%s: %v\n", testName, tm)
				fmt.Fprintf(os.Stderr, "Reference: [%v] %v (%.2f) \n",
					ok, reftm, tm.Seconds()/reftm.Seconds())
				if !ok {
					fmt.Fprintf(os.Stderr, "ERRlapack: %v\n", ERRlapack)
					fmt.Fprintf(os.Stderr, "ERRmatops: %v\n", ERRmatops)
				}
			}
			if asGflops {
				fmt.Printf("%.4f Gflops [ref: %.4f]\n",
					gFlops(N, tm.Seconds()), gFlops(N, reftm.Seconds()))
			}
			if !ok {
				//fmt.Printf("A orig:\n%v\n", Ac)
				saveData(Ac)
			}
			return
		}

		if refTest {
			tm = runRefTest(A, testCount, KB)
		} else {
			tm = runTest(A, testCount, KB)
		}

		if asGflops {
			fmt.Printf("%.4f Gflops\n", gFlops(N, tm.Seconds()))
		} else {
			fmt.Printf("%vs\n", tm.Seconds())
		}
		return
	}

	if len(sizeList) > 0 {
		sizes = parseSizeList(sizeList)
	}
	var times map[int]float64

	if refTest {
		times = runTestsForSizes(runRefTest, sizes)
	} else {
		times = runTestsForSizes(runTest, sizes)
	}
	if asGflops {
		if verbose {
			fmt.Printf("calculating Gflops ...\n")
		}
		for sz := range times {
			times[sz] = gFlops(sz, times[sz])
		}
	}
	// print out as python dictionary
	fmt.Printf("{")
	i := 0
	for sz := range times {
		if i > 0 {
			fmt.Printf(", ")
		}
		fmt.Printf("%d: %v", sz, times[sz])
		i++
	}
	fmt.Printf("}\n")
}
コード例 #2
0
ファイル: mmperf.go プロジェクト: hrautila/matops
func main() {
	flag.Parse()
	runtime.GOMAXPROCS(nWorker)
	matops.NumWorkers(nWorker)
	rand.Seed(time.Now().UnixNano())
	matops.BlockingParams(MB, NB, VPsize)

	testFunc, ok := tests[testName]
	if !ok {
		fmt.Printf("Error: test %s does not exists.\nKnown tests:\n", testName)
		for tname := range tests {
			fmt.Printf("\t%s\n", tname)
		}
		return
	}
	var checkFunc mperf.MatrixCheckFunc
	if transpose[0] == 'B' {
		checkFunc = CheckTransB
	} else if len(transpose) == 1 && transpose[0] == 'A' {
		checkFunc = CheckTransA
	} else if len(transpose) > 1 {
		checkFunc = CheckTransAB
	} else {
		checkFunc = CheckNoTrans
	}

	if singleTest {
		fnc, A, B, C0 := testFunc(M, N, P)
		mperf.FlushCache()
		tm := mperf.Timeit(fnc)
		if check {
			reftime, ok := mperf.CheckWithFunc(A, B, C0, checkFunc)
			if verbose {
				fmt.Fprintf(os.Stderr, "%s: %v\n", testName, tm)
				fmt.Fprintf(os.Stderr, "Reference: [%v] %v (%.2f) \n",
					ok, reftime, tm.Seconds()/reftime.Seconds())
			}
		}
		//sec, _ := mperf.SingleTest(testName, testFunc, M, N, P, check, verbose)
		if asGflops {
			gflops := 2.0 * float64(int64(M)*int64(N)*int64(P)) / tm.Seconds() * 1e-9
			fmt.Printf("%.4f Gflops\n", gflops)
		} else if asEps {
			eps := float64(int64(M)*int64(N)) / tm.Seconds()
			fmt.Printf("%.4f Eps\n", eps)
		} else {
			fmt.Printf("%vs\n", tm.Seconds())
		}
		return
	}

	if len(sizeList) > 0 {
		sizes = parseSizeList(sizeList)
	}
	times := mperf.MultipleSizeTests(testFunc, sizes, testCount, verbose)
	if asGflops || asEps {
		if verbose {
			fmt.Printf("calculating Gflops ...\n")
		}
		for sz := range times {
			n := int64(sz)
			if asGflops {
				times[sz] = 2.0 * float64(n*n*n) / times[sz] * 1e-9
			} else {
				times[sz] = float64(n*n) / times[sz]
			}
		}
	}
	// print out as python dictionary
	fmt.Printf("{")
	i := 0
	for sz := range times {
		if i > 0 {
			fmt.Printf(", ")
		}
		fmt.Printf("%d: %v", sz, times[sz])
		i++
	}
	fmt.Printf("}\n")
}