Skip to content
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

[Target][CI] Add LLVM functions for current system info #15903

Merged
merged 1 commit into from
Oct 12, 2023

Conversation

cbalint13
Copy link
Contributor

@cbalint13 cbalint13 commented Oct 9, 2023

This PR adds helper functions to query system info from the LLVM backend.
It enhances TVM target information handling and extends the CI coverage.


Changes:

  • Introduces llvm_get_system_cpu(), llvm_get_system_triple() and llvm_get_system_x86_vendor()
  • Exposes both C/FFI & PY interfaces for all the functions mentioned above with proper test cases.
  • Enhances CI test utils, removes old limiting checks related to arch/system/cpu/vendor dependencies.

Usage example

$ cat tvm-system-info.py
#!/usr/bin/python3

import tvm
from tvm.target import codegen, Target

cpu = codegen.llvm_get_system_cpu()
triple = codegen.llvm_get_system_triple()
vendor = codegen.llvm_get_system_x86_vendor()
target = "llvm -mtriple=%s -mcpu=%s" % (triple, cpu)

print("Current system CPU: [%s], VENDOR: [%s] TRIPLE: [%s]" % (cpu, vendor, triple))

with tvm.target.Target(target):
  features = codegen.llvm_get_cpu_features()
  print("TVM target [%s] having features:\n\n{%s}" % (target, features))
$ ./tvm-system-info.py 
Current system CPU: [skylake], VENDOR: [intel] TRIPLE: [x86_64-redhat-linux-gnu]
TVM target [llvm -mtriple=x86_64-redhat-linux-gnu -mcpu=skylake] having features:

{["64bit", "64bit-mode", "adx", "aes", "allow-light-256-bit", "avx", "avx2", "bmi", "bmi2", "clflushopt",
 "cmov", "crc32", "cx16", "cx8", "ermsb", "f16c", "false-deps-popcnt", "fast-15bytenop", "fast-gather", 
"fast-scalar-fsqrt", "fast-shld-rotate", "fast-variable-crosslane-shuffle", "fast-variable-perlane-shuffle",
 "fast-vector-fsqrt", "fma", "fsgsbase", "fxsr", "idivq-to-divl", "invpcid", "lzcnt", "macrofusion", "mmx",
 "movbe", "no-bypass-delay-blend", "no-bypass-delay-mov", "no-bypass-delay-shuffle", "nopl", "pclmul", 
"popcnt", "prfchw", "rdrnd", "rdseed", "sahf", "slow-3ops-lea", "sse", "sse2", "sse3", "sse4.1", "sse4.2", 
"ssse3", "vzeroupper", "x87", "xsave", "xsavec", "xsaveopt", "xsaves"]}
$ uname -s -r -v -m -o
Linux 6.5.0-57.fc40.x86_64 #1 SMP PREEMPT_DYNAMIC Mon Aug 28 01:50:08 UTC 2023 x86_64 GNU/Linux
$ cat /proc/cpuinfo  | grep -m1 name 
model name	: Intel(R) Core(TM) i7-10700K CPU @ 3.80GHz

Cc: @kparzysz-quic , @vinx13 , @masahi , @driazati , @junrushao , @tqchen , @elvin-n , @vvchernov , @echuraev

Notes:

  • Could also relate to efforts in [target] Use native architecture for llvm target #14981
  • Adds ability to lookup pure CPU features instead, regardless the vendor code-names (e.g. AMD vs. Intel)
  • Adds ability to lookup and work with things regardless of platform flavors (e.g.: Darwin, Windows, etc)

@cbalint13 cbalint13 force-pushed the main branch 9 times, most recently from 7e0da36 to f8464c3 Compare October 10, 2023 13:53
Copy link
Contributor

@leandron leandron left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks @cbalint13

@masahi masahi merged commit ab1aef9 into apache:main Oct 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants