Exemplo n.º 1
0
// Returns true if CtxEnablePeerAccess can be called on a context for dev and peerDev.
func DeviceCanAccessPeer(dev, peer Device) bool {
	var canAccessPeer C.int
	err := Result(C.cuDeviceCanAccessPeer(&canAccessPeer, C.CUdevice(dev), C.CUdevice(peer)))
	if err != SUCCESS {
		panic(err)
	}
	return int(canAccessPeer) != 0
}
Exemplo n.º 2
0
// Create a CUDA context.
func CtxCreate(flags uint, dev Device) Context {
	var ctx C.CUcontext
	err := Result(C.cuCtxCreate(&ctx, C.uint(flags), C.CUdevice(dev)))
	if err != SUCCESS {
		panic(err)
	}
	return Context(uintptr(unsafe.Pointer(ctx)))
}
Exemplo n.º 3
0
// Gets the value of a device attribute.
func DeviceGetAttribute(attrib DeviceAttribute, dev Device) int {
	var attr C.int
	err := Result(C.cuDeviceGetAttribute(&attr, C.CUdevice_attribute(attrib), C.CUdevice(dev)))
	if err != SUCCESS {
		panic(err)
	}
	return int(attr)
}
Exemplo n.º 4
0
// Returns the total amount of memory available on the device in bytes.
func DeviceTotalMem(device Device) int64 {
	var bytes C.size_t
	err := Result(C.cuDeviceTotalMem(&bytes, C.CUdevice(device)))
	if err != SUCCESS {
		panic(err)
	}
	return int64(bytes)
}
Exemplo n.º 5
0
func DeviceComputeCapability(dev int) (major, minor, err int) {
	var cErr, cMajor, cMinor C.int
	cErr = C.int(C.cuDeviceComputeCapability(&cMajor, &cMinor, C.CUdevice(dev)))
	major = int(cMajor)
	minor = int(cMinor)
	err = int(cErr)
	return
}
Exemplo n.º 6
0
// Gets the name of the device.
func DeviceGetName(dev Device) string {
	size := 256
	buf := make([]byte, size)
	cstr := C.CString(string(buf))
	err := Result(C.cuDeviceGetName(cstr, C.int(size), C.CUdevice(dev)))
	if err != SUCCESS {
		panic(err)
	}
	return C.GoString(cstr)
}
Exemplo n.º 7
0
// Returns the compute capability of the device.
func DeviceComputeCapability(device Device) (major, minor int) {
	var maj, min C.int
	err := Result(C.cuDeviceComputeCapability(&maj, &min, C.CUdevice(device)))
	if err != SUCCESS {
		panic(err)
	}
	major = int(maj)
	minor = int(min)
	return
}
Exemplo n.º 8
0
// Returns the device's properties.
func DeviceGetProperties(dev Device) (prop DevProp) {
	var cprop C.CUdevprop
	err := Result(C.cuDeviceGetProperties(&cprop, C.CUdevice(dev)))
	if err != SUCCESS {
		panic(err)
	}
	prop.MaxThreadsPerBlock = int(cprop.maxThreadsPerBlock)
	prop.MaxThreadsDim[0] = int(cprop.maxThreadsDim[0])
	prop.MaxThreadsDim[1] = int(cprop.maxThreadsDim[1])
	prop.MaxThreadsDim[2] = int(cprop.maxThreadsDim[2])
	prop.MaxGridSize[0] = int(cprop.maxGridSize[0])
	prop.MaxGridSize[1] = int(cprop.maxGridSize[1])
	prop.MaxGridSize[2] = int(cprop.maxGridSize[2])
	prop.SharedMemPerBlock = int(cprop.sharedMemPerBlock)
	prop.TotalConstantMemory = int(cprop.totalConstantMemory)
	prop.SIMDWidth = int(cprop.SIMDWidth)
	prop.MemPitch = int(cprop.memPitch)
	prop.RegsPerBlock = int(cprop.regsPerBlock)
	prop.ClockRate = int(cprop.clockRate)
	prop.TextureAlign = int(cprop.textureAlign)
	return
}