-
Notifications
You must be signed in to change notification settings - Fork 85
Add cpuinfo #5004
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Add cpuinfo #5004
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| #!/bin/bash | ||
| set -e | ||
|
|
||
| emcmake cmake . \ | ||
| -DCMAKE_BUILD_TYPE=Release \ | ||
| -DCMAKE_INSTALL_PREFIX=$PREFIX \ | ||
| -DCPUINFO_LIBRARY_TYPE=static \ | ||
| -DCPUINFO_BUILD_TOOLS=OFF \ | ||
| -DCPUINFO_BUILD_UNIT_TESTS=OFF \ | ||
| -DCPUINFO_BUILD_MOCK_TESTS=OFF \ | ||
| -DCPUINFO_BUILD_BENCHMARKS=OFF \ | ||
| -DCPUINFO_BUILD_PKG_CONFIG=OFF \ | ||
| -Bcmake-out-wasm | ||
|
|
||
| cd cmake-out-wasm | ||
|
|
||
| emmake cmake --build . --target install |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| #!/bin/bash | ||
| set -e | ||
|
|
||
| export PYTHON=$BUILD_PREFIX/bin/python | ||
|
|
||
| emcmake cmake -S tests -B build_tests \ | ||
| -DCMAKE_BUILD_TYPE=Release \ | ||
| -DCMAKE_PREFIX_PATH=$PREFIX \ | ||
| -DCMAKE_FIND_ROOT_PATH=$PREFIX \ | ||
| -DCMAKE_FIND_ROOT_PATH_MODE_PACKAGE=BOTH \ | ||
| -DCMAKE_FIND_ROOT_PATH_MODE_INCLUDE=BOTH | ||
|
|
||
| emmake make -C build_tests | ||
|
|
||
| node build_tests/test_cpuinfo.js | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| context: | ||
| name: cpuinfo | ||
| version: "7364b490b5f78d58efe23ea76e74210fd6c3c76f" | ||
|
|
||
| package: | ||
| name: ${{ name }} | ||
| version: ${{ version }} | ||
|
|
||
| source: | ||
| - url: https://github.com/pytorch/cpuinfo/archive/${{ version }}.tar.gz | ||
| sha256: 67093420590f97c84d0c38cc020f134579494089d06de387bb48c7455eb5b8af | ||
|
|
||
| build: | ||
| number: 0 | ||
| script: build.sh | ||
|
|
||
| requirements: | ||
| build: | ||
| - ${{ compiler('c') }} | ||
| - ${{ compiler('cxx') }} | ||
| - cmake | ||
| - ninja | ||
| - python | ||
|
|
||
| tests: | ||
| - package_contents: | ||
| include: | ||
| - cpuinfo.h | ||
| lib: | ||
| - libcpuinfo.a | ||
| files: | ||
| - share/cpuinfo/cpuinfo-config.cmake | ||
| - script: | ||
| - build_tests.sh | ||
| requirements: | ||
| build: | ||
| - ${{ compiler("c") }} | ||
| - cmake | ||
| - ninja | ||
| files: | ||
| recipe: | ||
| - build_tests.sh | ||
| - tests/ | ||
|
|
||
| about: | ||
| homepage: https://github.com/pytorch/cpuinfo | ||
| license: BSD-2-Clause | ||
| license_file: LICENSE | ||
| summary: CPU INFOrmation library for aarch64, x86, and WebAssembly | ||
| description: | | ||
| cpuinfo is a library to detect essential for performance optimization | ||
| information about host CPU. It includes detection of CPU topology, | ||
| supported instruction sets, cache sizes, and other properties. | ||
| It has native Emscripten/WebAssembly support. | ||
| repository: https://github.com/pytorch/cpuinfo | ||
|
|
||
| extra: | ||
| recipe-maintainers: | ||
| - Alex-PLACET |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| cmake_minimum_required(VERSION 3.15) | ||
| project(cpuinfo_tests) | ||
|
|
||
| set(CMAKE_C_STANDARD 11) | ||
|
|
||
| find_package(cpuinfo REQUIRED CONFIG) | ||
|
|
||
| add_executable(test_cpuinfo test_cpuinfo.c) | ||
| target_link_libraries(test_cpuinfo PRIVATE cpuinfo::cpuinfo) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| #include <cpuinfo.h> | ||
| #include <stdio.h> | ||
| #include <assert.h> | ||
|
|
||
| int main(void) { | ||
| /* Initialize cpuinfo */ | ||
| bool ok = cpuinfo_initialize(); | ||
| assert(ok && "cpuinfo_initialize() failed"); | ||
| printf("cpuinfo initialized successfully\n"); | ||
|
|
||
| /* Processor / core / package counts must be >= 1 */ | ||
| uint32_t processors = cpuinfo_get_processors_count(); | ||
| uint32_t cores = cpuinfo_get_cores_count(); | ||
| uint32_t packages = cpuinfo_get_packages_count(); | ||
| assert(processors >= 1 && "processors count must be >= 1"); | ||
| assert(cores >= 1 && "cores count must be >= 1"); | ||
| assert(packages >= 1 && "packages count must be >= 1"); | ||
| printf("Processors: %u\n", processors); | ||
| printf("Cores: %u\n", cores); | ||
| printf("Packages: %u\n", packages); | ||
|
|
||
| /* Cache info - just check it doesn't crash */ | ||
| uint32_t l1i = cpuinfo_get_l1i_caches_count(); | ||
| uint32_t l1d = cpuinfo_get_l1d_caches_count(); | ||
| uint32_t l2 = cpuinfo_get_l2_caches_count(); | ||
| printf("L1i caches: %u\n", l1i); | ||
| printf("L1d caches: %u\n", l1d); | ||
| printf("L2 caches: %u\n", l2); | ||
|
|
||
| /* Max cache size must be > 0 when any cache is present */ | ||
| if (l1i > 0 || l1d > 0 || l2 > 0) { | ||
| uint32_t max_cache = cpuinfo_get_max_cache_size(); | ||
| assert(max_cache > 0 && "max_cache_size must be > 0 when caches exist"); | ||
| printf("Max cache size: %u bytes\n", max_cache); | ||
| } | ||
|
|
||
| cpuinfo_deinitialize(); | ||
| printf("All cpuinfo tests passed!\n"); | ||
| return 0; | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.