compute_unit 0.2.0 → 0.3.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0ce131c209f99ed5bd86a2439e56b2fcd8e0d7b85120db149d3c4427e6ea8ef0
4
- data.tar.gz: 478ef837c6b68adecfc84bb6adc4f6120a8f8e119e371ce13f3503808e92788f
3
+ metadata.gz: 392d224e4b52410a749c91ddcc25c17c213c5c0b1210d535f3bd1b11c1e88f6f
4
+ data.tar.gz: 2043d45deb0e14470776ed90f04dbd89bdc02dea7b9a80b349fe4305e40f5055
5
5
  SHA512:
6
- metadata.gz: 9f1f22c7a80b053fb7612bb0e40bd7f2ea609b4c747dcdf486875289d2edab9090d590ca333d33be763cc3cec55faa6ca3a8568dc8f8f212eea3adf3e629120b
7
- data.tar.gz: 11b96609eec70c967865ecb476367210a356dfdec6a9b833929c4992e937ad8f568cdf5a01e4f1a7fa77cdcf941a245d20a55a5704385b7de1c4efc11855605d
6
+ metadata.gz: edd810f90429892d0b21d4889fd953c9b93453786b68fceb36ee8fed628e7ed650a42a4de0e535333e4a40833a43e62fd0b59c651a2d844fe60fa2dfaca76bd2
7
+ data.tar.gz: fad7d4f8fb84d70bb7613bbe4b0a34c24f108fcb8b58400a84e017ada8b4036e64d94f3be3c7a6007ab0f4164d38a7625a8b8b98c1fd27993540ea8e1b94e32d
@@ -1,6 +1,30 @@
1
1
  # Compute Unit Changelog
2
2
 
3
3
  ## Unrleased
4
+ ## 0.3.3
5
+ * Fix bug with default database not being created
6
+
7
+ ## 0.3.2
8
+ * Fix bug with default database not being created
9
+
10
+ ## 0.3.1
11
+ Released 9/24/2020
12
+
13
+ * Use the default system pcidb file instead of throwing error
14
+ * Return default data if no hmon value exist
15
+
16
+ ## 0.3.0
17
+ Released 6/16/2020
18
+
19
+ * Add name method to the cpu class
20
+ * Use constant for proc path
21
+ * Use debug when kernel file doesn't exist
22
+
23
+ ## 0.2.1
24
+ Released 6/6/2020
25
+
26
+ * update rake and other gems
27
+
4
28
  ## 0.2.0
5
29
  Released 6/5/2020
6
30
  * Added more cpu methods for various POI.
data/Gemfile CHANGED
@@ -2,17 +2,11 @@
2
2
 
3
3
  source 'https://rubygems.org'
4
4
 
5
-
6
- gem 'opencl_ruby_ffi', '~> 1.3.4'
7
- gem 'compute_unit', path: '.'
8
-
9
5
  group :test do
10
6
  gem 'pry'
11
7
  gem 'rubocop'
12
8
  gem 'rubocop-rspec'
13
9
  gem 'ruby-prof'
14
10
  gem 'simplecov'
15
- gem 'rake', '~> 10.0'
16
- gem 'rspec', '~> 3.0'
17
- gem 'bundler', '~> 2.0'
18
11
  end
12
+ gemspec
data/README.md CHANGED
@@ -1,9 +1,9 @@
1
1
  # Compute Unit Ruby Library
2
- The compute unit library helps you write future abstractions and tooling for crypto mining, machine learning or just general purpose usage. This library was extracted out of the crypto mining tool [Crossbelt](https://crossbelt.blockops.party) to help spur more tooling to ruby.
2
+ The compute unit library helps you write future abstractions and tooling for crypto mining, machine learning or just general purpose. This library was extracted out of the crypto mining tool [Crossbelt](https://crossbelt.blockops.party) to help spur more tooling for ruby.
3
3
 
4
4
  Uses the sysfs filesystem to quickly read and write compute unit data. More information about sysfs can be found [here](https://www.kernel.org/doc/Documentation/filesystems/sysfs-pci.txt)
5
5
 
6
- This library will:
6
+ This library has the ability to:
7
7
 
8
8
  * Detect all compute devices such as cpu, gpu, and anything else we add to this library.
9
9
  * Provide the ability to control GPU fans.
@@ -11,6 +11,7 @@ This library will:
11
11
  * Change or view voltage, core clock, memory clock and other tunning parameters used for overclocking.
12
12
  * Provide inventory data of all the devices with make, model and other important information.
13
13
  * Provide realtime status information of various data points. Useful for real-time tunning.
14
+ * Interact with the compute device via ruby.
14
15
 
15
16
  This library was open sourced to allow further refinement and usage throughout the ruby community.
16
17
  Since machine learning is not popular on ruby due to device and program support, I hope this gem will
@@ -34,17 +35,110 @@ Or install it yourself as:
34
35
 
35
36
  ## Usage
36
37
 
38
+ Find all compute devices
37
39
  ```
38
40
  require 'compute_unit'
39
41
  devices = ComputeUnit.find_all
40
42
 
41
43
  ```
42
44
 
45
+ Find just GPU devices and list the voltage table
46
+
47
+ ```ruby
48
+ require 'compute_unit/gpu'
49
+
50
+ gpu = ComputeUnit::Gpu.find_all.first
51
+ gpu.voltage_table
52
+ => [{:pstate=>0, :clk=>852, :volt=>800, :type=>:sclk},
53
+ {:pstate=>1, :clk=>997, :volt=>860, :type=>:sclk},
54
+ {:pstate=>2, :clk=>1084, :volt=>860, :type=>:sclk},
55
+ {:pstate=>3, :clk=>1138, :volt=>860, :type=>:sclk},
56
+ {:pstate=>4, :clk=>1200, :volt=>860, :type=>:sclk},
57
+ {:pstate=>5, :clk=>1401, :volt=>860, :type=>:sclk},
58
+ {:pstate=>6, :clk=>1536, :volt=>860, :type=>:sclk},
59
+ {:pstate=>7, :clk=>1630, :volt=>1200, :type=>:sclk}]
60
+
61
+ gpu.amdgpu_pm_info
62
+ => {:mclk=>{:value=>"1020", :unit=>"MHz"},
63
+ :sclk=>{:value=>"994", :unit=>"MHz"},
64
+ :pstate_sclk=>{:value=>"1138", :unit=>"MHz"},
65
+ :pstate_mclk=>{:value=>"800", :unit=>"MHz"},
66
+ :vddgfx=>{:value=>"862", :unit=>"mV"},
67
+ :average_gpu=>{:value=>"121.0", :unit=>"W"},
68
+ :temperature=>{:value=>"57", :unit=>"C"},
69
+ :load=>{:value=>"100", :unit=>"%"}}
70
+
71
+ ```
72
+
73
+ ## Example CLI command
74
+ There is a `list_computes` command that will enumerate all the compute devices found on the system.
75
+
76
+ ```ruby
77
+ list_computes
78
+ [
79
+ {
80
+ "uuid": "GPU0",
81
+ "gpuId": "GPU0",
82
+ "syspath": "/sys/bus/pci/devices/0000:03:00.0",
83
+ "pciLoc": "0000:03:00.0",
84
+ "name": "RX Vega56",
85
+ "bios": "113-D0500100-102",
86
+ "subType": "amdgpu",
87
+ "make": "AMD",
88
+ "model": "RX Vega56",
89
+ "vendor": "AMD",
90
+ "power": 121,
91
+ "utilization": 100,
92
+ "temperature": 57,
93
+ "status": 0,
94
+ "pstate": -1,
95
+ "fanSpeed": 2946,
96
+ "type": "GPU",
97
+ "maxTemp": null,
98
+ "mem": 1020,
99
+ "cor": 997,
100
+ "vlt": 862,
101
+ "mem_temp": 75,
102
+ "maxFan": null,
103
+ "dpm": null,
104
+ "vddci": null,
105
+ "maxPower": null,
106
+ "ocProfile": null,
107
+ "opencl_enabled": false
108
+ },
109
+ {
110
+ "chip_make": "GenuineIntel",
111
+ "make": "GenuineIntel",
112
+ "model": "Intel(R) Core(TM) i3-7100 CPU @ 3.90GHz",
113
+ "device_id": "590f",
114
+ "vendor_id": "8086",
115
+ "subsystem_device_id": "7a59",
116
+ "subsystem_vendor_id": "1462",
117
+ "device_class": "060000",
118
+ "temp": 33,
119
+ "minFreqMhz": 800,
120
+ "maxFreqMhz": 3900,
121
+ "currentFreqMhz": 3600,
122
+ "numCores": 2,
123
+ "numThreads": 2,
124
+ "nproc": 4,
125
+ "temps": {
126
+ "package_id_0": 33,
127
+ "core_0": 26,
128
+ "core_1": 33
129
+ }
130
+ }
131
+ ]
132
+ ```
133
+
43
134
  ### Subclassing a compute object
44
- Instead of monkey patching this code you can simply subclass the objects. The find_all methods are intelligent enough to locate your subclass by searching the Objectspace for all decendants of `ComputeUnit::ComputeBase`. This makes it dead simple to add new functionality without having to wrap any code. This gives you the ability to include new modules or override existing methods.
135
+ Instead of monkey patching this code you can simply subclass the objects. The find_all methods are intelligent enough to locate your subclass by searching the Objectspace for all decendants of `ComputeUnit::ComputeBase`. This makes it dead simple to add new functionality without having to wrap any code. This gives you the ability to include new modules or override existing methods. Just make sure you load your class before using the find_all method.
136
+
137
+
45
138
 
46
139
  ```ruby
47
140
  # coolproject/vegagpu.rb
141
+ require 'cool_project/vega_gpu'
48
142
  module CoolProject
49
143
  class VegaGpu < ::ComputeUnit::Gpu::AmdGpu
50
144
  include CoolProject::Metrics
@@ -60,7 +154,7 @@ end
60
154
 
61
155
  Once you have your new class created all you need to do is load the class before running find all.
62
156
 
63
- ```
157
+ ```ruby
64
158
  require 'compute_unit'
65
159
  require 'coolproject/vegagpu'
66
160
  require 'yaml'
@@ -84,6 +178,21 @@ There will likely be changes with reading and writing information to sysfs as ne
84
178
  * 4.15 - 4.20
85
179
  * 5.x
86
180
 
181
+ ## OpenCL Usage
182
+ The opencl_ruby_ffi gem is optionally used to gather additional info about the GPU. This can sometimes result in better model info.
183
+
184
+ There is some caution when using OpenCL. If a GPU is dead, OpenCL tends to hang/freeze thus forcing a reboot. This is not a bug in the compute_unit or opencl_ruby_ffi gem but in the OpenCL library instead.
185
+
186
+ Getting data from OpenCL also takes a long time! So if you have multiple GPUs in your system this could takes multiple seconds to return data. Because of this we cache the responses for the next query. This response is cached until the system checksum changes. This checksum is a special calculate of all the devices present in the system. So if you ever added or changed the equipment in the system, a new OpenCL query would ensue.
187
+
188
+ To enable OpenCL you just need to pass a boolean value to any of the find_all methods:
189
+
190
+ ```ruby
191
+ require 'compute_unit'
192
+ devices = ComputeUnit.find_all(true)
193
+
194
+ ```
195
+
87
196
  ## Development
88
197
 
89
198
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
@@ -96,7 +205,7 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/logicm
96
205
 
97
206
  ## License
98
207
 
99
- The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
208
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT.
100
209
 
101
210
  ## Code of Conduct
102
211
 
@@ -13,9 +13,9 @@ Gem::Specification.new do |spec|
13
13
  spec.summary = 'A ruby library for compute unit devices'
14
14
  spec.description = <<~EOF
15
15
 
16
- A ruby library that searches uses the linux sysfs file system for compute unit devices such as
17
- CPUS, GPUs and other ASIC compute devices. Allows programmatic access collect real time metrics from the kernel or relatated driver toolchain.
18
- Is meant to be used as a toolchain to future build tooling on. This library also makes use of opencl toolchain and requires
16
+ A ruby library that searches the linux sysfs file system for compute unit devices such as
17
+ CPUS, GPUs and other ASIC compute devices. Allows programmatic access to collect real time metrics from the kernel or relatated driver toolchain.
18
+ Is meant to be used as a toolchain for future tools. This library also makes use of opencl library and requires
19
19
  the opencl_ruby_ffi gem.
20
20
 
21
21
  EOF
@@ -25,7 +25,7 @@ Gem::Specification.new do |spec|
25
25
 
26
26
  spec.metadata['homepage_uri'] = spec.homepage
27
27
  spec.metadata['source_code_uri'] = spec.homepage
28
- spec.metadata['changelog_uri'] = "#{spec.homepage}/CHANGELOG"
28
+ spec.metadata['changelog_uri'] = "#{spec.homepage}/-/blob/master/CHANGELOG.md"
29
29
 
30
30
  # Specify which files should be added to the gem when it is released.
31
31
  # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
@@ -36,8 +36,8 @@ Gem::Specification.new do |spec|
36
36
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
37
37
  spec.require_paths = ['lib']
38
38
 
39
- spec.add_dependency 'opencl_ruby_ffi', '~> 1.3.0'
40
- spec.add_development_dependency 'bundler', '~> 2.0'
41
- spec.add_development_dependency 'rake', '~> 10.0'
39
+ spec.add_dependency 'opencl_ruby_ffi', '~> 1.3.4'
40
+ spec.add_development_dependency 'bundler', '~> 2.1'
41
+ spec.add_development_dependency 'rake', '~> 13'
42
42
  spec.add_development_dependency 'rspec', '~> 3.0'
43
43
  end
@@ -11,23 +11,36 @@ module ComputeUnit
11
11
  SYS_DEVICE_PATH = File.join(SYSFS_PATH, 'bus/pci/devices')
12
12
  PCI_DATABASE_PATH = File.join(File.dirname(__dir__), 'pci.ids')
13
13
  PCI_DATABASE_URL = 'http://pci-ids.ucw.cz/v2.2/pci.ids'
14
+ DEFAULT_PCIDB_PATH = '/usr/share/hwdata/pci.ids'
14
15
 
16
+ # @param use_opencl [Boolean]
17
+ # @return [Array] - return a list of compute units
15
18
  def self.find_all(use_opencl = false)
16
19
  require 'compute_unit/gpu'
17
20
  require 'compute_unit/cpu'
18
21
  require 'compute_unit/asic'
19
- raise Exceptions::InvalidPCIDatabase.new('Run: ComputeUnit.refresh_pci_database') unless File.exist?(PCI_DATABASE_PATH)
22
+
23
+ copy_default_database unless File.exist?(PCI_DATABASE_PATH)
20
24
 
21
25
  ComputeUnit::Gpu.find_all(use_opencl) +
22
26
  ComputeUnit::Cpu.find_all +
23
27
  ComputeUnit::Asic.find_all
24
28
  end
25
29
 
30
+ # copies the default pci database from linux filesystem over to the gem path
31
+ def self.copy_default_database
32
+ FileUtils.cp(DEFAULT_PCIDB_PATH, PCI_DATABASE_PATH)
33
+ end
34
+
35
+ # get a fresh copy of the database and then use find_all
36
+ # @param use_opencl [Boolean]
37
+ # @return [Array] - return a list of compute units
26
38
  def self.find_all_with_database(use_opencl = false)
27
39
  refresh_pci_database
28
40
  find_all(use_opencl)
29
41
  end
30
42
 
43
+ # downloads the pci database
31
44
  def self.refresh_pci_database
32
45
  ComputeUnit::Utils.check_for_root
33
46
  require 'net/http'
@@ -7,6 +7,8 @@ module ComputeUnit
7
7
  DEVICE_CLASS = '060000'
8
8
  DEVICE_CLASS_NAME = 'CPU'
9
9
  # @return [Array] - returns a list of device paths of all devices considered for display
10
+ alias name model
11
+
10
12
  def self.devices
11
13
  ComputeUnit::ComputeBase.devices.find_all do |device|
12
14
  ComputeUnit::Device.device_class(device) == DEVICE_CLASS
@@ -10,7 +10,7 @@ module ComputeUnit
10
10
  class Device
11
11
  # We can supply a mock sysfs path in order to test with containers and other scenarios
12
12
  SYSFS_DEVICES_PATH = File.join(ComputeUnit::SYSFS_PATH, 'bus', 'pci', 'devices')
13
-
13
+ PROC_PATH = ENV['PROC_PATH'] || '/proc'
14
14
  attr_reader :device_class_id,
15
15
  :device_id,
16
16
  :device_vendor_id,
@@ -130,7 +130,7 @@ module ComputeUnit
130
130
  rescue Errno::EINVAL, Errno::EPERM
131
131
  default
132
132
  rescue Errno::ENOENT
133
- logger.warn("File #{path} does not exist, using defaults")
133
+ logger.debug("File #{path} does not exist, using defaults")
134
134
  default
135
135
  rescue Errno::EACCES
136
136
  logger.fatal('run this command as root or with sudo, using default value')
@@ -140,9 +140,9 @@ module ComputeUnit
140
140
  # @param item [String] - the name of the hwmon file to read from
141
141
  # @param default [Object] - the default value to return if the file is empty or not readable
142
142
  # @return [String] - the value of the item looked up
143
- def read_hwmon_data(item, _default = nil)
143
+ def read_hwmon_data(item, default = nil)
144
144
  path = File.join(hwmon_path, item)
145
- read_file(path)
145
+ read_file(path, default)
146
146
  end
147
147
 
148
148
  # @param item [String] - the name of the hwmon file to write to
@@ -271,7 +271,7 @@ module ComputeUnit
271
271
  logger.fatal(e.message)
272
272
  default
273
273
  rescue Errno::ENOENT
274
- logger.warn("File #{path} does not exist")
274
+ logger.debug("File #{path} does not exist")
275
275
  default
276
276
  rescue Errno::EACCES
277
277
  logger.fatal('Run this command as root or with sudo')
@@ -8,6 +8,7 @@ module ComputeUnit
8
8
  MAKE = 'Nvidia'
9
9
  SUBTYPE = 'nvidia'
10
10
  NVIDIA_SMI = '/usr/bin/nvidia-smi'
11
+ NVIDIA_PROC_PATH = ENV['NVIDIA_PROC_PATH'] || File.join(ComputeUnit::Device::PROC_PATH, 'driver', 'nvidia', 'gpus')
11
12
 
12
13
  def initialize(device_path, opts = {})
13
14
  data = self.class.read_information_file(device_path).merge(opts)
@@ -159,7 +160,7 @@ module ComputeUnit
159
160
  def information_file
160
161
  @information_file ||= begin
161
162
  device_name = File.basename(device_path)
162
- File.join('/proc/driver/nvidia/gpus', device_name, 'information')
163
+ File.join(NVIDIA_PROC_PATH, device_name, 'information')
163
164
  end
164
165
  end
165
166
 
@@ -209,7 +210,8 @@ module ComputeUnit
209
210
  # :device_minor=>"7"}
210
211
  def self.read_information_file(device_path)
211
212
  device_name = File.basename(device_path)
212
- information_file = "/proc/driver/nvidia/gpus/#{device_name}/information"
213
+ information_file = File.join(NVIDIA_PROC_PATH, device_name, 'information')
214
+
213
215
  File.open(information_file, 'r') do |file|
214
216
  content = file.read
215
217
  content.scan(/\n?([\w\s]*):\s+(.*)/).map { |key, value| [key.downcase.tr(' ', '_').to_sym, value] }.to_h
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ComputeUnit
4
- VERSION = '0.2.0'
4
+ VERSION = '0.3.3'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: compute_unit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Corey Osman
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-06-05 00:00:00.000000000 Z
11
+ date: 2020-10-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: opencl_ruby_ffi
@@ -16,42 +16,42 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 1.3.0
19
+ version: 1.3.4
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 1.3.0
26
+ version: 1.3.4
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '2.0'
33
+ version: '2.1'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '2.0'
40
+ version: '2.1'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '10.0'
47
+ version: '13'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '10.0'
54
+ version: '13'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rspec
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -68,9 +68,9 @@ dependencies:
68
68
  version: '3.0'
69
69
  description: |2+
70
70
 
71
- A ruby library that searches uses the linux sysfs file system for compute unit devices such as
72
- CPUS, GPUs and other ASIC compute devices. Allows programmatic access collect real time metrics from the kernel or relatated driver toolchain.
73
- Is meant to be used as a toolchain to future build tooling on. This library also makes use of opencl toolchain and requires
71
+ A ruby library that searches the linux sysfs file system for compute unit devices such as
72
+ CPUS, GPUs and other ASIC compute devices. Allows programmatic access to collect real time metrics from the kernel or relatated driver toolchain.
73
+ Is meant to be used as a toolchain for future tools. This library also makes use of opencl library and requires
74
74
  the opencl_ruby_ffi gem.
75
75
 
76
76
  email:
@@ -119,7 +119,7 @@ licenses:
119
119
  metadata:
120
120
  homepage_uri: https://gitlab.com/blockops/compute_unit
121
121
  source_code_uri: https://gitlab.com/blockops/compute_unit
122
- changelog_uri: https://gitlab.com/blockops/compute_unit/CHANGELOG
122
+ changelog_uri: https://gitlab.com/blockops/compute_unit/-/blob/master/CHANGELOG.md
123
123
  post_install_message:
124
124
  rdoc_options: []
125
125
  require_paths: