Skip to content

Commit

Permalink
Meson build
Browse files Browse the repository at this point in the history
- tools/expand.py can take input/output files as arguments (for meson)
- tools/expand.py handles the C++ string wrapping
- drop int128 use
  • Loading branch information
preda committed May 5, 2022
1 parent e8c6b6a commit 07e05cb
Show file tree
Hide file tree
Showing 9 changed files with 78 additions and 23 deletions.
8 changes: 1 addition & 7 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,19 +1,12 @@
gpuowl
version.inc
*-wrap.cpp
*-wrap.cl
version.new
config.txt
gpuowl.log
worktodo.txt
results.txt
results.old
sent.txt
sent.old
*.owl
*.bak
*.o
*.so
tmp/
tmp?/
cuda/
Expand All @@ -31,3 +24,4 @@ comgr.log
\#*\#
trashbin
proof
build/
9 changes: 4 additions & 5 deletions Gpu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
#include <bitset>
#include <limits>
#include <iomanip>
#include <quadmath.h>

#ifndef M_PIl
#define M_PIl 3.141592653589793238462643383279502884L
Expand Down Expand Up @@ -73,8 +72,8 @@ pair<T, T> root1(u32 N, u32 k) {
assert(!(N&7));
assert(k <= N/8);
N /= 2;
__float128 angle = - M_PIq * k / N;
return {cosq(angle), sinq(angle)};
auto angle = - M_PIl * k / N;
return {cosl(angle), sinl(angle)};
}
}

Expand Down Expand Up @@ -143,12 +142,12 @@ u32 kAt(u32 H, u32 line, u32 col) { return (line + col * H) * 2; }

auto weight(u32 N, u32 E, u32 H, u32 line, u32 col, u32 rep) {
auto iN = 1 / (f128) N;
return exp2q(iN * extra(N, E, kAt(H, line, col) + rep));
return exp2l(iN * extra(N, E, kAt(H, line, col) + rep));
}

auto invWeight(u32 N, u32 E, u32 H, u32 line, u32 col, u32 rep) {
auto iN = 1 / (f128) N;
return exp2q(- iN * extra(N, E, kAt(H, line, col) + rep));
return exp2l(- iN * extra(N, E, kAt(H, line, col) + rep));
}

double boundUnderOne(double x) { return std::min(x, nexttoward(1, 0)); }
Expand Down
11 changes: 4 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ CXXFLAGS = -Wall -g -O3 -std=gnu++17

LIBPATH = -L/opt/rocm-5.1.1/opencl/lib -L/opt/rocm-4.0.0/opencl/lib -L/opt/rocm-3.3.0/opencl/lib/x86_64 -L/opt/rocm/opencl/lib -L/opt/rocm/opencl/lib/x86_64 -L/opt/amdgpu-pro/lib/x86_64-linux-gnu -L.

LDFLAGS = -lstdc++fs -lOpenCL -lgmp -pthread -lquadmath ${LIBPATH}
LDFLAGS = -lstdc++fs -lOpenCL -lgmp -pthread ${LIBPATH}

LINK = $(CXX) $(CXXFLAGS) -o $@ ${OBJS} ${LDFLAGS}

Expand All @@ -26,7 +26,7 @@ D: D.o Pm1Plan.o log.o common.o timeutil.o
$(CXX) -o $@ $^ ${LDFLAGS}

clean:
rm -f ${OBJS} gpuowl gpuowl-win.exe
rm -f ${OBJS} gpuowl gpuowl-win.exe gpuowl-wrap.cpp

%.o : %.cpp
%.o : %.cpp $(DEPDIR)/%.d gpuowl-wrap.cpp version.inc
Expand All @@ -41,11 +41,8 @@ version.inc: FORCE
diff -q -N version.new version.inc >/dev/null || mv version.new version.inc
echo Version: `cat version.inc`

gpuowl-expanded.cl: gpuowl.cl
python3 tools/expand.py < gpuowl.cl > gpuowl-expanded.cl

gpuowl-wrap.cpp: gpuowl-expanded.cl head.txt tail.txt
cat head.txt gpuowl-expanded.cl tail.txt > gpuowl-wrap.cpp
gpuowl-wrap.cpp: gpuowl.cl
python3 tools/expand.py < gpuowl.cl > gpuowl-wrap.cpp

FORCE:

Expand Down
24 changes: 23 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,35 @@ exponent and optionally the assignment ID (AID) from PrimeNet. The `PRPDC=` pref
* Run `gpuowl`. It prints progress report on stdout and in `gpuowl.log`, and writes result lines to `results.txt`
* Submit the result lines from `results.txt` to https://www.mersenne.org/manual_result/ manual testing.


## Build
To build simply invoke "`make`" (or look inside the Makefile for a manual build).

Prerequisites (please install these):
* the GNU Multiple Precision (GMP) 6.1 library `libgmp-dev`
* a C++20 compiler (e.g. GCC, Clang)
* an OpenCL implementation (which provides the **libOpenCL** library). Recommended: an AMD GPU with ROCm 1.7.

### Meson build
Example build steps on linux:
```
cd gpuowl
mkdir build
cd build
meson ..
ninja
```

What the previous commands do:
- go to gpuowl source directory
- create a subdirectory named "build"
- go to the build directory
- invoke meson, passing as argument the gpuowl source directory (.. in this situation)
- run ninja to build

### Make build
To build simply invoke "`make`" (or look inside the Makefile for a manual build).


## See \"`gpuowl -h`\" for the command line options.

## Self-test
Expand Down
1 change: 0 additions & 1 deletion head.txt

This file was deleted.

29 changes: 29 additions & 0 deletions meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# -*- mode:Python -*-

project('gpuowl', 'cpp', default_options:['cpp_std=c++17', 'buildtype=debugoptimized'])

vcs_tag(input:'version.inc.in', output:'version.inc')

python3 = import('python').find_installation('python3')
expander = find_program('./tools/expand.py')

wrap = generator(expander, output:'@[email protected]', arguments:['@INPUT@', '@OUTPUT@'])

gpuowl_wrap = wrap.process('gpuowl.cl')

srcs = 'ProofCache.cpp Proof.cpp Pm1Plan.cpp B1Accumulator.cpp Memlock.cpp log.cpp md5.cpp sha3.cpp AllocTrac.cpp GmpUtil.cpp FFTConfig.cpp Worktodo.cpp common.cpp main.cpp Gpu.cpp clwrap.cpp Task.cpp Saver.cpp timeutil.cpp Args.cpp state.cpp Signal.cpp'.split()

cpp = meson.get_compiler('cpp')
amdocl = cpp.find_library('amdocl64', dirs:['/opt/rocm-3.3.0/opencl/lib/x86_64', '/opt/rocm-5.1.1/opencl/lib', '/opt/rocm/opencl/lib'])


executable('gpuowl', sources: srcs + [gpuowl_wrap], dependencies:[amdocl, dependency('gmp')])


# Meson experiments below:

#executable('gpuowl', sources:srcs, link_with:[amdocl, dependency('gmp')])
# amdocl = declare_dependency(link_args : ['-L/opt/rocm-3.3.0/opencl/lib/x86_64', '-lamdocl64'])
# dependency('amdocl64')
# thread_dep = dependency('threads')
# gpuowl_wrap = custom_target('gpuowl_wrap', command:[python3, '@INPUT@', '@OUTPUT@'], input:['tools/expand.py', 'gpuowl.cl'], output:'gpuowl-wrap.cpp')
1 change: 0 additions & 1 deletion tail.txt

This file was deleted.

17 changes: 16 additions & 1 deletion tools/expand.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,23 @@

import sys

# If any arguments are passed, expect <input-file> <output-file>
# Otherwise read from stdin, write to stdout
if len(sys.argv) > 1:
assert len(sys.argv) == 3, f'Use: f{sys.argv[0]} <input-file> <output-file>'
sys.stdin = open(sys.argv[1])
sys.stdout = open(sys.argv[2], 'w')

HEAD = 'const char *CL_SOURCE = R"clsource('
TAIL = ')clsource";';

lineNo = 0
current = None
body = None
macros = {}

print(HEAD)

def err(text):
print(f'#{lineNo}', text, file=sys.stderr)
exit(1)
Expand Down Expand Up @@ -44,4 +56,7 @@ def err(text):
if current:
body += line
else:
print(line,end='')
print(line, end='')

print(TAIL)

1 change: 1 addition & 0 deletions version.inc.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"@VCS_TAG@"

0 comments on commit 07e05cb

Please sign in to comment.