Example #1
0
// See [2]. We basically do the same here, but the Go OpenCL bindings
// are at a slightly higher abtraction level.
func InitCL(blockNum uint64, c *OpenCLMiner) error {
	platforms, err := cl.GetPlatforms()
	if err != nil {
		return fmt.Errorf("Plaform error: %v\nCheck your OpenCL installation and then run geth gpuinfo", err)
	}

	var devices []*cl.Device
	for _, p := range platforms {
		ds, err := cl.GetDevices(p, cl.DeviceTypeGPU)
		if err != nil {
			return fmt.Errorf("Devices error: %v\nCheck your GPU drivers and then run geth gpuinfo", err)
		}
		for _, d := range ds {
			devices = append(devices, d)
		}
	}

	pow := New()
	_ = pow.getDAG(blockNum)     // generates DAG if we don't have it
	pow.Light.getCache(blockNum) // and cache

	c.ethash = pow
	dagSize := uint64(C.ethash_get_datasize(C.uint64_t(blockNum)))
	c.dagSize = dagSize

	for _, id := range c.deviceIds {
		if id > len(devices)-1 {
			return fmt.Errorf("Device id not found. See available device ids with: geth gpuinfo")
		} else {
			err := initCLDevice(id, devices[id], c)
			if err != nil {
				return err
			}
		}
	}
	if len(c.devices) == 0 {
		return fmt.Errorf("No GPU devices found")
	}
	return nil
}
Example #2
0
func PrintDevices() {
	fmt.Println("=============================================")
	fmt.Println("============ OpenCL Device Info =============")
	fmt.Println("=============================================")

	var found []*cl.Device

	platforms, err := cl.GetPlatforms()
	if err != nil {
		fmt.Println("Plaform error (check your OpenCL installation): %v", err)
		return
	}

	for i, p := range platforms {
		fmt.Println("Platform id             ", i)
		fmt.Println("Platform Name           ", p.Name())
		fmt.Println("Platform Vendor         ", p.Vendor())
		fmt.Println("Platform Version        ", p.Version())
		fmt.Println("Platform Extensions     ", p.Extensions())
		fmt.Println("Platform Profile        ", p.Profile())
		fmt.Println("")

		devices, err := cl.GetDevices(p, cl.DeviceTypeGPU)
		if err != nil {
			fmt.Println("Device error (check your GPU drivers) :", err)
			return
		}

		for _, d := range devices {
			fmt.Println("Device OpenCL id        ", i)
			fmt.Println("Device id for mining    ", len(found))
			fmt.Println("Device Name             ", d.Name())
			fmt.Println("Vendor                  ", d.Vendor())
			fmt.Println("Version                 ", d.Version())
			fmt.Println("Driver version          ", d.DriverVersion())
			fmt.Println("Address bits            ", d.AddressBits())
			fmt.Println("Max clock freq          ", d.MaxClockFrequency())
			fmt.Println("Global mem size         ", d.GlobalMemSize())
			fmt.Println("Max constant buffer size", d.MaxConstantBufferSize())
			fmt.Println("Max mem alloc size      ", d.MaxMemAllocSize())
			fmt.Println("Max compute units       ", d.MaxComputeUnits())
			fmt.Println("Max work group size     ", d.MaxWorkGroupSize())
			fmt.Println("Max work item sizes     ", d.MaxWorkItemSizes())
			fmt.Println("=============================================")

			found = append(found, d)
		}
	}
	if len(found) == 0 {
		fmt.Println("Found no GPU(s). Check that your OS can see the GPU(s)")
	} else {
		var idsFormat string
		for i := 0; i < len(found); i++ {
			idsFormat += strconv.Itoa(i)
			if i != len(found)-1 {
				idsFormat += ","
			}
		}
		fmt.Printf("Found %v devices. Benchmark first GPU:       geth gpubench 0\n", len(found))
		fmt.Printf("Mine using all GPUs:                        geth --minegpu %v\n", idsFormat)
	}
}