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

Compile error on centos system #319

Open
mellonyou opened this issue Oct 20, 2022 · 18 comments
Open

Compile error on centos system #319

mellonyou opened this issue Oct 20, 2022 · 18 comments

Comments

@mellonyou
Copy link

Does anyone develop native code on Centos?

My ENV: Intel Xeon, Centos 8, Python 3.9.0, clang version 13.0.0, get some compile error with the latest code:
(py39_env) [eric@icx250 sonic]$ make
mkdir -p internal/native/avx/
echo '// Code generated by Makefile, DO NOT EDIT.' > internal/native/avx/native_amd64.go
echo >> internal/native/avx/native_amd64.go
sed -e 's/{{PACKAGE}}/avx/g' internal/native/native_amd64.tmpl >> internal/native/avx/native_amd64.go
mkdir -p output/avx
clang -mno-red-zone -fno-asynchronous-unwind-tables -fno-builtin -fno-exceptions -fno-rtti -fno-stack-protector -nostdlib -O3 -Wall -Werror -Wno-misleading-indentation -Wno-incompatible-pointer-types -msse -mno-sse4 -mavx -mno-avx2 -DUSE_AVX=1 -DUSE_AVX2=0 -S -o output/avx/native.s native/native.c
python3 tools/asm2asm/asm2asm.py internal/native/avx/native_amd64.s output/avx/native.s
Traceback (most recent call last):
File "/home/download/sonic_dir/sonic/tools/asm2asm/asm2asm.py", line 2132, in
main()
File "/home/download/sonic_dir/sonic/tools/asm2asm/asm2asm.py", line 2067, in main
asm.parse(src, proto)
File "/home/download/sonic_dir/sonic/tools/asm2asm/asm2asm.py", line 1979, in parse
self._parse(src)
File "/home/download/sonic_dir/sonic/tools/asm2asm/asm2asm.py", line 1857, in _parse
raise SyntaxError('invalid assembly command: ' + cmd.cmd)
SyntaxError: invalid assembly command: .text
make: *** [Makefile:108: internal/native/avx/native_amd64.s] Error 1

Is this a config problem, or the asm2asm.py just only support the assembly code compile from Mac OS?

@AsterDY
Copy link
Collaborator

AsterDY commented Oct 20, 2022

do you change native C code?

@mellonyou
Copy link
Author

I want to do some work on native code, but I can't compile successful before I do any change.

Just modify the Makefile for some compile errors:
(base) [eric@icx250 sonic]$ git diff Makefile
diff --git a/Makefile b/Makefile
index afe1b30..20192de 100644
--- a/Makefile
+++ b/Makefile
@@ -35,7 +35,7 @@ CC_amd64 := clang
ASM2ASM_amd64 := tools/asm2asm/asm2asm.py

CFLAGS := -mno-red-zone
-CFLAGS += -arch x86_64
+#CFLAGS += -arch x86_64
CFLAGS += -fno-asynchronous-unwind-tables
CFLAGS += -fno-builtin
CFLAGS += -fno-exceptions
@@ -43,7 +43,7 @@ CFLAGS += -fno-rtti
CFLAGS += -fno-stack-protector
CFLAGS += -nostdlib
CFLAGS += -O3
-CFLAGS += -Wall -Werror
+CFLAGS += -Wall -Werror -Wno-misleading-indentation -Wno-incompatible-pointer-types

@AsterDY
Copy link
Collaborator

AsterDY commented Oct 22, 2022

DONOT change any flags. At present, asm2asm only supports very limited ASM syntax, not including GOT、.text instruction ... etc —— In one word, you can only use it to write simple C functions, without gcc libs

@mellonyou
Copy link
Author

(base) [eric@icx250 sonic]$ make
mkdir -p internal/native/avx/
echo '// Code generated by Makefile, DO NOT EDIT.' > internal/native/avx/native_amd64.go
echo >> internal/native/avx/native_amd64.go
sed -e 's/{{PACKAGE}}/avx/g' internal/native/native_amd64.tmpl >> internal/native/avx/native_amd64.go
mkdir -p output/avx
clang -mno-red-zone -arch x86_64 -fno-asynchronous-unwind-tables -fno-builtin -fno-exceptions -fno-rtti -fno-stack-protector -nostdlib -O3 -Wall -Werror -msse -mno-sse4 -mavx -mno-avx2 -DUSE_AVX=1 -DUSE_AVX2=0 -S -o output/avx/native.s native/native.c
clang-13: error: argument unused during compilation: '-arch x86_64' [-Werror,-Wunused-command-line-argument]
make: *** [Makefile:107: internal/native/avx/native_amd64.s] Error 1

Do not change any word, get this error.
You do not have a Linux PC, and have a try?

@AsterDY
Copy link
Collaborator

AsterDY commented Oct 28, 2022

only use it on macOS and clang 12+

@PureWhiteWu
Copy link
Collaborator

Seems that this is because you have changed the makefile:
clang-13: error: argument unused during compilation: '-arch x86_64' [-Werror,-Wunused-command-line-argument]

@mellonyou
Copy link
Author

only use it on macOS and clang 12+

As a open source project, you'd better clarify this limitation in the readme.
Do you have the plans to support Linux OS recently?

@AsterDY
Copy link
Collaborator

AsterDY commented Oct 28, 2022

This is only used for our development, not for sonic's users. If you want to use asm2asm to develop your own code, you can submit issues on its repo. If you want develop sonic, you can contact us about your plan and we will see how it works

@mellonyou
Copy link
Author

I want to modify the native code with AVX512 and check the performance.

@AsterDY
Copy link
Collaborator

AsterDY commented Oct 31, 2022

Actually our team has tried this and it decreased the speed due to the CPU underclocking effects introduced by AVX512. You can just try it in C-code benchmark (like Google Test, etc.)

@mellonyou
Copy link
Author

Which CPU platform did you test on?

@mellonyou
Copy link
Author

As I know, on the latest Intel platform, Icelake or SPR, the problem of underclocking has been solved.
Could you upload the AVX512 code as a branch, I can do some tests on these platform to evaluate this problem.

@AsterDY
Copy link
Collaborator

AsterDY commented Nov 2, 2022

cc @PureWhiteWu @liuq19 @chenzhuoyu , any code left?

@Max-Cheng
Copy link

only use it on macOS and clang 12+

As a open source project, you'd better clarify this limitation in the readme. Do you have the plans to support Linux OS recently?

checkout this repo should be compile with clang on linux(arch).But asm2asm need further work

@liuq19
Copy link
Collaborator

liuq19 commented Nov 9, 2022

only use it on macOS and clang 12+

As a open source project, you'd better clarify this limitation in the readme. Do you have the plans to support Linux OS recently?

checkout this repo should be compile with clang on linux(arch).But asm2asm need further work

yeah, asm2asm does not works in Linux because of different asm syntax.

@Max-Cheng
Copy link

only use it on macOS and clang 12+

As a open source project, you'd better clarify this limitation in the readme. Do you have the plans to support Linux OS recently?

checkout this repo should be compile with clang on linux(arch).But asm2asm need further work

yeah, asm2asm does not works in Linux because of different asm syntax.

yep, I believe if we want sonic running on ARM we should spill the work to two-step.

  1. adaptation Sonic native code from Apple Clang to LLVM Clang(now we can compile with LLVM clang, But asm2asm needs further work)
  2. adaptations native code from AVX to NEON(adaptations ARM instruction set)
    All work needs to contribute asm2asm project, I'm working learn ATT assembly to plan9, but only a few documents of plan9 can be found.
    it maybe takes looong time.

@mellonyou
Copy link
Author

only use it on macOS and clang 12+

As a open source project, you'd better clarify this limitation in the readme. Do you have the plans to support Linux OS recently?

checkout this repo should be compile with clang on linux(arch).But asm2asm need further work

yeah, asm2asm does not works in Linux because of different asm syntax.

Any plan to support Linux?

@ii64
Copy link
Contributor

ii64 commented Feb 24, 2023

Perhaps using -ffreestanding and small reimplementation of STDC like eg. string.h would not work on freestanding?

Example
> clang -mno-red-zone -target x86_64-apple-macos11 -fno-asynchronous-unwind-tables -fno-builtin -fno-exceptions -fno-rtti -fno-stack-protector -nostdlib -O3 -Wall -Werror -msse -mno-sse4-mavx -mpclmul -mno-avx2 -DUSE_AVX=1 -DUSE_AVX2=0 -S -ffreestanding -o out_avx.s a.c
> cat out_avx.s
	.section	__TEXT,__text,regular,pure_instructions
	.build_version macos, 11, 0
	.globl	_go_reflect_tree                ## -- Begin function go_reflect_tree
	.p2align	4, 0x90
_go_reflect_tree:                       ## @go_reflect_tree
## %bb.0:
	pushq	%rbp
	movq	%rsp, %rbp
	xorl	%eax, %eax
	cmpq	$1, %rdi
	sbbl	%eax, %eax
	orl	$65535, %eax                    ## imm = 0xFFFF
	popq	%rbp
	retq
                                        ## -- End function
.subsections_via_symbols
> cat a.c
#include <stdint.h>
#include <immintrin.h>
//#include <string.h>

int go_reflect_tree(void* ptr)
{
	register int a = 0;
	if (ptr == 0) return -1;
	if ((uintptr_t)ptr & 0xff) a = 0xff;
	a |= 0xffff;
	return a;
}

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

No branches or pull requests

6 participants