Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions recipes/recipes_emscripten/cpuinfo/build.sh
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
13 changes: 13 additions & 0 deletions recipes/recipes_emscripten/cpuinfo/build_tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash
set -e

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
59 changes: 59 additions & 0 deletions recipes/recipes_emscripten/cpuinfo/recipe.yaml
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
9 changes: 9 additions & 0 deletions recipes/recipes_emscripten/cpuinfo/tests/CMakeLists.txt
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)
40 changes: 40 additions & 0 deletions recipes/recipes_emscripten/cpuinfo/tests/test_cpuinfo.c
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;
}
Loading