jackmott / nim_simd

Nim experiment for a write once run optimum simd anywhere *at runtime* library
MIT License
30 stars 1 forks source link

simple.nim example does not detect SIMD type on OSX #4

Open sdwfrost opened 6 years ago

sdwfrost commented 6 years ago

simple.nim compiles and runs fine on my Ubuntu 16.04 box, but fails with the following under OSX, using either clang or gcc-7.

./simple
Illegal instruction: 4
jackmott commented 6 years ago

Thanks for testing that, probably something awry with CPU detection. what hardware is the osx box?

jackmott commented 6 years ago

Check out this post: https://stackoverflow.com/questions/14268887/what-is-the-illegal-instruction-4-error-and-why-does-mmacosx-version-min-10

Any chance that is relevant? Can you set minversion and resolve it?

sdwfrost commented 6 years ago

That didn't fix it. I get the same error on a Mac Pro (Late 2013), with 3 Ghz 8-core Intel Xeon E3, 64GB 1866 Mhz RAM, running OSX v 10.11.3 (El Capitan), as well as on a Mac Mini Server with El Capitan.

jackmott commented 6 years ago

I wonder if you put a bunch of echos in the cpu identification code to narrow down the LOC that causes the fault? I have no way to debug OSX issues from here

sdwfrost commented 6 years ago

The code compiles under debug:

Detected cpu type:SSE41
A + B = R
@[0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0, 15.0]
@[0.0, 2.0, 4.0, 6.0, 8.0, 10.0, 12.0, 14.0, 16.0, 18.0, 20.0, 22.0, 24.0, 26.0, 28.0, 30.0]
@[0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]

The error only comes with -d:release, in which case I can't even echo from the first line.

jackmott commented 6 years ago

@sdwfrost just wanted to let you know I am occasionally trying to figure this out as I have time. Been inquiring on the nim forums.

jackmott commented 6 years ago

@sdwfrost new version of nim, and all new cpu detection code! If you can get latest and try this with nim 0.18 and let me know what you get I would appreciate it.

sdwfrost commented 6 years ago

Hi @jackmott

The code doesn't compile under clang at all:

nim/nim_simd/examples/nimcache/nimsimd_nimsimd.c:120:20: error: expected '(' after 'asm'
                    __asm {
                          ^
1 error generated.

As before, the code compiles with gcc under debug, but I still get an illegal instruction with -d:release. I'm using 0.18.1.

ghost commented 6 years ago

@sdwfrost the error is here because Nim uses GCC-style assembly in its C files (if you embed ASM from nim)

jackmott commented 6 years ago

@Yardanico hmm, I'm trying to emit both styles of assembly depending on the C compiler used.

ghost commented 6 years ago

@jackmott well, IDK, but it doesn't work with clang

jackmott commented 6 years ago

I'll get clang set up and figure it out, thanks for the feedback!

jackmott commented 6 years ago

@Yardanico @sdwfrost fix for clang is in, got it working on ubuntu. Will be interesting to see if we still get the illegal instruction with it.

sdwfrost commented 6 years ago

Hi @jackmott The package now compiles with clang, but I still get the problem with -d:release where I get the illegal instruction (which I don't get with the debug build)

jackmott commented 6 years ago

I guess I have a 3rd excuse to buy a mac

ghost commented 6 years ago

@jackmott you can also try hackintosh :)

data-man commented 6 years ago

@jackmott Maybe these libraries will be useful for you: google/cpu_features tycho/cpuid mgorny/cpuid2cpuflags anrieff/libcpuid Maratyszcza/cpuinfo (x86/x86-64/ARM/ARM64, Linux/Windows/Android/macOS/iOS)

whiterock commented 6 years ago

@jackmott maybe the easiest option just from terminal with no dependencies (?): sysctl -a | grep machdep.cpu.leaf7_features and also sysctl -a | grep machdep.cpu.features