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

Unify makefiles for Linux and MacOS #17

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

proski
Copy link
Contributor

@proski proski commented Jan 6, 2025

Don't pass BITS to the compiler unless bitness is overridden.

Don't try to support generic Windows. MSYS has the install command, MSVC
doesn't use the Makefile.

Use the install command unconditionally. Make mfakto.ini writable when
installed.

Set the optimization flags based on whether the compiler is clang or
gcc, not based on the OS.

Compile C++ files with the C++ compiler.

Properly mark targets as phony, the syntax was incorrect. The "src/all"
file is not created anymore.

Don't override CFLAGS and LDFLAGS on MacOS in CI.

@proski
Copy link
Contributor Author

proski commented Jan 6, 2025

A bit more context beyond the commit description.

The difference between Linux and MacOS is not so big to have different build systems.

Having separate makefiles means that certain choices as hidden from view. For instance, some compiler flags are passed on Linux but not on MacOS. Having that logic in one file helps see the difference and why it's needed. Apparently it's because gcc on MacOS is actually clang, which doesn't understand some flags. Then the flags can be based on the compiler rather than on the OS. Somebody can install gcc on MacOS and use the flags supported by gcc.

@henning-gerhardt
Copy link
Contributor

henning-gerhardt commented Jan 8, 2025

I tried you changes in general they are working on Linux (Gentoo) without major issue. The only issue which I could found is that the optimized compile flags are not used in-depended of I use clang (version 19.1.4) or gcc (14.2.1):

  • with clang/clang++
mfakto/src $ make CC=clang CPP=clang++
clang   -Wall -O3 -funroll-loops -ffast-math -finline-functions -flto -I/opt/rocm/opencl/include  -c sieve.c -o sieve.o
clang   -Wall -O3 -funroll-loops -ffast-math -finline-functions -flto -I/opt/rocm/opencl/include -c timer.c -o timer.o
clang   -Wall -O3 -funroll-loops -ffast-math -finline-functions -flto -I/opt/rocm/opencl/include -c parse.c -o parse.o
clang   -Wall -O3 -funroll-loops -ffast-math -finline-functions -flto -I/opt/rocm/opencl/include -c read_config.c -o read_config.o
clang   -Wall -O3 -funroll-loops -ffast-math -finline-functions -flto -I/opt/rocm/opencl/include -c mfaktc.c -o mfaktc.o
clang   -Wall -O3 -funroll-loops -ffast-math -finline-functions -flto -I/opt/rocm/opencl/include -c checkpoint.c -o checkpoint.o
clang   -Wall -O3 -funroll-loops -ffast-math -finline-functions -flto -I/opt/rocm/opencl/include -c signal_handler.c -o signal_handler.o
clang   -Wall -O3 -funroll-loops -ffast-math -finline-functions -flto -I/opt/rocm/opencl/include -c filelocking.c -o filelocking.o
clang   -Wall -O3 -funroll-loops -ffast-math -finline-functions -flto -I/opt/rocm/opencl/include -c output.c -o output.o
clang++   -Wall -O3 -funroll-loops -ffast-math -finline-functions -flto -I/opt/rocm/opencl/include  -c mfakto.cpp -o mfakto.o
clang++   -Wall -O3 -funroll-loops -ffast-math -finline-functions -flto -I/opt/rocm/opencl/include  -c gpusieve.cpp -o gpusieve.o
clang++   -Wall -O3 -funroll-loops -ffast-math -finline-functions -flto -I/opt/rocm/opencl/include  -c perftest.cpp -o perftest.o
clang++   -Wall -O3 -funroll-loops -ffast-math -finline-functions -flto -I/opt/rocm/opencl/include  -c menu.cpp -o menu.o
menu.cpp:204:5: warning: ignoring return value of function declared with 'warn_unused_result' attribute [-Wunused-result]
  204 |     fgets(choice_string, 9, stdin); // std:cin does not allow empty input
      |     ^~~~~ ~~~~~~~~~~~~~~~~~~~~~~~
1 warning generated.
clang++   -Wall -O3 -funroll-loops -ffast-math -finline-functions -flto -I/opt/rocm/opencl/include  -c kbhit.cpp -o kbhit.o
kbhit.cpp:55:12: warning: ignoring return value of function declared with 'warn_unused_result' attribute [-Wunused-result]
   55 |     } else read(0,&ch,1);
      |            ^~~~ ~~~~~~~
1 warning generated.
clang++ sieve.o timer.o parse.o read_config.o mfaktc.o checkpoint.o signal_handler.o filelocking.o output.o mfakto.o gpusieve.o perftest.o menu.o kbhit.o    -O3 -funroll-loops -ffast-math -finline-functions -flto -L/opt/rocm/opencl/lib/x86_64 -lOpenCL -o ../mfakto
  • with gcc / g++
mfakto/src $ make CC=gcc CPP=g++ 
gcc   -Wall -O3 -funroll-loops -ffast-math -finline-functions -flto -I/opt/rocm/opencl/include  -c sieve.c -o sieve.o
gcc   -Wall -O3 -funroll-loops -ffast-math -finline-functions -flto -I/opt/rocm/opencl/include -c timer.c -o timer.o
gcc   -Wall -O3 -funroll-loops -ffast-math -finline-functions -flto -I/opt/rocm/opencl/include -c parse.c -o parse.o
gcc   -Wall -O3 -funroll-loops -ffast-math -finline-functions -flto -I/opt/rocm/opencl/include -c read_config.c -o read_config.o
gcc   -Wall -O3 -funroll-loops -ffast-math -finline-functions -flto -I/opt/rocm/opencl/include -c mfaktc.c -o mfaktc.o
gcc   -Wall -O3 -funroll-loops -ffast-math -finline-functions -flto -I/opt/rocm/opencl/include -c checkpoint.c -o checkpoint.o
gcc   -Wall -O3 -funroll-loops -ffast-math -finline-functions -flto -I/opt/rocm/opencl/include -c signal_handler.c -o signal_handler.o
gcc   -Wall -O3 -funroll-loops -ffast-math -finline-functions -flto -I/opt/rocm/opencl/include -c filelocking.c -o filelocking.o
gcc   -Wall -O3 -funroll-loops -ffast-math -finline-functions -flto -I/opt/rocm/opencl/include -c output.c -o output.o
g++   -Wall -O3 -funroll-loops -ffast-math -finline-functions -flto -I/opt/rocm/opencl/include  -c mfakto.cpp -o mfakto.o
mfakto.cpp: In function ‘int run_kernel15(cl_kernel, cl_uint, int75, int, cl_uint8, cl_mem, cl_int, cl_int)’:
mfakto.cpp:1804:5: note: the ABI for passing parameters with 32-byte alignment has changed in GCC 4.6
 1804 | int run_kernel15(cl_kernel l_kernel, cl_uint exp, int75 k_base, int stream, cl_uint8 b_in, cl_mem res, cl_int shiftcount, cl_int bin_max)
      |     ^~~~~~~~~~~~
g++   -Wall -O3 -funroll-loops -ffast-math -finline-functions -flto -I/opt/rocm/opencl/include  -c gpusieve.cpp -o gpusieve.o
g++   -Wall -O3 -funroll-loops -ffast-math -finline-functions -flto -I/opt/rocm/opencl/include  -c perftest.cpp -o perftest.o
g++   -Wall -O3 -funroll-loops -ffast-math -finline-functions -flto -I/opt/rocm/opencl/include  -c menu.cpp -o menu.o
menu.cpp: In function ‘void handle_menu(mystuff_t*)’:
menu.cpp:204:10: warning: ignoring return value of ‘char* fgets(char*, int, FILE*)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
  204 |     fgets(choice_string, 9, stdin); // std:cin does not allow empty input
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
g++   -Wall -O3 -funroll-loops -ffast-math -finline-functions -flto -I/opt/rocm/opencl/include  -c kbhit.cpp -o kbhit.o
kbhit.cpp: In member function ‘int keyboard::getch()’:
kbhit.cpp:55:16: warning: ignoring return value of ‘ssize_t read(int, void*, size_t)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   55 |     } else read(0,&ch,1);
      |            ~~~~^~~~~~~~~
g++ sieve.o timer.o parse.o read_config.o mfaktc.o checkpoint.o signal_handler.o filelocking.o output.o mfakto.o gpusieve.o perftest.o menu.o kbhit.o    -O3 -funroll-loops -ffast-math -finline-functions -flto -L/opt/rocm/opencl/lib/x86_64 -lOpenCL -o ../mfakto
lto-wrapper: warning: using serial compilation of 3 LTRANS jobs
lto-wrapper: note: see the ‘-flto’ option documentation for more information
mfakto.cpp: In function ‘run_kernel15’:
mfakto.cpp:1804:5: note: the ABI for passing parameters with 32-byte alignment has changed in GCC 4.6
 1804 | int run_kernel15(cl_kernel l_kernel, cl_uint exp, int75 k_base, int stream, cl_uint8 b_in, cl_mem res, cl_int shiftcount, cl_int bin_max)
      |     ^
mfakto.cpp: In function ‘run_gs_kernel15.isra’:
mfakto.cpp:2194:5: note: the ABI for passing parameters with 32-byte alignment has changed in GCC 4.6
 2194 | int run_gs_kernel15(cl_kernel kernel, cl_uint numblocks, cl_uint shared_mem_required, int75 k_base, cl_uint8 b_in, cl_uint shiftcount)
      |     ^

If I change line 72 in src/Makefile to ifeq ($(CC),clang) then building with clang/clang++ the not optimized flags will be used and if gcc/g++ is used then the high optimized flags are in use:

mfakto/src $ make CC=gcc CPP=g++
gcc   -Wall -O3 -funroll-loops -ffast-math -finline-functions -frerun-loop-opt -fgcse-sm -fgcse-las -flto -I/opt/rocm/opencl/include -funroll-all-loops -funsafe-loop-optimizations -fira-region=all -fsched-spec-load -fsched-stalled-insns=10 -fsched-stalled-insns-dep=10 -fno-align-labels -c sieve.c -o sieve.o
gcc   -Wall -O3 -funroll-loops -ffast-math -finline-functions -frerun-loop-opt -fgcse-sm -fgcse-las -flto -I/opt/rocm/opencl/include -c timer.c -o timer.o
gcc   -Wall -O3 -funroll-loops -ffast-math -finline-functions -frerun-loop-opt -fgcse-sm -fgcse-las -flto -I/opt/rocm/opencl/include -c parse.c -o parse.o
gcc   -Wall -O3 -funroll-loops -ffast-math -finline-functions -frerun-loop-opt -fgcse-sm -fgcse-las -flto -I/opt/rocm/opencl/include -c read_config.c -o read_config.o
gcc   -Wall -O3 -funroll-loops -ffast-math -finline-functions -frerun-loop-opt -fgcse-sm -fgcse-las -flto -I/opt/rocm/opencl/include -c mfaktc.c -o mfaktc.o
gcc   -Wall -O3 -funroll-loops -ffast-math -finline-functions -frerun-loop-opt -fgcse-sm -fgcse-las -flto -I/opt/rocm/opencl/include -c checkpoint.c -o checkpoint.o
gcc   -Wall -O3 -funroll-loops -ffast-math -finline-functions -frerun-loop-opt -fgcse-sm -fgcse-las -flto -I/opt/rocm/opencl/include -c signal_handler.c -o signal_handler.o
gcc   -Wall -O3 -funroll-loops -ffast-math -finline-functions -frerun-loop-opt -fgcse-sm -fgcse-las -flto -I/opt/rocm/opencl/include -c filelocking.c -o filelocking.o
gcc   -Wall -O3 -funroll-loops -ffast-math -finline-functions -frerun-loop-opt -fgcse-sm -fgcse-las -flto -I/opt/rocm/opencl/include -c output.c -o output.o
g++   -Wall -O3 -funroll-loops -ffast-math -finline-functions -frerun-loop-opt -fgcse-sm -fgcse-las -flto -I/opt/rocm/opencl/include  -c mfakto.cpp -o mfakto.o
mfakto.cpp: In function ‘int run_kernel15(cl_kernel, cl_uint, int75, int, cl_uint8, cl_mem, cl_int, cl_int)’:
mfakto.cpp:1804:5: note: the ABI for passing parameters with 32-byte alignment has changed in GCC 4.6
 1804 | int run_kernel15(cl_kernel l_kernel, cl_uint exp, int75 k_base, int stream, cl_uint8 b_in, cl_mem res, cl_int shiftcount, cl_int bin_max)
      |     ^~~~~~~~~~~~
g++   -Wall -O3 -funroll-loops -ffast-math -finline-functions -frerun-loop-opt -fgcse-sm -fgcse-las -flto -I/opt/rocm/opencl/include  -c gpusieve.cpp -o gpusieve.o
g++   -Wall -O3 -funroll-loops -ffast-math -finline-functions -frerun-loop-opt -fgcse-sm -fgcse-las -flto -I/opt/rocm/opencl/include  -c perftest.cpp -o perftest.o
g++   -Wall -O3 -funroll-loops -ffast-math -finline-functions -frerun-loop-opt -fgcse-sm -fgcse-las -flto -I/opt/rocm/opencl/include  -c menu.cpp -o menu.o
menu.cpp: In function ‘void handle_menu(mystuff_t*)’:
menu.cpp:204:10: warning: ignoring return value of ‘char* fgets(char*, int, FILE*)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
  204 |     fgets(choice_string, 9, stdin); // std:cin does not allow empty input
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
g++   -Wall -O3 -funroll-loops -ffast-math -finline-functions -frerun-loop-opt -fgcse-sm -fgcse-las -flto -I/opt/rocm/opencl/include  -c kbhit.cpp -o kbhit.o
kbhit.cpp: In member function ‘int keyboard::getch()’:
kbhit.cpp:55:16: warning: ignoring return value of ‘ssize_t read(int, void*, size_t)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   55 |     } else read(0,&ch,1);
      |            ~~~~^~~~~~~~~
g++ sieve.o timer.o parse.o read_config.o mfaktc.o checkpoint.o signal_handler.o filelocking.o output.o mfakto.o gpusieve.o perftest.o menu.o kbhit.o    -O3 -funroll-loops -ffast-math -finline-functions -frerun-loop-opt -fgcse-sm -fgcse-las -flto -L/opt/rocm/opencl/lib/x86_64 -lOpenCL -o ../mfakto
lto-wrapper: warning: using serial compilation of 3 LTRANS jobs
lto-wrapper: note: see the ‘-flto’ option documentation for more information
mfakto.cpp: In function ‘run_kernel15’:
mfakto.cpp:1804:5: note: the ABI for passing parameters with 32-byte alignment has changed in GCC 4.6
 1804 | int run_kernel15(cl_kernel l_kernel, cl_uint exp, int75 k_base, int stream, cl_uint8 b_in, cl_mem res, cl_int shiftcount, cl_int bin_max)
      |     ^
mfakto.cpp: In function ‘run_gs_kernel15.isra’:
mfakto.cpp:2194:5: note: the ABI for passing parameters with 32-byte alignment has changed in GCC 4.6
 2194 | int run_gs_kernel15(cl_kernel kernel, cl_uint numblocks, cl_uint shared_mem_required, int75 k_base, cl_uint8 b_in, cl_uint shiftcount)
      |     ^

@proski
Copy link
Contributor Author

proski commented Jan 9, 2025

I tried you changes in general they are working on Linux (Gentoo) without major issue. The only issue which I could found is that the optimized compile flags are not used in-depended of I use clang (version 19.1.4) or gcc (14.2.1):

Good catch! Thank you for testing! Indeed, I hardcoded gcc in the test, I'll fix it shortly.

@proski
Copy link
Contributor Author

proski commented Jan 9, 2025

Fixed broken compiler detection.

@henning-gerhardt
Copy link
Contributor

I tried your recent changes but it is on my Linux system still not working with gcc/g++ and clang/clang++. Even in the log files from the GitHub CI run it is visible that no optimization flags are used. It will use every time the last choice of the condition in line 89 and 90:

mfakto/src $ make CC=gcc CPP=g++
gcc   -Wall -O3 -I/opt/rocm/opencl/include  -c sieve.c -o sieve.o
gcc   -Wall -O3 -I/opt/rocm/opencl/include -c timer.c -o timer.o
gcc   -Wall -O3 -I/opt/rocm/opencl/include -c parse.c -o parse.o
gcc   -Wall -O3 -I/opt/rocm/opencl/include -c read_config.c -o read_config.o
read_config.c: In function ‘my_read_string’:
read_config.c:126:9: warning: ‘__builtin_strncpy’ specified bound depends on the length of the source argument [-Wstringop-truncation]
  126 |         strncpy(string, buf + idx + 1, found);
      |         ^
read_config.c:122:30: note: length computed here
  122 |       found = (unsigned int) strlen(buf + idx + 1);
      |                              ^~~~~~~~~~~~~~~~~~~~~
gcc   -Wall -O3 -I/opt/rocm/opencl/include -c mfaktc.c -o mfaktc.o
mfaktc.c: In function ‘find_fastest_kernel’:
mfaktc.c:543:29: warning: ‘test_use_kernel’ may be used uninitialized [-Wmaybe-uninitialized]
  543 |   if (do_test && use_kernel != test_use_kernel)
      |                  ~~~~~~~~~~~^~~~~~~~~~~~~~~~~~
mfaktc.c:519:54: note: ‘test_use_kernel’ was declared here
  519 |   GPUKernels         use_kernel = AUTOSELECT_KERNEL, test_use_kernel;
      |                                                      ^~~~~~~~~~~~~~~
gcc   -Wall -O3 -I/opt/rocm/opencl/include -c checkpoint.c -o checkpoint.o
gcc   -Wall -O3 -I/opt/rocm/opencl/include -c signal_handler.c -o signal_handler.o
gcc   -Wall -O3 -I/opt/rocm/opencl/include -c filelocking.c -o filelocking.o
gcc   -Wall -O3 -I/opt/rocm/opencl/include -c output.c -o output.o
output.c: In function ‘print_result_line’:
output.c:467:41: warning: ‘__builtin___sprintf_chk’ may write a terminating nul past the end of the destination [-Wformat-overflow=]
  467 |     sprintf(userjson, ", \"user\":\"%s\"", mystuff->V5UserID);
      |                                         ^
In file included from /usr/include/stdio.h:970,
                 from output.c:21:
In function ‘sprintf’,
    inlined from ‘print_result_line’ at output.c:467:5:
/usr/include/bits/stdio2.h:30:10: note: ‘__builtin___sprintf_chk’ output between 12 and 62 bytes into a destination of size 61
   30 |   return __builtin___sprintf_chk (__s, __USE_FORTIFY_LEVEL - 1,
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   31 |                                   __glibc_objsize (__s), __fmt,
      |                                   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   32 |                                   __va_arg_pack ());
      |                                   ~~~~~~~~~~~~~~~~~
output.c: In function ‘print_result_line’:
output.c:472:49: warning: ‘__builtin___sprintf_chk’ may write a terminating nul past the end of the destination [-Wformat-overflow=]
  472 |     sprintf(computerjson, ", \"computer\":\"%s\"", mystuff->ComputerID);
      |                                                 ^
In function ‘sprintf’,
    inlined from ‘print_result_line’ at output.c:472:5:
/usr/include/bits/stdio2.h:30:10: note: ‘__builtin___sprintf_chk’ output between 16 and 66 bytes into a destination of size 65
   30 |   return __builtin___sprintf_chk (__s, __USE_FORTIFY_LEVEL - 1,
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   31 |                                   __glibc_objsize (__s), __fmt,
      |                                   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   32 |                                   __va_arg_pack ());
      |                                   ~~~~~~~~~~~~~~~~~
output.c: In function ‘print_result_line’:
output.c:477:44: warning: ‘__builtin___sprintf_chk’ may write a terminating nul past the end of the destination [-Wformat-overflow=]
  477 |     sprintf(factorjson, ", \"factors\":[%s]", mystuff->factors_string);
      |                                            ^
In function ‘sprintf’,
    inlined from ‘print_result_line’ at output.c:477:5:
/usr/include/bits/stdio2.h:30:10: note: ‘__builtin___sprintf_chk’ output between 15 and 514 bytes into a destination of size 513
   30 |   return __builtin___sprintf_chk (__s, __USE_FORTIFY_LEVEL - 1,
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   31 |                                   __glibc_objsize (__s), __fmt,
      |                                   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   32 |                                   __va_arg_pack ());
      |                                   ~~~~~~~~~~~~~~~~~
g++   -Wall -O3 -I/opt/rocm/opencl/include  -c mfakto.cpp -o mfakto.o
mfakto.cpp: In function ‘int run_kernel15(cl_kernel, cl_uint, int75, int, cl_uint8, cl_mem, cl_int, cl_int)’:
mfakto.cpp:1804:5: note: the ABI for passing parameters with 32-byte alignment has changed in GCC 4.6
 1804 | int run_kernel15(cl_kernel l_kernel, cl_uint exp, int75 k_base, int stream, cl_uint8 b_in, cl_mem res, cl_int shiftcount, cl_int bin_max)
      |     ^~~~~~~~~~~~
g++   -Wall -O3 -I/opt/rocm/opencl/include  -c gpusieve.cpp -o gpusieve.o
g++   -Wall -O3 -I/opt/rocm/opencl/include  -c perftest.cpp -o perftest.o
perftest.cpp: In function ‘int test_gpu_sieve(cl_uint)’:
perftest.cpp:702:20: note: the ABI for passing parameters with 32-byte alignment has changed in GCC 4.6
  702 |     run_gs_kernel15(kernel_info[BARRETT69_MUL15_GS].kernel, mystuff.gpu_sieve_size / mystuff.gpu_sieve_processing_size, shared_mem_required, k_base, b_in, shiftcount);
      |     ~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/stdio.h:970,
                 from /usr/lib/gcc/x86_64-pc-linux-gnu/14/include/g++-v14/cstdio:42,
                 from /usr/lib/gcc/x86_64-pc-linux-gnu/14/include/g++-v14/ext/string_conversions.h:45,
                 from /usr/lib/gcc/x86_64-pc-linux-gnu/14/include/g++-v14/bits/basic_string.h:4154,
                 from /usr/lib/gcc/x86_64-pc-linux-gnu/14/include/g++-v14/string:54,
                 from /usr/lib/gcc/x86_64-pc-linux-gnu/14/include/g++-v14/bits/locale_classes.h:40,
                 from /usr/lib/gcc/x86_64-pc-linux-gnu/14/include/g++-v14/bits/ios_base.h:41,
                 from /usr/lib/gcc/x86_64-pc-linux-gnu/14/include/g++-v14/ios:44,
                 from /usr/lib/gcc/x86_64-pc-linux-gnu/14/include/g++-v14/ostream:40,
                 from /usr/lib/gcc/x86_64-pc-linux-gnu/14/include/g++-v14/iostream:41,
                 from perftest.cpp:24:
In function ‘int printf(const char*, ...)’,
    inlined from ‘GPUKernels test_cpu_tf_kernels(cl_uint)’ at perftest.cpp:1110:15:
/usr/include/bits/stdio2.h:118:23: warning: ‘ghz’ may be used uninitialized [-Wmaybe-uninitialized]
  118 |   return __printf_chk (__USE_FORTIFY_LEVEL - 1, __fmt, __va_arg_pack ());
      |          ~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
perftest.cpp: In function ‘GPUKernels test_cpu_tf_kernels(cl_uint)’:
perftest.cpp:883:62: note: ‘ghz’ was declared here
  883 |   double   time1, time2[UNKNOWN_KERNEL-_71BIT_MUL24], ghzdt, ghz;
      |                                                              ^~~
In function ‘int printf(const char*, ...)’,
    inlined from ‘GPUKernels test_gpu_tf_kernels(cl_uint)’ at perftest.cpp:1206:15:
/usr/include/bits/stdio2.h:118:23: warning: ‘ghz’ may be used uninitialized [-Wmaybe-uninitialized]
  118 |   return __printf_chk (__USE_FORTIFY_LEVEL - 1, __fmt, __va_arg_pack ());
      |          ~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
perftest.cpp: In function ‘GPUKernels test_gpu_tf_kernels(cl_uint)’:
perftest.cpp:1124:69: note: ‘ghz’ was declared here
 1124 |   double time1, time2[UNKNOWN_GS_KERNEL-BARRETT79_MUL32_GS], ghzdt, ghz;
      |                                                                     ^~~
perftest.cpp:1214:10: warning: ‘fastest_kernel’ may be used uninitialized [-Wmaybe-uninitialized]
 1214 |   return fastest_kernel;
      |          ^~~~~~~~~~~~~~
perftest.cpp:1131:14: note: ‘fastest_kernel’ was declared here
 1131 |   GPUKernels fastest_kernel;
      |              ^~~~~~~~~~~~~~
g++   -Wall -O3 -I/opt/rocm/opencl/include  -c menu.cpp -o menu.o
menu.cpp: In function ‘void handle_menu(mystuff_t*)’:
menu.cpp:204:10: warning: ignoring return value of ‘char* fgets(char*, int, FILE*)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
  204 |     fgets(choice_string, 9, stdin); // std:cin does not allow empty input
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
g++   -Wall -O3 -I/opt/rocm/opencl/include  -c kbhit.cpp -o kbhit.o
kbhit.cpp: In member function ‘int keyboard::getch()’:
kbhit.cpp:55:16: warning: ignoring return value of ‘ssize_t read(int, void*, size_t)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   55 |     } else read(0,&ch,1);
      |            ~~~~^~~~~~~~~
g++ sieve.o timer.o parse.o read_config.o mfaktc.o checkpoint.o signal_handler.o filelocking.o output.o mfakto.o gpusieve.o perftest.o menu.o kbhit.o    -O3 -L/opt/rocm/opencl/lib/x86_64 -lOpenCL -o ../mfakto

If I change line 82 in src/Makefile from ifneq (, $(findstring GCC, $(CC_VERSION))) to ifneq (, $(findstring gcc, $(CC_VERSION))) (lower case written gcc) then it is working for gcc/g++ and clang/clang++:

mfakto/src $ make CC=gcc CPP=g++
gcc   -Wall -O3 -funroll-loops -ffast-math -finline-functions -frerun-loop-opt -fgcse-sm -fgcse-las -flto -I/opt/rocm/opencl/include -funroll-all-loops -funsafe-loop-optimizations -fira-region=all -fsched-spec-load -fsched-stalled-insns=10 -fsched-stalled-insns-dep=10 -fno-align-labels -c sieve.c -o sieve.o
gcc   -Wall -O3 -funroll-loops -ffast-math -finline-functions -frerun-loop-opt -fgcse-sm -fgcse-las -flto -I/opt/rocm/opencl/include -c timer.c -o timer.o
gcc   -Wall -O3 -funroll-loops -ffast-math -finline-functions -frerun-loop-opt -fgcse-sm -fgcse-las -flto -I/opt/rocm/opencl/include -c parse.c -o parse.o
gcc   -Wall -O3 -funroll-loops -ffast-math -finline-functions -frerun-loop-opt -fgcse-sm -fgcse-las -flto -I/opt/rocm/opencl/include -c read_config.c -o read_config.o
gcc   -Wall -O3 -funroll-loops -ffast-math -finline-functions -frerun-loop-opt -fgcse-sm -fgcse-las -flto -I/opt/rocm/opencl/include -c mfaktc.c -o mfaktc.o
gcc   -Wall -O3 -funroll-loops -ffast-math -finline-functions -frerun-loop-opt -fgcse-sm -fgcse-las -flto -I/opt/rocm/opencl/include -c checkpoint.c -o checkpoint.o
gcc   -Wall -O3 -funroll-loops -ffast-math -finline-functions -frerun-loop-opt -fgcse-sm -fgcse-las -flto -I/opt/rocm/opencl/include -c signal_handler.c -o signal_handler.o
gcc   -Wall -O3 -funroll-loops -ffast-math -finline-functions -frerun-loop-opt -fgcse-sm -fgcse-las -flto -I/opt/rocm/opencl/include -c filelocking.c -o filelocking.o
gcc   -Wall -O3 -funroll-loops -ffast-math -finline-functions -frerun-loop-opt -fgcse-sm -fgcse-las -flto -I/opt/rocm/opencl/include -c output.c -o output.o
g++   -Wall -O3 -funroll-loops -ffast-math -finline-functions -frerun-loop-opt -fgcse-sm -fgcse-las -flto -I/opt/rocm/opencl/include  -c mfakto.cpp -o mfakto.o
mfakto.cpp: In function ‘int run_kernel15(cl_kernel, cl_uint, int75, int, cl_uint8, cl_mem, cl_int, cl_int)’:
mfakto.cpp:1804:5: note: the ABI for passing parameters with 32-byte alignment has changed in GCC 4.6
 1804 | int run_kernel15(cl_kernel l_kernel, cl_uint exp, int75 k_base, int stream, cl_uint8 b_in, cl_mem res, cl_int shiftcount, cl_int bin_max)
      |     ^~~~~~~~~~~~
g++   -Wall -O3 -funroll-loops -ffast-math -finline-functions -frerun-loop-opt -fgcse-sm -fgcse-las -flto -I/opt/rocm/opencl/include  -c gpusieve.cpp -o gpusieve.o
g++   -Wall -O3 -funroll-loops -ffast-math -finline-functions -frerun-loop-opt -fgcse-sm -fgcse-las -flto -I/opt/rocm/opencl/include  -c perftest.cpp -o perftest.o
g++   -Wall -O3 -funroll-loops -ffast-math -finline-functions -frerun-loop-opt -fgcse-sm -fgcse-las -flto -I/opt/rocm/opencl/include  -c menu.cpp -o menu.o
menu.cpp: In function ‘void handle_menu(mystuff_t*)’:
menu.cpp:204:10: warning: ignoring return value of ‘char* fgets(char*, int, FILE*)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
  204 |     fgets(choice_string, 9, stdin); // std:cin does not allow empty input
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
g++   -Wall -O3 -funroll-loops -ffast-math -finline-functions -frerun-loop-opt -fgcse-sm -fgcse-las -flto -I/opt/rocm/opencl/include  -c kbhit.cpp -o kbhit.o
kbhit.cpp: In member function ‘int keyboard::getch()’:
kbhit.cpp:55:16: warning: ignoring return value of ‘ssize_t read(int, void*, size_t)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   55 |     } else read(0,&ch,1);
      |            ~~~~^~~~~~~~~
g++ sieve.o timer.o parse.o read_config.o mfaktc.o checkpoint.o signal_handler.o filelocking.o output.o mfakto.o gpusieve.o perftest.o menu.o kbhit.o    -O3 -funroll-loops -ffast-math -finline-functions -frerun-loop-opt -fgcse-sm -fgcse-las -flto -L/opt/rocm/opencl/lib/x86_64 -lOpenCL -o ../mfakto
lto-wrapper: warning: using serial compilation of 3 LTRANS jobs
lto-wrapper: note: see the ‘-flto’ option documentation for more information
mfakto.cpp: In function ‘run_kernel15’:
mfakto.cpp:1804:5: note: the ABI for passing parameters with 32-byte alignment has changed in GCC 4.6
 1804 | int run_kernel15(cl_kernel l_kernel, cl_uint exp, int75 k_base, int stream, cl_uint8 b_in, cl_mem res, cl_int shiftcount, cl_int bin_max)
      |     ^
mfakto.cpp: In function ‘run_gs_kernel15.isra’:
mfakto.cpp:2194:5: note: the ABI for passing parameters with 32-byte alignment has changed in GCC 4.6
 2194 | int run_gs_kernel15(cl_kernel kernel, cl_uint numblocks, cl_uint shared_mem_required, int75 k_base, cl_uint8 b_in, cl_uint shiftcount)
      |     ^

Don't pass BITS to the compiler unless bitness is overridden.

Don't try to support generic Windows. MSYS has the install command, MSVC
doesn't use the Makefile.

Use the install command unconditionally. Make mfakto.ini writable when
installed.

Set the optimization flags based on whether the compiler is clang or
gcc, not based on the OS.

Compile C++ files with the C++ compiler.

Properly mark targets as phony, the syntax was incorrect. The "src/all"
file is not created anymore.

Don't override CFLAGS and LDFLAGS on MacOS in CI.
@proski
Copy link
Contributor Author

proski commented Jan 11, 2025

Fixed gcc detection on Ubuntu. Thank you, @henning-gerhardt!
Changed CI commands for MacOS so that clang specific flags are not lost.

@henning-gerhardt
Copy link
Contributor

Your recent changes are now working without any issue on my Linux system for gcc/g++ and clang/clang++. Results from GitHub CI execution looks even correct.

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

Successfully merging this pull request may close these issues.

2 participants