module ComputeUnit
This file supports reading from sysfs More information about sysfs can be found here - www.kernel.org/doc/Documentation/filesystems/sysfs-pci.txt
Constants
- CACHE_DIR
- DEFAULT_PCIDB_PATH
- PCI_DATABASE_PATH
- PCI_DATABASE_URL
- SYSFS_PATH
- SYS_DEVICE_PATH
- VERSION
Public Class Methods
copy_default_database()
click to toggle source
copies the default pci database from linux filesystem over to the gem path
# File lib/compute_unit.rb, line 51 def self.copy_default_database FileUtils.cp(DEFAULT_PCIDB_PATH, PCI_DATABASE_PATH) if File.exist?(DEFAULT_PCIDB_PATH) end
device_paths_by_process(pid)
click to toggle source
@param pid [Integer] the pid to search with @param field [Symbol] - the field to sort by @return [Array] - a array of device paths @example usage
device_paths_by_process(3748) => ["/sys/bus/pci/devices/0000:00:00.0"]
# File lib/compute_unit.rb, line 34 def self.device_paths_by_process(pid) # processes = ComputeUnit::Cpu.attached_processes(field).last(1) + ComputeUnit::Gpu.attached_processes(field) # processes.find_all { |process| process.pid == pid } # We can get the utilized devices but it appears cubersome to convert to a device path # This method uses more resources find_by_process(pid).map(&:device_path) end
find_all(use_opencl = false)
click to toggle source
@param use_opencl [Boolean] @return [Array] - return a list of compute units
# File lib/compute_unit.rb, line 18 def self.find_all(use_opencl = false) require 'compute_unit/gpu' require 'compute_unit/cpu' require 'compute_unit/asic' # if this file doesn't exist we need to fetch it or copy it refresh_pci_database unless File.exist?(PCI_DATABASE_PATH) Gpu.find_all(use_opencl) + Cpu.find_all + Asic.find_all end
find_all_with_database(use_opencl = false)
click to toggle source
get a fresh copy of the database and then use find_all
@param use_opencl [Boolean] @return [Array] - return a list of compute units
# File lib/compute_unit.rb, line 58 def self.find_all_with_database(use_opencl = false) refresh_pci_database find_all(use_opencl) end
find_by_process(pid, use_opencl = false)
click to toggle source
@param pid [Integer] the pid to search with @param use_opencl [Boolean] use opencl on gpu devices
# File lib/compute_unit.rb, line 44 def self.find_by_process(pid, use_opencl = false) find_all(use_opencl).find_all do |unit| unit.top_processes.first.pid.to_i == pid.to_i end end
refresh_pci_database()
click to toggle source
downloads the pci database
# File lib/compute_unit.rb, line 64 def self.refresh_pci_database ComputeUnit::Utils.check_for_root require 'net/http' require 'uri' uri = URI.parse(PCI_DATABASE_URL) response = Net::HTTP.get_response(uri) # I can't write to it unless it has correct permissions File.chmod(0o644, PCI_DATABASE_PATH) if File.exist?(PCI_DATABASE_PATH) File.write(PCI_DATABASE_PATH, response.body) if response.code == '200' File.chmod(0o644, PCI_DATABASE_PATH) PCI_DATABASE_PATH end