Exemple #1
0
// Get a single value
func (b *Array) Get(comp, x, y, z int) float64 {
	b.checkBounds(comp, x, y, z)
	var value float64
	acomp := b.Comp[comp]
	index := acomp.indexOf(x, y, z)
	cu.MemcpyDtoH(cu.HostPtr(unsafe.Pointer(&value)),
		cu.DevicePtr(offset(uintptr(acomp.pointer), SIZEOF_FLOAT*index)),
		1*SIZEOF_FLOAT)
	return value
}
Exemple #2
0
// Copy from device array to host array.
func (src *Array) CopyToHost(dst *host.Array) {
	CheckSize(dst.Size4D, src.size4D)

	partPlaneN := src.partSize[1] * src.partSize[2]    // floats per YZ plane per GPU
	planeN := src.size3D[1] * src.size3D[2]            // total floats per YZ plane
	NPlane := src.size4D[0] * src.size3D[0]            // total YZ planes (NComp * X size)
	partPlaneBytes := SIZEOF_FLOAT * int64(partPlaneN) // bytes per YZ plane per GPU

	for i := 0; i < NPlane; i++ {
		srcOffset := i * partPlaneN
		srcPtr := ArrayOffset(uintptr(src.pointer), srcOffset)

		dstOffset := i * planeN

		cu.MemcpyDtoH(cu.HostPtr(&dst.List[dstOffset]), cu.DevicePtr(srcPtr), partPlaneBytes)
	}

}