Exemplo n.º 1
0
func deviceGetByPCIBusId(busid string) (handle, error) {
	var dev C.int

	id := C.CString(busid)
	r := C.cudaDeviceGetByPCIBusId(&dev, id)
	C.free(unsafe.Pointer(id))
	return handle{dev}, errorString(r)
}
Exemplo n.º 2
0
func NewDevice(busID string) (*Device, error) {
	var (
		dev  C.int
		prop C.struct_cudaDeviceProp
	)

	id := C.CString(busID)
	if err := cudaErr(C.cudaDeviceGetByPCIBusId(&dev, id)); err != nil {
		return nil, err
	}
	C.free(unsafe.Pointer(id))

	if err := cudaErr(C.cudaGetDeviceProperties(&prop, dev)); err != nil {
		return nil, err
	}
	arch := fmt.Sprintf("%d.%d", prop.major, prop.minor)
	cores, ok := archToCoresPerSM[arch]
	if !ok {
		return nil, fmt.Errorf("unsupported CUDA arch: %s", arch)
	}

	// Destroy the active CUDA context
	cudaErr(C.cudaDeviceReset())

	return &Device{
		handle: dev,
		Family: archToFamily[arch[:1]],
		Arch:   arch,
		Cores:  cores * uint(prop.multiProcessorCount),
		Memory: MemoryInfo{
			ECC:       bool(prop.ECCEnabled != 0),
			Global:    uint(prop.totalGlobalMem / (1024 * 1024)),
			Shared:    uint(prop.sharedMemPerMultiprocessor / 1024),
			Constant:  uint(prop.totalConstMem / 1024),
			L2Cache:   uint(prop.l2CacheSize / 1024),
			Bandwidth: 2 * uint((prop.memoryClockRate/1000)*(prop.memoryBusWidth/8)) / 1000,
		},
	}, nil
}