func main() { var info NodeInfo // If an error occurs, send it in the NodeInfo defer func() { err := recover() if err != nil { info.ErrorString = fmt.Sprint(err) if cudaErr, ok := err.(cu.Result); ok { info.CudaError = int(cudaErr) } } // Send the info no matter what bytes, err2 := json.Marshal(info) Check(err2) _, err3 := os.Stdout.Write(bytes) fmt.Println() Check(err3) }() cu.Init(0) NDev := cu.DeviceGetCount() info.Devices = make([]DeviceInfo, NDev) for i := range info.Devices { dev := cu.DeviceGet(i) info.Devices[i].Name = dev.Name() info.Devices[i].TotalMem = dev.TotalMem() } }
// set up device properties func initGPUProperties() { dev := cu.DeviceGet(_useDevice) maxThreadsPerBlock = dev.Attribute(cu.MAX_THREADS_PER_BLOCK) maxBlockDim[0] = dev.Attribute(cu.MAX_BLOCK_DIM_X) maxBlockDim[1] = dev.Attribute(cu.MAX_BLOCK_DIM_Y) maxBlockDim[2] = dev.Attribute(cu.MAX_BLOCK_DIM_Z) maxGridDim[0] = dev.Attribute(cu.MAX_GRID_DIM_X) maxGridDim[1] = dev.Attribute(cu.MAX_GRID_DIM_Y) maxGridDim[2] = dev.Attribute(cu.MAX_GRID_DIM_Z) Debug("Max", maxThreadsPerBlock, "threads per block, max", maxGridDim, "x", maxBlockDim, "threads per GPU") }
// output device info func printGPUInfo() { dev := cu.DeviceGet(_useDevice) Log("device", "( PCI", dev.Attribute(cu.PCI_DEVICE_ID), ")", dev.Name(), ",", dev.TotalMem()/(1024*1024), "MiB") }