greg7mdp/parallel-hashmap

Getting illegal instruction with simple example

Closed this issue · 1 comments

Hello, I compiled a simple test from a cloud instance (detail below), and tried to run on the same OS (ubuntu22.04 docker container) on my Intel Mac and encountered illegal instruction when I tried to use the std::mutex.

#include <fmt/core.h>
#include <fmt/format.h>
#include <parallel_hashmap/phmap.h>
#include <thread>
#include <mutex>

int main() {
    {
        fmt::print("hehe\n");
        // phmap test
        phmap::parallel_node_hash_map<int, int,
                        phmap::priv::hash_default_hash<size_t>,
                        phmap::priv::hash_default_eq<size_t>,
                        phmap::priv::Allocator<phmap::priv::Pair<const int, int>>,
                        1,
                        std::mutex> map;
        auto search_preassigned = [&](int i) {
            map[i] = i;
        };

        search_preassigned(1);
    }

    return 0;
}
root@88481476ae00:~# ./test
hehe
Illegal instruction

However if using the phmap::NullMutex we are fine:

#include <fmt/core.h>
#include <fmt/format.h>
#include <parallel_hashmap/phmap.h>
#include <thread>
#include <mutex>

int main() {
    {
        fmt::print("hehe\n");
        // phmap test
        phmap::parallel_node_hash_map<int, int,
                        phmap::priv::hash_default_hash<size_t>,
                        phmap::priv::hash_default_eq<size_t>,
                        phmap::priv::Allocator<phmap::priv::Pair<const int, int>>,
                        1,
                        phmap::NullMutex> map;
        auto search_preassigned = [&](int i) {
            map[i] = i;
        };

        search_preassigned(1);
    }

    return 0;
}
root@88481476ae00:~# ./test
hehe

On the other hand simply instantiating a mutex is fine without the error.

std::mutex m;

I'm using CMake 3.22.1 that came with ubuntu22.04 to compile it, C++17. No special flags like -mnative or -mavx2 are provided.

Cloud instance lscpu:

# lscpu
Architecture:            x86_64
  CPU op-mode(s):        32-bit, 64-bit
  Address sizes:         46 bits physical, 48 bits virtual
  Byte Order:            Little Endian
CPU(s):                  64
  On-line CPU(s) list:   0-63
Vendor ID:               GenuineIntel
  Model name:            Intel(R) Xeon(R) Platinum 8375C CPU @ 2.90GHz
    CPU family:          6
    Model:               106
    Thread(s) per core:  2
    Core(s) per socket:  32
    Socket(s):           1
    Stepping:            6
    BogoMIPS:            5799.96
    Flags:               fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss ht syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon
                         rep_good nopl xtopology nonstop_tsc cpuid aperfmperf tsc_known_freq pni pclmulqdq monitor ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_ti
                         mer aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch invpcid_single ssbd ibrs ibpb stibp ibrs_enhanced fsgsbase tsc_adjust bmi1 avx2 smep bmi2 er
                         ms invpcid avx512f avx512dq rdseed adx smap avx512ifma clflushopt clwb avx512cd sha_ni avx512bw avx512vl xsaveopt xsavec xgetbv1 xsaves wbnoinvd ida arat avx51
                         2vbmi pku ospke avx512_vbmi2 gfni vaes vpclmulqdq avx512_vnni avx512_bitalg tme avx512_vpopcntdq rdpid md_clear flush_l1d arch_capabilities
Virtualization features:
  Hypervisor vendor:     KVM
  Virtualization type:   full
Caches (sum of all):
  L1d:                   1.5 MiB (32 instances)
  L1i:                   1 MiB (32 instances)
  L2:                    40 MiB (32 instances)
  L3:                    54 MiB (1 instance)
NUMA:
  NUMA node(s):          1
  NUMA node0 CPU(s):     0-63
Vulnerabilities:
  Itlb multihit:         Not affected
  L1tf:                  Not affected
  Mds:                   Not affected
  Meltdown:              Not affected
  Mmio stale data:       Mitigation; Clear CPU buffers; SMT Host state unknown
  Retbleed:              Not affected
  Spec store bypass:     Mitigation; Speculative Store Bypass disabled via prctl and seccomp
  Spectre v1:            Mitigation; usercopy/swapgs barriers and __user pointer sanitization
  Spectre v2:            Mitigation; Enhanced IBRS, IBPB conditional, RSB filling
  Srbds:                 Not affected
  Tsx async abort:       Not affected

Intel Mac Ubuntu container lscpu:

# lscpu
Architecture:           x86_64
  CPU op-mode(s):       32-bit, 64-bit
  Address sizes:        39 bits physical, 48 bits virtual
  Byte Order:           Little Endian
CPU(s):                 12
  On-line CPU(s) list:  0-11
Vendor ID:              GenuineIntel
  Model name:           Intel(R) Core(TM) i9-9980HK CPU @ 2.40GHz
    CPU family:         6
    Model:              158
    Thread(s) per core: 1
    Core(s) per socket: 1
    Socket(s):          12
    Stepping:           13
    BogoMIPS:           4800.00
    Flags:              fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss ht pbe syscall nx pdpe1gb lm constant_tsc rep_good nopl
                        xtopology nonstop_tsc cpuid pni pclmulqdq dtes64 ds_cpl ssse3 sdbg fma cx16 xtpr pcid sse4_1 sse4_2 movbe popcnt aes xsave avx f16c rdrand hypervisor lahf_lm
                         abm 3dnowprefetch fsgsbase bmi1 avx2 bmi2 erms xsaveopt arat
Caches (sum of all):
  L1d:                  384 KiB (12 instances)
  L1i:                  384 KiB (12 instances)
  L2:                   3 MiB (12 instances)
  L3:                   192 MiB (12 instances)
Vulnerabilities:
  Itlb multihit:        KVM: Mitigation: VMX unsupported
  L1tf:                 Mitigation; PTE Inversion
  Mds:                  Vulnerable; SMT Host state unknown
  Meltdown:             Vulnerable
  Mmio stale data:      Vulnerable
  Spec store bypass:    Vulnerable
  Spectre v1:           Vulnerable: __user pointer sanitization and usercopy barriers only; no swapgs barriers
  Spectre v2:           Vulnerable, STIBP: disabled
  Srbds:                Unknown: Dependent on hypervisor status
  Tsx async abort:      Not affected

I think I did accidentally put -march=native as a compiler flag. Resolved.