Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/xsawyerx/lib-cpuinfo

Interface to PyTorch's libcpuinfo C library
https://github.com/xsawyerx/lib-cpuinfo

Last synced: 28 days ago
JSON representation

Interface to PyTorch's libcpuinfo C library

Awesome Lists containing this project

README

        

# NAME

Lib::CPUInfo - Perl interface to PyTorch's libcpuinfo C library

# VERSION

version 0.001

# SYNOPSIS

use Lib::CPUInfo qw<
initialize
get_cores_count
get_current_core
get_clusters
deinitialize
>;

# First, initialize
initialize()
or die "Cannot initialize cpuinfo";

# Get all the data you want through the functions
my $count = get_cores_count();

# Some functions return struct objects
my $core = get_current_core();
printf "Vendor: %s\n", $core->vendor();

foreach my $cluster ( get_clusters()->@* ) {
printf "Cluster (%d): %s\n", $cluster->id(), $cluster->vendor();
}

# Wrap up by de-initializing
deinitialize();

# DESCRIPTION

This module implements an interface to PyTorch's `libcpuinfo` available
[here](https://github.com/pytorch/cpuinfo).

Installing it on Debian and Debian-based distros:

apt install libcpuinfo0

I had written it against Debian version 0.0~git20200422.a1e0b95-2. If you find
differences, please report via GitHub and I'll do my best to handle it.

If you have use for this and need an [Alien](https://metacpan.org/pod/Alien) module to install the library
for you as a dependency, let me know.

# FUNCTIONS

The following functions are available:

## `initialize`

my $success = initialize();
if ( !$success ) {...}

# or better yet
initialize()
or die "Cannot initialize libcpuinfo";

Initialize the library.

## `deinitialize`

deinitialize();

De-initialize the library.

## `get_processors_count`

my $count = get_processors_count();

Return how many processors there are.

## `get_cores_count`

my $count = get_cores_count();

Return how many cores there are.

## `get_clusters_count`

my $count = get_clusters_count();

Return how many clusters there are.

## `get_packages_count`

my $count = get_packages_count();

Return how many packages there are.

## `get_uarchs_count`

my $count = get_uarchs_count();

Return how many uarchs there are.

## `get_l1i_caches_count`

my $count = get_l1i_caches_count();

Return how many L1i caches there are.

## `get_l1d_caches_count`

my $count = get_l1d_caches_count();

Return how many L1d caches there are.

## `get_l2_caches_count`

my $count = get_l2_caches_count();

Return how many L2 caches there are.

## `get_l3_caches_count`

my $count = get_l3_caches_count();

Return how many L3 caches there are.

## `get_l4_caches_count`

my $count = get_l4_caches_count();

Return how many L4 caches there are.

## `get_processors`

foreach my $processor ( get_processors()->@* ) {
# do something with processor object
}

Return an arrayref of all the processor objects.

See [Lib::CPUInfo::Processor](https://metacpan.org/pod/Lib%3A%3ACPUInfo%3A%3AProcessor).

## `get_cores`

foreach my $core ( get_cores()->@* ) {
# do something with core object
}

Return an arrayref of all the core objects.

See [Lib::CPUInfo::Core](https://metacpan.org/pod/Lib%3A%3ACPUInfo%3A%3ACore).

## `get_clusters`

foreach my $cluster ( get_clusters()->@* ) {
# do something with cluster object
}

Return an arrayref of all the cluster objects.

See [Lib::CPUInfo::Cluster](https://metacpan.org/pod/Lib%3A%3ACPUInfo%3A%3ACluster).

## `get_packages`

foreach my $package ( get_packages()->@* ) {
# do something with package object
}

Return an arrayref of all the package objects.

See [Lib::CPUInfo::Package](https://metacpan.org/pod/Lib%3A%3ACPUInfo%3A%3APackage).

## `get_uarchs`

foreach my $uarch ( get_uarchs()->@* ) {
# do something with uarch object
}

Return an arrayref of all the uarch objects.

See [Lib::CPUInfo::UArchInfo](https://metacpan.org/pod/Lib%3A%3ACPUInfo%3A%3AUArchInfo).

## `get_l1i_caches`

foreach my $cache ( get_l1i_caches()->@* ) {
# do something with cache object
}

Return an arrayref of all the L1i cache objects.

See [Lib::CPUInfo::Cache](https://metacpan.org/pod/Lib%3A%3ACPUInfo%3A%3ACache).

## `get_l1d_caches`

foreach my $cache ( get_l1d_caches()->@* ) {
# do something with cache object
}

Return an arrayref of all the L1d cache objects.

See [Lib::CPUInfo::Cache](https://metacpan.org/pod/Lib%3A%3ACPUInfo%3A%3ACache).

## `get_l2_caches`

foreach my $cache ( get_l2_caches()->@* ) {
# do something with cache object
}

Return an arrayref of all the L2 cache objects.

See [Lib::CPUInfo::Cache](https://metacpan.org/pod/Lib%3A%3ACPUInfo%3A%3ACache).

## `get_l3_caches`

foreach my $cache ( get_l3_caches()->@* ) {
# do something with cache object
}

Return an arrayref of all the L3 cache objects.

See [Lib::CPUInfo::Cache](https://metacpan.org/pod/Lib%3A%3ACPUInfo%3A%3ACache).

## `get_l4_caches`

foreach my $cache ( get_l4_caches()->@* ) {
# do something with cache object
}

Return an arrayref of all the L4 cache objects.

See [Lib::CPUInfo::Cache](https://metacpan.org/pod/Lib%3A%3ACPUInfo%3A%3ACache).

## `get_processor($index)`

my $index = 0;
my $processor = get_processor($index);

Return the [Lib::CPUInfo::Processor](https://metacpan.org/pod/Lib%3A%3ACPUInfo%3A%3AProcessor) processor object at index `$index`.

## `get_core($index)`

my $index = 0;
my $core = get_core($index);

Return the core object at index `$index`.

## `get_cluster($index)`

my $index = 0;
my $cluster = get_cluster($index);

Return the [Lib::CPUInfo::Cluster](https://metacpan.org/pod/Lib%3A%3ACPUInfo%3A%3ACluster) cluster object at index `$index`.

## `get_package($index)`

my $index = 0;
my $package = get_package($index);

Return the [Lib::CPUInfo::Package](https://metacpan.org/pod/Lib%3A%3ACPUInfo%3A%3APackage) package object at index `$index`.

## `get_uarch($index)`

my $index = 0;
my $uarchinfo = get_uarch($index);

Return the [Lib::CPUInfo::UArchInfo](https://metacpan.org/pod/Lib%3A%3ACPUInfo%3A%3AUArchInfo) uarch object at index `$index`.

## `get_l1i_cache($index)`

my $index = 0;
my $cache = get_l1i_cache($index);

Return the [Lib::CPUInfo::Cache](https://metacpan.org/pod/Lib%3A%3ACPUInfo%3A%3ACache) L1i cache object at index `$index`.

## `get_l1d_cache($index)`

my $index = 0;
my $cache = get_l1d_cache($index);

Return the [Lib::CPUInfo::Cache](https://metacpan.org/pod/Lib%3A%3ACPUInfo%3A%3ACache) L1d cache object at index `$index`.

## `get_l2_cache($index)`

my $index = 0;
my $cache = get_l2_cache($index);

Return the [Lib::CPUInfo::Cache](https://metacpan.org/pod/Lib%3A%3ACPUInfo%3A%3ACache) L2 cache object at index `$index`.

## `get_l3_cache($index)`

my $index = 0;
my $cache = get_l3_cache($index);

Return the [Lib::CPUInfo::Cache](https://metacpan.org/pod/Lib%3A%3ACPUInfo%3A%3ACache) L3 cache object at index `$index`.

## `get_l4_cache($index)`

my $index = 0;
my $cache = get_l4_cache($index);

Return the [Lib::CPUInfo::Cache](https://metacpan.org/pod/Lib%3A%3ACPUInfo%3A%3ACache) L4 cache object at index `$index`.

## `get_max_cache_size`

my $size = get_max_cache_size();

Get the max cache size.

## `get_current_uarch_index`

my $index = get_current_uarch_index();

Get the current UArch index, I guess?

## `get_current_core`

my $core = get_current_core();

Get the current [Lib::CPUInfo::Core](https://metacpan.org/pod/Lib%3A%3ACPUInfo%3A%3ACore) core object.

## `get_current_processor`

my $processor = get_current_processor();

Get the current [Lib::CPUInfo::Processor](https://metacpan.org/pod/Lib%3A%3ACPUInfo%3A%3AProcessor) processor object.

# BENCHMARKS

- Counting number of CPUs

Loops: 1,000.

Lib::CPUInfo: Ran 21 iterations (1 outliers).
Lib::CPUInfo: Rounded run time per iteration: 4.163e-04 +/- 1.5e-06 (0.4%)

Sys::Info::Device::CPU: Ran 25 iterations (5 outliers).
Sys::Info::Device::CPU: Rounded run time per iteration: 9.4582e-01 +/- 2.9e-04 (0.0%)

Rex::Inventory::Proc: Ran 21 iterations (0 outliers).
Rex::Inventory::Proc: Rounded run time per iteration: 5.790e-01 +/- 1.1e-03 (0.2%)

- Getting the CPU package name

Loops: 1,000.

Lib::CPUInfo: Ran 23 iterations (3 outliers).
Lib::CPUInfo: Rounded run time per iteration: 1.2206e-02 +/- 1.3e-05 (0.1%)

Sys::Info::Device::CPU: Ran 23 iterations (3 outliers).
Sys::Info::Device::CPU: Rounded run time per iteration: 9.6313e-01 +/- 1.0e-03 (0.1%)

# COVERAGE

-------------- ------ ------ ------ ------ ------ ------ ------
File stmt bran cond sub pod time total
-------------- ------ ------ ------ ------ ------ ------ ------
Lib/CPUInfo.pm 100.0 n/a 63.6 100.0 100.0 100.0 93.5
Total 100.0 n/a 63.6 100.0 100.0 100.0 93.5
-------------- ------ ------ ------ ------ ------ ------ ------

# SEE ALSO

This module uses [FFI::Platypus](https://metacpan.org/pod/FFI%3A%3APlatypus) to connect to the C library and
[FFI::C](https://metacpan.org/pod/FFI%3A%3AC) to define the object structs.

These modules also retrieve CPU information:

- [Sys::Info](https://metacpan.org/pod/Sys%3A%3AInfo)
- [Proc::CPUUsage](https://metacpan.org/pod/Proc%3A%3ACPUUsage)
- [Rex::Inventory::Proc](https://metacpan.org/pod/Rex%3A%3AInventory%3A%3AProc)
- [Linux::Cpuinfo](https://metacpan.org/pod/Linux%3A%3ACpuinfo)
- [Linux::Proc::Cpuinfo](https://metacpan.org/pod/Linux%3A%3AProc%3A%3ACpuinfo)
- [Linux::Info::CpuStats](https://metacpan.org/pod/Linux%3A%3AInfo%3A%3ACpuStats)

# AUTHOR

Sawyer X

# COPYRIGHT AND LICENSE

This software is copyright (c) 2021 by Sawyer X.

This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.