compute_unit 0.1.0 → 0.3.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +28 -0
- data/Gemfile +1 -7
- data/README.md +142 -4
- data/compute_unit.gemspec +7 -7
- data/lib/compute_unit.rb +14 -1
- data/lib/compute_unit/asic.rb +19 -0
- data/lib/compute_unit/compute_base.rb +10 -0
- data/lib/compute_unit/cpu.rb +116 -2
- data/lib/compute_unit/device.rb +10 -7
- data/lib/compute_unit/gpu.rb +1 -1
- data/lib/compute_unit/gpus/amd_gpu.rb +10 -10
- data/lib/compute_unit/gpus/nvidia_gpu.rb +4 -2
- data/lib/compute_unit/logger.rb +2 -2
- data/lib/compute_unit/version.rb +1 -1
- metadata +12 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d3fe6b765613752707aca6037a41159d6a3d1d0f33638b3ab5b20ed7d693d844
|
4
|
+
data.tar.gz: bbc7c51a56dcca030098341bfe587ff4263d28d44859b13e9ad2efffb5614a46
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4653e9bd5a0c9da77403b6afa8fd3cd9b07c95399c074b140b82201742ef50fb80cbfd4221c792aee17d2b60547f96db2265d2a4d6797b3558bab7ffb9e97416
|
7
|
+
data.tar.gz: ef104cce6547acdc6390e5d1ab315b11eed5aaa5dcf548198f531b2bca30bec58220f23d062f2e7e7076bfc137056980fc35f34517577bdb2331e77b5d8ad840
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,31 @@
|
|
1
1
|
# Compute Unit Changelog
|
2
2
|
|
3
|
+
## Unrleased
|
4
|
+
## 0.3.2
|
5
|
+
* Fix bug with default database not being created
|
6
|
+
|
7
|
+
## 0.3.1
|
8
|
+
Released 9/24/2020
|
9
|
+
|
10
|
+
* Use the default system pcidb file instead of throwing error
|
11
|
+
* Return default data if no hmon value exist
|
12
|
+
|
13
|
+
## 0.3.0
|
14
|
+
Released 6/16/2020
|
15
|
+
|
16
|
+
* Add name method to the cpu class
|
17
|
+
* Use constant for proc path
|
18
|
+
* Use debug when kernel file doesn't exist
|
19
|
+
|
20
|
+
## 0.2.1
|
21
|
+
Released 6/6/2020
|
22
|
+
|
23
|
+
* update rake and other gems
|
24
|
+
|
25
|
+
## 0.2.0
|
26
|
+
Released 6/5/2020
|
27
|
+
* Added more cpu methods for various POI.
|
28
|
+
* Ensure constants exist when side loaded
|
29
|
+
* Add descendent discovery mechanism to GPU class
|
30
|
+
|
3
31
|
## initial version 0.1.0
|
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
|
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
|
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,12 +35,133 @@ 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
|
+
|
134
|
+
### Subclassing a compute object
|
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
|
+
|
138
|
+
|
139
|
+
```ruby
|
140
|
+
# coolproject/vegagpu.rb
|
141
|
+
require 'cool_project/vega_gpu'
|
142
|
+
module CoolProject
|
143
|
+
class VegaGpu < ::ComputeUnit::Gpu::AmdGpu
|
144
|
+
include CoolProject::Metrics
|
145
|
+
|
146
|
+
def initialize(device_path, opts)
|
147
|
+
super(device_path, opts)
|
148
|
+
@is_vega = true
|
149
|
+
end
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
```
|
154
|
+
|
155
|
+
Once you have your new class created all you need to do is load the class before running find all.
|
156
|
+
|
157
|
+
```ruby
|
158
|
+
require 'compute_unit'
|
159
|
+
require 'coolproject/vegagpu'
|
160
|
+
require 'yaml'
|
161
|
+
|
162
|
+
puts ComputeUnit.find_all.to_yaml
|
163
|
+
|
164
|
+
```
|
43
165
|
|
44
166
|
## Make and Model information
|
45
167
|
This library uses the pci database maintained here https://pci-ids.ucw.cz/ which is also used by `lspci` and other linux tools. If your device is giving the wrong info the problem is likely due to the database being incorrect.
|
@@ -51,9 +173,25 @@ If you want to refresh the database every time with finding all the devices you
|
|
51
173
|
Or you can also run the simple cli tool. `update_pcidb` that comes with this library.
|
52
174
|
|
53
175
|
## Kernel support
|
54
|
-
There will likely be changes with reading and writing information to sysfs as new
|
176
|
+
There will likely be changes with reading and writing information to sysfs as new kernels are released. This library has been tested against.
|
55
177
|
|
56
178
|
* 4.15 - 4.20
|
179
|
+
* 5.x
|
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
|
+
```
|
57
195
|
|
58
196
|
## Development
|
59
197
|
|
@@ -67,7 +205,7 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/logicm
|
|
67
205
|
|
68
206
|
## License
|
69
207
|
|
70
|
-
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.
|
71
209
|
|
72
210
|
## Code of Conduct
|
73
211
|
|
data/compute_unit.gemspec
CHANGED
@@ -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
|
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
|
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.
|
40
|
-
spec.add_development_dependency 'bundler', '~> 2.
|
41
|
-
spec.add_development_dependency 'rake', '~>
|
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
|
data/lib/compute_unit.rb
CHANGED
@@ -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
|
-
|
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
|
+
File.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'
|
data/lib/compute_unit/asic.rb
CHANGED
@@ -9,6 +9,25 @@ module ComputeUnit
|
|
9
9
|
[]
|
10
10
|
end
|
11
11
|
|
12
|
+
def self.create_from_path(device_path, index)
|
13
|
+
opts = {
|
14
|
+
device_class_id: device_class(device_path),
|
15
|
+
device_id: device(device_path),
|
16
|
+
device_vendor_id: device_vendor(device_path),
|
17
|
+
subsystem_vendor_id: subsystem_vendor(device_path),
|
18
|
+
subsystem_device_id: subsystem_device(device_path),
|
19
|
+
index: index
|
20
|
+
}
|
21
|
+
new(device_path, opts)
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.find_all
|
25
|
+
return []
|
26
|
+
devices.sort.map.with_index do |device_path, index|
|
27
|
+
create_from_path(device_path, index)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
12
31
|
# /sys/devices/platform $ more coretemp.0/hwmon/hwmon1/temp1_input / 1000
|
13
32
|
end
|
14
33
|
end
|
@@ -16,6 +16,16 @@ module ComputeUnit
|
|
16
16
|
# timeout value
|
17
17
|
CACHE_TIMEOUT = 30
|
18
18
|
|
19
|
+
# @return [Array] - find all the decendants of thyself
|
20
|
+
def self.compute_classes
|
21
|
+
ObjectSpace.each_object(Class).select do |klass|
|
22
|
+
# <Class:#<Crossbelt::ComputeUnit::NvidiaGpu:0x00007fddc5c02a10>>
|
23
|
+
# We have to filter out these kinds of Ojbects as they don't respond to :new
|
24
|
+
# without a singleton error.
|
25
|
+
klass < self && !klass.to_s.include?('Class')
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
19
29
|
# @param value [Float] a value to offset the power calculation, either a whole number, or decimal
|
20
30
|
# @return [Integer] the value set as the offset
|
21
31
|
def power_offset=(value)
|
data/lib/compute_unit/cpu.rb
CHANGED
@@ -7,12 +7,86 @@ 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
|
13
15
|
end
|
14
16
|
end
|
15
17
|
|
18
|
+
def model
|
19
|
+
raw_cpu_data[:model_name]
|
20
|
+
end
|
21
|
+
|
22
|
+
def make
|
23
|
+
raw_cpu_data[:vendor_id]
|
24
|
+
end
|
25
|
+
|
26
|
+
def num_cores
|
27
|
+
raw_cpu_data[:cores_per_socket].to_i
|
28
|
+
end
|
29
|
+
|
30
|
+
def num_threads
|
31
|
+
raw_cpu_data[:threads_per_core].to_i
|
32
|
+
end
|
33
|
+
|
34
|
+
def nproc
|
35
|
+
raw_cpu_data[:cpus].to_i
|
36
|
+
end
|
37
|
+
|
38
|
+
def current_freq_mhz
|
39
|
+
raw_cpu_data[:cpu_mhz].to_f.round(0)
|
40
|
+
end
|
41
|
+
|
42
|
+
def max_freq_mhz
|
43
|
+
raw_cpu_data[:cpu_max_mhz].to_f.round(0)
|
44
|
+
end
|
45
|
+
|
46
|
+
def min_freq_mhz
|
47
|
+
raw_cpu_data[:cpu_min_mhz].to_f.round(0)
|
48
|
+
end
|
49
|
+
|
50
|
+
def base_hwmon_path
|
51
|
+
File.join(ComputeUnit::SYSFS_PATH, 'devices/platform/coretemp.0/hwmon')
|
52
|
+
end
|
53
|
+
|
54
|
+
# @return [Hash] - a hash of temp readings and their labels
|
55
|
+
# @example temps => {:core_0=>31, :core_1=>31, :package_id_0=>27}
|
56
|
+
def temps
|
57
|
+
Dir.glob(File.join(hwmon_path, 'temp*_label')).each_with_object({}) do |label_file, acc|
|
58
|
+
temp_file = label_file.sub('label', 'input')
|
59
|
+
label = normalize_name(read_file(label_file))
|
60
|
+
reading = read_file(temp_file).to_f.round(0) / 1000
|
61
|
+
acc[label] = reading
|
62
|
+
acc
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
# @return [Integer] - the temperature of the cpu package in Celsius
|
67
|
+
def temp
|
68
|
+
read_hwmon_data('temp1_input', 0).to_f.round(0) / 1000
|
69
|
+
end
|
70
|
+
|
71
|
+
def metrics
|
72
|
+
{
|
73
|
+
temp: temp,
|
74
|
+
minFreqMhz: min_freq_mhz,
|
75
|
+
maxFreqMhz: max_freq_mhz,
|
76
|
+
currentFreqMhz: current_freq_mhz,
|
77
|
+
model: model,
|
78
|
+
make: make,
|
79
|
+
numCores: num_cores,
|
80
|
+
numThreads: num_threads,
|
81
|
+
nproc: nproc,
|
82
|
+
temps: temps
|
83
|
+
}
|
84
|
+
end
|
85
|
+
|
86
|
+
def to_h
|
87
|
+
super.merge(metrics)
|
88
|
+
end
|
89
|
+
|
16
90
|
def self.create_from_path(device_path, index)
|
17
91
|
opts = {
|
18
92
|
device_class_id: device_class(device_path),
|
@@ -26,11 +100,51 @@ module ComputeUnit
|
|
26
100
|
end
|
27
101
|
|
28
102
|
def self.find_all
|
29
|
-
return [] # not quite ready to show cpu data
|
30
103
|
devices.sort.map.with_index do |device_path, index|
|
31
104
|
create_from_path(device_path, index)
|
32
105
|
end
|
33
106
|
end
|
34
|
-
|
107
|
+
|
108
|
+
private
|
109
|
+
|
110
|
+
# @param value [String]
|
111
|
+
# @return [String]
|
112
|
+
# @summary downcases and transforms spaces into underscores
|
113
|
+
def normalize_name(value)
|
114
|
+
value.downcase.gsub(/\s/, '_').gsub('(s)', 's').to_sym
|
115
|
+
end
|
116
|
+
|
117
|
+
# @return [Hash] - a hash of cpu info returned from lscpu
|
118
|
+
# normalizes the key name by downcasing and removing spaces
|
119
|
+
# @example
|
120
|
+
# raw_cpu_data() =>
|
121
|
+
# {"architecture"=>"x86_64", "cpu_op-modes"=>"32-bit, 64-bit", "byte_order"=>"Little Endian",
|
122
|
+
# "cpus"=>"4", "on-line_cpus list"=>"0-3", "threads_per core"=>"2", "cores_per socket"=>"2",
|
123
|
+
# "sockets"=>"1", "numa_nodes"=>"1", "vendor_id"=>"GenuineIntel", "cpu_family"=>"6",
|
124
|
+
# "model"=>"158", "model_name"=>"Intel(R) Core(TM) i3-7100 CPU @ 3.90GHz", "stepping"=>"9",
|
125
|
+
# "cpu_mhz"=>"800.545", "cpu_max mhz"=>"3900.0000", "cpu_min mhz"=>"800.0000",
|
126
|
+
# "bogomips"=>"7799.87", "virtualization"=>"VT-x", "l1d_cache"=>"32K", "l1i_cache"=>"32K",
|
127
|
+
# "l2_cache"=>"256K", "l3_cache"=>"3072K", "numa_node0 cpus"=>"0-3",
|
128
|
+
# "flags"=>"fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36
|
129
|
+
# clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc
|
130
|
+
# art arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf pni
|
131
|
+
# pclmulqdq dtes64 monitor ds_cpl vmx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid sse4_1
|
132
|
+
# sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm
|
133
|
+
# 3dnowprefetch cpuid_fault invpcid_single tpr_shadow vnmi flexpriority ept vpid ept_ad
|
134
|
+
# fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid mpx rdseed adx smap clflushopt intel_pt
|
135
|
+
# xsaveopt xsavec xgetbv1 xsaves dtherm arat pln pts hwp hwp_notify hwp_act_window hwp_epp"
|
136
|
+
# }
|
137
|
+
def raw_cpu_data
|
138
|
+
@raw_cpu_data ||= begin
|
139
|
+
# turns each line into a hash of key value pairs
|
140
|
+
regex = /(?<name>[\s\w\-\(\)]+)\:\s+(?<value>[@\s\w\-\,\.\(\)]+)$/
|
141
|
+
`lscpu`.lines.each_with_object({}) do |line, acc|
|
142
|
+
m = line.match(regex)
|
143
|
+
name = normalize_name(m.named_captures['name'])
|
144
|
+
acc[name] = m.named_captures['value'].chomp if m
|
145
|
+
acc
|
146
|
+
end
|
147
|
+
end
|
148
|
+
end
|
35
149
|
end
|
36
150
|
end
|
data/lib/compute_unit/device.rb
CHANGED
@@ -1,16 +1,16 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'compute_unit'
|
3
4
|
require 'compute_unit/logger'
|
4
5
|
require 'compute_unit/cache_store'
|
5
6
|
require 'compute_unit/utils'
|
6
|
-
|
7
7
|
# This file supports reading from sysfs
|
8
8
|
# More information about sysfs can be found here - https://www.kernel.org/doc/Documentation/filesystems/sysfs-pci.txt
|
9
9
|
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,
|
@@ -127,7 +127,10 @@ module ComputeUnit
|
|
127
127
|
|
128
128
|
def read_file(path, default = nil)
|
129
129
|
File.read(path).chomp
|
130
|
-
rescue Errno::EINVAL, Errno::EPERM
|
130
|
+
rescue Errno::EINVAL, Errno::EPERM
|
131
|
+
default
|
132
|
+
rescue Errno::ENOENT
|
133
|
+
logger.debug("File #{path} does not exist, using defaults")
|
131
134
|
default
|
132
135
|
rescue Errno::EACCES
|
133
136
|
logger.fatal('run this command as root or with sudo, using default value')
|
@@ -137,9 +140,9 @@ module ComputeUnit
|
|
137
140
|
# @param item [String] - the name of the hwmon file to read from
|
138
141
|
# @param default [Object] - the default value to return if the file is empty or not readable
|
139
142
|
# @return [String] - the value of the item looked up
|
140
|
-
def read_hwmon_data(item,
|
143
|
+
def read_hwmon_data(item, default = nil)
|
141
144
|
path = File.join(hwmon_path, item)
|
142
|
-
read_file(path)
|
145
|
+
read_file(path, default)
|
143
146
|
end
|
144
147
|
|
145
148
|
# @param item [String] - the name of the hwmon file to write to
|
@@ -268,7 +271,7 @@ module ComputeUnit
|
|
268
271
|
logger.fatal(e.message)
|
269
272
|
default
|
270
273
|
rescue Errno::ENOENT
|
271
|
-
logger.
|
274
|
+
logger.debug("File #{path} does not exist")
|
272
275
|
default
|
273
276
|
rescue Errno::EACCES
|
274
277
|
logger.fatal('Run this command as root or with sudo')
|
@@ -286,7 +289,7 @@ module ComputeUnit
|
|
286
289
|
rescue Errno::EINVAL, Errno::EPERM => e
|
287
290
|
logger.fatal(e.message)
|
288
291
|
rescue Errno::ENOENT
|
289
|
-
logger.
|
292
|
+
logger.warn("File #{path} does not exist")
|
290
293
|
rescue Errno::EACCES
|
291
294
|
logger.fatal('Run this command as root or with sudo')
|
292
295
|
end
|
data/lib/compute_unit/gpu.rb
CHANGED
@@ -265,7 +265,7 @@ module ComputeUnit
|
|
265
265
|
def self.find_all(use_opencl = false)
|
266
266
|
require 'compute_unit/gpus/amd_gpu'
|
267
267
|
require 'compute_unit/gpus/nvidia_gpu'
|
268
|
-
g =
|
268
|
+
g = compute_classes.map { |klass| klass.find_all(use_opencl) }.flatten
|
269
269
|
g.sort_by(&:index)
|
270
270
|
end
|
271
271
|
|
@@ -90,6 +90,16 @@ module ComputeUnit
|
|
90
90
|
utilization
|
91
91
|
end
|
92
92
|
|
93
|
+
# @return [Integer] - the temperature of the asic chip
|
94
|
+
def asic_temp
|
95
|
+
read_hwmon_data('temp2_input', 0).to_i / 1000
|
96
|
+
end
|
97
|
+
|
98
|
+
# @return [Integer] - temperature of the memory
|
99
|
+
def mem_temp
|
100
|
+
read_hwmon_data('temp3_input', 0).to_i / 1000
|
101
|
+
end
|
102
|
+
|
93
103
|
# @return [Integer] - returns temp of gpu in celius
|
94
104
|
def temp
|
95
105
|
read_hwmon_data('temp1_input', 0).to_i / 1000
|
@@ -421,16 +431,6 @@ module ComputeUnit
|
|
421
431
|
vddci_voltage_table.first[:volt]
|
422
432
|
end
|
423
433
|
|
424
|
-
# @return [Integer] - the temperature of the asic chip
|
425
|
-
def asic_temp
|
426
|
-
read_hwmon_data('temp2_input', 0).to_i / 1000
|
427
|
-
end
|
428
|
-
|
429
|
-
# @return [Integer] - the temperature of the memory chips
|
430
|
-
def mem_temp
|
431
|
-
read_hwmon_data('temp3_input', 0).to_i / 1000
|
432
|
-
end
|
433
|
-
|
434
434
|
def set_mem_clock_and_vddc(mem_clock, mem_volt)
|
435
435
|
return unless experimental_on?
|
436
436
|
|
@@ -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(
|
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 =
|
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
|
data/lib/compute_unit/logger.rb
CHANGED
@@ -8,7 +8,7 @@ module ComputeUnit
|
|
8
8
|
if ENV['LOG_FILENAME'] && File.exist?(ENV['LOG_FILENAME'])
|
9
9
|
ENV['LOG_FILENAME']
|
10
10
|
else
|
11
|
-
|
11
|
+
STDERR
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
@@ -18,7 +18,7 @@ module ComputeUnit
|
|
18
18
|
log.level = log_level
|
19
19
|
log.progname = 'ComputeUnit'
|
20
20
|
log.formatter = proc do |severity, datetime, progname, msg|
|
21
|
-
if Logger.log_file ==
|
21
|
+
if Logger.log_file == STDERR
|
22
22
|
"#{severity} - #{progname}: #{msg}\n".send(color(severity))
|
23
23
|
else
|
24
24
|
"#{datetime} #{severity} - #{progname}: #{msg}\n".send(color(severity))
|
data/lib/compute_unit/version.rb
CHANGED
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.
|
4
|
+
version: 0.3.2
|
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-
|
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.
|
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.
|
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.
|
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.
|
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: '
|
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: '
|
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
|
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
|
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:
|