コード例 #1
0
ファイル: main.go プロジェクト: klickverbot/DigitalWhip
func main() {
	// prepare input data
	fileName := path.Join(os.Args[1], "normals.txt")
	normals := ReadNormals(fileName)

	// run benchmark
	start := time.Now()
	vector := Vector{1, 0, 0}
	const count = 1024 * 1024 * 100

	for i := 0; i < count; i++ {
		vector = ReflectVector(vector, normals[i%len(normals)])
		vector = RefractVector(vector, normals[(i+1)%len(normals)])
	}

	// communicate time to master
	elapsedTime := int(time.Since(start) / time.Millisecond)
	timingStorage := path.Join(filepath.Dir(os.Args[0]), "timing")
	common.StoreBenchmarkTiming(timingStorage, elapsedTime)

	// validation
	if len(normals) != 1024*1024 {
		common.ValidationError("invalid size of normals array")
	}
	if !VIsEqual(vector, Vector{-0.2653, -0.1665, -0.9497}, 1e-3) {
		common.ValidationError("invalid final vector value")
	}
}
コード例 #2
0
ファイル: main.go プロジェクト: klickverbot/DigitalWhip
func main() {
	// prepare input data
	fileName := path.Join(os.Args[1], "random_numbers")
	array := ReadNumbersFromFile(fileName)

	// run benchmark
	start := time.Now()
	QuickSort(array)

	// communicate time to master
	elapsedTime := int(time.Since(start) / time.Millisecond)
	timingStorage := path.Join(filepath.Dir(os.Args[0]), "timing")
	common.StoreBenchmarkTiming(timingStorage, elapsedTime)

	// validation
	if len(array) != 4000000 {
		common.ValidationError("invalid size")
	}
	prevValue := array[0]
	for _, value := range array[1:] {
		if prevValue > value {
			common.ValidationError("array is not sorted")
		}
		prevValue = value
	}
}
コード例 #3
0
ファイル: benchmark.go プロジェクト: klickverbot/DigitalWhip
func ValidateKdTree(kdTree *KdTree, raysCount int) {
	lastHit := VMul64(VAdd64(kdTree.meshBounds.minPoint, kdTree.meshBounds.maxPoint), 0.5)
	lastHitEpsilon := 0.0

	rg := newRayGenerator(kdTree.meshBounds)

	for raysTested := 0; raysTested < raysCount; raysTested++ {
		ray := rg.generateRay(lastHit, lastHitEpsilon)

		kdTreeHitFound, kdTreeIntersection := kdTree.Intersect(&ray)

		bruteForceIntersection := KdTreeIntersection{t: math.Inf(+1)}
		bruteForceHitFound := false

		for i := int32(0); i < kdTree.mesh.GetTrianglesCount(); i++ {
			indices := kdTree.mesh.triangles[i]

			triangle := Triangle{[3]Vector64{
				NewVector64FromVector32(kdTree.mesh.vertices[indices[0]]),
				NewVector64FromVector32(kdTree.mesh.vertices[indices[1]]),
				NewVector64FromVector32(kdTree.mesh.vertices[indices[2]]),
			}}

			hitFound, intersection := IntersectTriangle(&ray, &triangle)

			if hitFound && intersection.t < bruteForceIntersection.t {
				bruteForceIntersection.t = intersection.t
				bruteForceHitFound = true
			}
		}

		if kdTreeHitFound != bruteForceHitFound ||
			kdTreeIntersection.t != bruteForceIntersection.t {
			o := ray.origin
			d := ray.direction
			fmt.Printf("KdTree accelerator test failure:\n"+
				"KdTree hit: %v\n"+
				"actual hit: %v\n"+
				"KdTree T %.16g [%b]\n"+
				"actual T %.16g [%b]\n"+
				"ray origin: (%b, %b, %b)\n"+
				"ray direction: (%b, %b, %b)\n",
				kdTreeHitFound, bruteForceHitFound,
				kdTreeIntersection.t, kdTreeIntersection.t,
				bruteForceIntersection.t, bruteForceIntersection.t,
				o[0], o[1], o[2], d[0], d[1], d[2])
			common.ValidationError("kdTree traversal error detected")
		}

		if bruteForceHitFound {
			lastHit = ray.GetPoint(bruteForceIntersection.t)
			lastHitEpsilon = bruteForceIntersection.epsilon
		}
	}
}