Skip to content

Commit

Permalink
Fix LL; parse args without regex
Browse files Browse the repository at this point in the history
  • Loading branch information
preda committed Jul 12, 2024
1 parent 82053b8 commit b11ca80
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 17 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ prp-*/
ll-*/
proof-*/
config.txt
txt/
11 changes: 9 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
# 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 -static-libstdc++ -static-libgcc
COMMON_FLAGS = -Wall -std=c++20
# -static-libstdc++ -static-libgcc
# -fext-numeric-literals


Expand All @@ -32,7 +33,9 @@ endif

SRCS1 = TuneEntry.cpp Primes.cpp tune.cpp CycleFile.cpp TrigBufCache.cpp Event.cpp Queue.cpp TimeInfo.cpp Profile.cpp bundle.cpp Saver.cpp SaveMan.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

SRCS=$(addprefix src/, $(SRCS1))
SRCS2 = test.cpp

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

OBJS = $(SRCS1:%.cpp=$(BIN)/%.o)
DEPDIR := $(BIN)/.d
Expand All @@ -47,6 +50,9 @@ prpll: $(BIN)/prpll

amd: $(BIN)/prpll-amd

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

$(BIN)/prpll: ${OBJS}
$(CXX) $(CXXFLAGS) -o $@ ${OBJS} $(LIBPATH) -lOpenCL ${STRIP}

Expand Down Expand Up @@ -80,3 +86,4 @@ src/version.inc: FORCE
FORCE:

include $(wildcard $(patsubst %,$(DEPDIR)/%.d,$(basename $(SRCS1))))
# include $(wildcard $(patsubst %,$(DEPDIR)/%.d,$(basename $(SRCS2))))
37 changes: 24 additions & 13 deletions src/Args.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

#include <vector>
#include <string>
#include <regex>
#include <cstring>
#include <cassert>
#include <cstdlib>
Expand All @@ -35,18 +34,30 @@ string Args::mergeArgs(int argc, char **argv) {
vector<KeyVal> Args::splitArgLine(const string& inputLine) {
vector<KeyVal> ret;

// The line must be ended with at least one space for the regex to function correctly.
string line = inputLine + ' ';
std::regex rx("\\s*(-+\\w+)\\s+([^-]\\S*)?\\s*([^-]*)");
for (std::sregex_iterator it(line.begin(), line.end(), rx); it != std::sregex_iterator(); ++it) {
smatch m = *it;
// printf("'%s' '%s' '%s'\n", m.str(1).c_str(), m.str(2).c_str(), m.str(3).c_str());
string prefix = m.prefix().str();
string suffix = m.str(3);
if (!prefix.empty()) { log("Args: unexpected '%s' before '%s'\n", prefix.c_str(), m.str(0).c_str()); }
if (!suffix.empty()) { log("Args: unexpected '%s' in '%s'\n", suffix.c_str(), m.str(0).c_str()); }
if (!prefix.empty() || !suffix.empty()) { throw "Argument syntax"; }
ret.push_back({m.str(1), m.str(2)});
string prev;
for (const string& s : split(inputLine, ' ')) {
if (s.empty()) { continue; }

if (prev.empty()) {
if (s[0] != '-') {
log("Args: expected '-' before '%s'\n", s.c_str());
throw "Argument syntax";
}

prev = s;
} else {
if (s[0] == '-') {
ret.push_back({prev, {}});
prev = s;
} else {
ret.push_back({prev, s});
prev.clear();
}
}
}
if (!prev.empty()) {
assert(prev[0] == '-');
ret.push_back({prev, {}});
}
return ret;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Gpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ class Gpu {

void carryFusedMul(Buffer<double>& a, Buffer<double>& b);

void carryFusedLL(Buffer<double>& a, Buffer<double>& b) { kCarryFusedLL(updateCarryPos(1<<0), a, b);}
void carryFusedLL(Buffer<double>& a, Buffer<double>& b) { kCarryFusedLL(a, b, updateCarryPos(1<<0));}

void writeIn(Buffer<int>& buf, const vector<u32> &words);

Expand Down
2 changes: 1 addition & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ int main(int argc, char **argv) {
gpuWorker(shared, &queues[0], 0);
}

log("No more work. Add work to worktodo.txt , see -h for details.\n");
// log("No more work. Add work to worktodo.txt , see -h for details.\n");
}
} catch (const char *mes) {
log("Exiting because \"%s\"\n", mes);
Expand Down

0 comments on commit b11ca80

Please sign in to comment.