Skip to content

cpuinfo returns 0 for cpuinfo_get_l2_caches_count on some devices #4654

Open

Description

Activity

  1. added
    bug 🐞
    hal/cpu
    on Jan 28, 2021
  2. changed the title [-]Dylib driver creation fails on devices which report zero l2 caches through cpuinfo[/-] [+]cpuinfo returns 0 for cpuinfo_get_l2_caches_count on some devices[/+] on Jan 28, 2021
  3. benvanik commented on Jan 28, 2021

    @benvanik
    Collaborator

    Leaving this here for now as we are working around it by bailing to a fallback of 1 thread when this happens. If someone who has a machine that returns this they can debug on/file an upstream cpuinfo bug/etc that'd be helpful. Otherwise you get 1 thread :)

  4. removed their assignment
    on Jan 28, 2021
  5. added
    help wanted
    on Jan 28, 2021
  6. bjacob commented on Jan 29, 2021

    @bjacob
    Collaborator

    Notes:

    • It is common even for real CPUs (not just emulators) on the ARM architecture to have no L2 cache, either because they skip from L1 to L3 (typical on some phone-class cpus) or because they have nothing at all beyond L1 (for some microcontrolled CPUs).
    • Of course, when running on emulator, it's even more unsurprising that there would be 0 L2 cache.

    TLDR: this seems normal at both the qemu and cpuinfo level, and will happen not only on qemu.

  7. benvanik commented on Jan 29, 2021

    @benvanik
    Collaborator

    This is super useful information @bjacob - thanks! The current strategy (heh "strategy" is a stretch) is just a placeholder anyway - would love to sync more about reasonable defaults/specializations/etc and I was mostly just waiting until mahesh's queue is flushed with the linalg on tensors work so we have some parallel workloads and the CPU threading lands in the HAL rewrite so we'd have something concrete to talk about.

  8. bjacob commented on Jan 29, 2021

    @bjacob
    Collaborator

    no problem! whenever you want to get back to this, you could take a look at this code that I wrote with much help from Marat for ruy's needs --- It's not exactly the same as you're doing, but it does wrestle with a similar issue of using cpuinfo distinguishing shared vs non-shared ("local") caches:
    https://github.com/google/ruy/blob/2887692065c38ef6617f423feafc6b69dd0a0681/ruy/cpuinfo.cc#L42-L83
    the key part is this condition, which Marat wrote down for me:
    https://github.com/google/ruy/blob/2887692065c38ef6617f423feafc6b69dd0a0681/ruy/cpuinfo.cc#L59-L63
    With this logic, we detect which cache is effectively the last level of cache that is local to each processor, which would indeed be the L2 cache on a majority of current CPUs but would be the L1 cache when there is no L2 --- i.e. avoiding making any assumptions about level N cache being special for any particular value of N.

  9. benvanik commented on Jan 29, 2021

    @benvanik
    Collaborator

    That's fantastic code and effectively what I was reaching for when I originally wrote this and then punted on. I'll see if I can adapt that. Did you find any way to test that besides actually grabbing a device with certain characteristics? (it'd be cool if cpuinfo could mock out certain devices for testing - like "pretend you are X" - maybe it can?)

  10. bjacob commented on Jan 29, 2021

    @bjacob
    Collaborator

    Also note about ARM architecture CPUs: in addition to the above-mentioned case where there is no L2 cache, there are other CPUs with only L1 and L2, with the L2 cache being shared across cores!

    Maybe ask Marat directly about cpuinfo mocking - I don't know personally.

  11. bjacob commented on Jan 29, 2021

    @bjacob
    Collaborator

    Ah, cpuinfo does support mocking: in its public include/ directory, right besides cpuinfo.h, you got cpuinfo-mock.h:
    https://github.com/pytorch/cpuinfo/blob/master/include/cpuinfo-mock.h

  12. added a commit that references this issue on Jan 29, 2021
  13. moved this from Not Started to Backlog in (Deprecated) IREEon May 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug 🐞hal/cpuhelp wanted

    Type

    No type

    Projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions