nim_simd icon indicating copy to clipboard operation
nim_simd copied to clipboard

simple.nim example does not detect SIMD type on OSX

Open sdwfrost opened this issue 8 years ago • 18 comments

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

sdwfrost avatar Dec 20 '17 15:12 sdwfrost

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

jackmott avatar Dec 20 '17 15:12 jackmott

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?

jackmott avatar Dec 20 '17 16:12 jackmott

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.

sdwfrost avatar Dec 20 '17 18:12 sdwfrost

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

jackmott avatar Dec 20 '17 22:12 jackmott

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.

sdwfrost avatar Dec 21 '17 19:12 sdwfrost

@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 avatar Jan 12 '18 15:01 jackmott

@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.

jackmott avatar Mar 05 '18 22:03 jackmott

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.

sdwfrost avatar Mar 06 '18 09:03 sdwfrost

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

Yardanico avatar Mar 06 '18 12:03 Yardanico

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

jackmott avatar Mar 06 '18 12:03 jackmott

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

Yardanico avatar Mar 06 '18 12:03 Yardanico

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

jackmott avatar Mar 06 '18 12:03 jackmott

@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.

jackmott avatar Mar 06 '18 18:03 jackmott

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)

sdwfrost avatar Mar 06 '18 20:03 sdwfrost

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

jackmott avatar Mar 06 '18 21:03 jackmott

@jackmott you can also try hackintosh :)

Yardanico avatar Mar 06 '18 21:03 Yardanico

@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)

data-man avatar Mar 07 '18 02:03 data-man

@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

whiterock avatar May 27 '18 12:05 whiterock