preda / gpuowl

GPU Mersenne primality test.
GNU General Public License v3.0
127 stars 35 forks source link

OSX_Support :: MakeFile and File.h Updates #292

Open deacon-mp opened 1 week ago

deacon-mp commented 1 week ago

Makefile:: # Use "make DEBUG=1" for a debug build

# The build artifacts are put in the "build-release" subfolder (or "build-debug" for a debug build).

# Uncomment below as desired to set a particular compiler or force a debug build: # CXX = g++-12 # DEBUG = 1 # or export those into environment, or pass on the command line e.g. # make all DEBUG=1 CXX=g++-12

COMMON_FLAGS = -Wall -std=c++20 -v # -static-libstdc++ -static-libgcc # -fext-numeric-literals

ifeq ($(DEBUG), 1)

BIN=build-debug

CXXFLAGS = -g $(COMMON_FLAGS) STRIP=

else

BIN=build-release

CXXFLAGS = -O2 -DNDEBUG $(COMMON_FLAGS) STRIP=-s

endif

SRCS1 = fs.cpp TuneEntry.cpp Primes.cpp tune.cpp CycleFile.cpp TrigBufCache.cpp Event.cpp Queue.cppTimeInfo.cpp Profile.cpp bundle.cpp Saver.cpp KernelCompiler.cpp Kernel.cpp gpuid.cpp File.cpp Proof.cpp log.cpp Worktodo.cpp ``common.cpp main.cpp Gpu.cpp clwrap.cpp Task.cpp timeutil.cpp Args.cpp state.cpp Signal.cpp FFTConfig.cpp AllocTrac.cpp sha3.cpp md5.cpp version.cpp

SRCS2 = test.cpp

# SRCS=$(addprefix src/, $(SRCS1))

OBJS = $(SRCS1:%.cpp=$(BIN)/%.o) DEPDIR := $(BIN)/.d $(shell mkdir -p $(DEPDIR) >/dev/null) DEPFLAGS = -MT $@ -MMD -MP -MF $(DEPDIR)/$*.Td COMPILE.cc = $(CXX) $(DEPFLAGS) $(CXXFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c POSTCOMPILE = @mv -f $(DEPDIR)/$*.Td $(DEPDIR)/$*.d && touch $@

all: prpll

prpll: $(BIN)/prpll

amd: $(BIN)/prpll-amd

#$(BIN)/test: $(BIN)/test.o # $(CXX) $(CXXFLAGS) -o $@ $< $(LIBPATH) ${STRIP}

$(BIN)/prpll: ${OBJS} # $(CXX) $(CXXFLAGS) -o $@ ${OBJS} -lpthread -lOpenCL ${STRIP} $(CXX) $(CXXFLAGS) -o $@ ${OBJS} -lpthread -lOpenCL -lstdc++ ${STRIP}`

# Instead of linking with libOpenCL, link with libamdocl64 $(BIN)/prpll-amd: ${OBJS} $(CXX) $(CXXFLAGS) -o $@ ${OBJS} -lamdocl64 -L/opt/rocm/lib ${STRIP}

clean: rm -rf build-debug build-release

$(BIN)/%.o : src/%.cpp $(DEPDIR)/%.d $(COMPILE.cc) $(OUTPUT_OPTION) $< $(POSTCOMPILE)

# src/bundle.cpp is just a wrapping of the OpenCL sources (*.cl) as a C string.

src/bundle.cpp: genbundle.sh src/cl/*.cl ./genbundle.sh $^ > src/bundle.cpp

$(DEPDIR)/%.d: ; .PRECIOUS: $(DEPDIR)/%.d

#src/version.cpp : src/version.inc

src/version.inc: FORCE echo \"basename `git describe --tags --long --dirty --always --match v/prpll/*`\" > $(BIN)/version.new diff -q -N $(BIN)/version.new $@ >/dev/null || mv $(BIN)/version.new $@ echo Version:cat $@``

FORCE:

include $(wildcard $(patsubst %,$(DEPDIR)/%.d,$(basename $(SRCS1)))) # include $(wildcard $(patsubst %,$(DEPDIR)/%.d,$(basename $(SRCS2))))

src/File.h:: 58 | fsync(fileno(f));

preda commented 1 week ago

Please prepare a pull request with the diff.

proski commented 1 week ago

289 has a better fix for File.h. Please feel free to reuse. The rest of #289 is probably misguided and useless.

preda commented 1 week ago

In the end, does it run on MacOS? what hardware and OS version was it tested on?

proski commented 1 week ago

I was able to make prpll compile on MacOS with Apple Silicon, but it was failing to load the OpenCL code. I made bad hacks to work around the unsupported 80-bit long double. That should be fixable in principle, perhaps with an extra library. But I don't have time and expertise to fix the OpenCL code.

Even the latest XCode doesn't support C++20 filesystem operations, so I used gcc from Homebrew.

I can have a look at supporting Intel Macs, that might be easier.

proski commented 3 days ago

Things are much simpler on x86_64. I was able to make a cleaner PR #294 that doesn't attempt to support Apple Silicon. Something is still not working, but it fails much further down the road. It's even possible that everything would work with different hardware.