Skip to content

Commit

Permalink
pass required channel to newMinerDevs and return devices
Browse files Browse the repository at this point in the history
  • Loading branch information
dajohi committed Oct 12, 2023
1 parent 2e7c33a commit c520a0a
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 25 deletions.
17 changes: 9 additions & 8 deletions cladldevice.go
Original file line number Diff line number Diff line change
Expand Up @@ -583,20 +583,21 @@ func (d *Device) runDevice() error {
}
}

func newMinerDevs(m *Miner) (*Miner, int, error) {
func newMinerDevs(workDone chan []byte) ([]*Device, error) {
deviceListIndex := 0
deviceListEnabledCount := 0

platformIDs, err := getCLPlatforms()
if err != nil {
return nil, 0, fmt.Errorf("could not get CL platforms: %w", err)
return nil, fmt.Errorf("could not get CL platforms: %w", err)
}

var devices []*Device
for p := range platformIDs {
platformID := platformIDs[p]
CLdeviceIDs, err := getCLDevices(platformID)
if err != nil {
return nil, 0, fmt.Errorf("could not get CL devices for platform: %w", err)
return nil, fmt.Errorf("could not get CL devices for platform: %w", err)
}

for _, CLdeviceID := range CLdeviceIDs {
Expand All @@ -613,17 +614,17 @@ func newMinerDevs(m *Miner) (*Miner, int, error) {
miningAllowed = true
}
if miningAllowed {
newDevice, err := NewDevice(deviceListIndex, deviceListEnabledCount, platformID, CLdeviceID, m.workDone)
deviceListEnabledCount++
m.devices = append(m.devices, newDevice)
newDevice, err := NewDevice(deviceListIndex, deviceListEnabledCount, platformID, CLdeviceID, workDone)
if err != nil {
return nil, 0, err
return nil, err
}
devices = append(devices, newDevice)
deviceListEnabledCount++
}
deviceListIndex++
}
}
return m, deviceListEnabledCount, nil
return devices, nil
}

func getDeviceInfo(id cl.CL_device_id,
Expand Down
17 changes: 9 additions & 8 deletions cldevice.go
Original file line number Diff line number Diff line change
Expand Up @@ -710,20 +710,21 @@ func (d *Device) runDevice(ctx context.Context) error {
}
}

func newMinerDevs(m *Miner) (*Miner, int, error) {
func newMinerDevs(workDone chan []byte) ([]*Device, error) {
deviceListIndex := 0
deviceListEnabledCount := 0

platformIDs, err := getCLPlatforms()
if err != nil {
return nil, 0, fmt.Errorf("could not get CL platforms: %w", err)
return nil, fmt.Errorf("could not get CL platforms: %w", err)
}

var devices []*Device
for p := range platformIDs {
platformID := platformIDs[p]
CLdeviceIDs, err := getCLDevices(platformID)
if err != nil {
return nil, 0, fmt.Errorf("could not get CL devices for platform: %w", err)
return nil, fmt.Errorf("could not get CL devices for platform: %w", err)
}

for _, CLdeviceID := range CLdeviceIDs {
Expand All @@ -740,17 +741,17 @@ func newMinerDevs(m *Miner) (*Miner, int, error) {
miningAllowed = true
}
if miningAllowed {
newDevice, err := NewDevice(deviceListIndex, deviceListEnabledCount, platformID, CLdeviceID, m.workDone)
deviceListEnabledCount++
m.devices = append(m.devices, newDevice)
newDevice, err := NewDevice(deviceListIndex, deviceListEnabledCount, platformID, CLdeviceID, workDone)
if err != nil {
return nil, 0, err
return nil, err
}
devices = append(devices, newDevice)
deviceListEnabledCount++
}
deviceListIndex++
}
}
return m, deviceListEnabledCount, nil
return devices, nil
}

func getDeviceInfo(id cl.CL_device_id,
Expand Down
15 changes: 8 additions & 7 deletions cudevice.go
Original file line number Diff line number Diff line change
Expand Up @@ -546,18 +546,19 @@ func (d *Device) calcGridSizeForMilliseconds(ms int, threadCount uint32) (uint32

return gridSize, nil
}
func newMinerDevs(m *Miner) (*Miner, int, error) {
func newMinerDevs(workDone chan []byte) ([]*Device, error) {
deviceListIndex := 0
deviceListEnabledCount := 0

CUdeviceIDs, err := getInfo()
if err != nil {
return nil, 0, err
return nil, err
}

// XXX Can probably combine these bits with the opencl ones once
// I decide what to do about the types.

var devices []*Device
for _, CUDeviceID := range CUdeviceIDs {
miningAllowed := false

Expand All @@ -573,17 +574,17 @@ func newMinerDevs(m *Miner) (*Miner, int, error) {
}

if miningAllowed {
newDevice, err := NewCuDevice(deviceListIndex, deviceListEnabledCount, CUDeviceID, m.workDone)
deviceListEnabledCount++
m.devices = append(m.devices, newDevice)
newDevice, err := NewCuDevice(deviceListIndex, deviceListEnabledCount, CUDeviceID, workDone)
if err != nil {
return nil, 0, err
return nil, err
}
devices = append(devices, newDevice)
deviceListEnabledCount++
}
deviceListIndex++
}

return m, deviceListEnabledCount, nil
return devices, nil
}

func (d *Device) Release() {
Expand Down
5 changes: 3 additions & 2 deletions miner.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,16 @@ func NewMiner() (*Miner, error) {
m.pool = s
}

m, deviceListEnabledCount, err := newMinerDevs(m)
devices, err := newMinerDevs(m.workDone)
if err != nil {
return nil, err
}

if deviceListEnabledCount == 0 {
if len(devices) == 0 {
return nil, fmt.Errorf("no devices started")
}

m.devices = devices
m.started = uint32(time.Now().Unix())

return m, nil
Expand Down

0 comments on commit c520a0a

Please sign in to comment.