public AmdConfig GetAmdConfig(AlgorithmType algorithmType) { AmdConfig config = null; _amdConfigs.TryGetValue(algorithmType, out config); return(config); }
public void SetAmdConfig(AlgorithmType algorithmType, AmdConfig conf) { if (HasConfig(DeviceType.AMD, algorithmType)) { return; } _amdConfigs.TryAdd(algorithmType, conf); }
protected async Task <string> PrepareDeviceConfigs(CancellationToken stop) { var binPathBinCwdPair = GetBinAndCwdPaths(); var binCwd = binPathBinCwdPair.Item2; var algo = AlgorithmName(_algorithmType); // prepare configs var folder = _algorithmType.ToString().ToLower(); // check if we have configs var createConfigs = _miningDeviceTypes.All(deviceType => !_configHandler.HasConfig(deviceType, _algorithmType)); if (createConfigs) { using (_stopSource = new CancellationTokenSource()) using (var linked = CancellationTokenSource.CreateLinkedTokenSource(stop, _stopSource.Token)) { try { var t = CreateConfigFiles(_miningDeviceTypes, linked.Token); var tupleResult = await t; var result = tupleResult.Item1; var configFilePaths = tupleResult.Item2; if (result) { foreach (var path in configFilePaths) { var deviceTypes = _miningDeviceTypes.Where(deviceType => path.Contains(deviceType.ToString())); if (deviceTypes.Count() > 0) { var deviceType = deviceTypes.First(); _configHandler.SaveMoveConfig(deviceType, _algorithmType, path); } } } } catch (Exception e) { Logger.Info(_logGroup, $"Failed to create config file: {e.Message}"); } } } // wait until we have the algorithms ready, 5 seconds should be enough foreach (var deviceType in _miningDeviceTypes) { var hasConfig = false; var start = DateTime.UtcNow; while (DateTime.UtcNow.Subtract(start).Seconds < 5) { await Task.Delay(100); hasConfig = _configHandler.HasConfig(deviceType, _algorithmType); if (hasConfig) { break; } } if (!hasConfig) { Logger.Info(_logGroup, $"Config for {deviceType.ToString()}_{_algorithmType.ToString()} not found!"); throw new Exception($"Cannot start device type {deviceType.ToString()} for algorithm {_algorithmType.ToString()} there is no config"); } } var deviceConfigParams = ""; // prepare foreach (var deviceType in _miningDeviceTypes) { var flag = deviceType.ToString().ToLower(); // for filtering devices by CUDA and OpenCL indexes var deviceIDs = _miningPairs.Where(pair => pair.Device.DeviceType == deviceType).Select(pair => pair.Device.ID); var config = $"{flag}_{string.Join(",", deviceIDs)}.txt".ToLower(); deviceConfigParams += $@" --{flag} {folder}\{config}"; var deviceConfigFilePath = Path.Combine(binCwd, folder, config); if (_cpuConfig == null && DeviceType.CPU == deviceType) { // we just use the template _cpuConfig = _configHandler.GetCpuConfig(_algorithmType); ConfigHelpers.WriteConfigFile(deviceConfigFilePath, _cpuConfig); } if (_nvidiaConfig == null && DeviceType.NVIDIA == deviceType) { var nvidiaTemplate = _configHandler.GetNvidiaConfig(_algorithmType); _nvidiaConfig = new NvidiaConfig(); _nvidiaConfig.gpu_threads_conf = nvidiaTemplate.gpu_threads_conf.Where(t => deviceIDs.Contains(t.index)).ToList(); ConfigHelpers.WriteConfigFile(deviceConfigFilePath, _nvidiaConfig); } if (_amdConfig == null && DeviceType.AMD == deviceType) { var openClAmdPlatformResult = MinerToolkit.GetOpenCLPlatformID(_miningPairs); var openClAmdPlatformNum = openClAmdPlatformResult.Item1; bool openClAmdPlatformNumUnique = openClAmdPlatformResult.Item2; if (!openClAmdPlatformNumUnique) { Logger.Error(_logGroup, "Initialization of miner failed. Multiple OpenCLPlatform IDs found!"); throw new InvalidOperationException("Invalid mining initialization"); } var amdTemplate = _configHandler.GetAmdConfig(_algorithmType); _amdConfig = new AmdConfig() { platform_index = openClAmdPlatformNum }; _amdConfig.gpu_threads_conf = amdTemplate.gpu_threads_conf.Where(t => deviceIDs.Contains(t.index)).ToList(); ConfigHelpers.WriteConfigFile(deviceConfigFilePath, _amdConfig); } } return(deviceConfigParams); }