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

Better Multithreading #1

Open
wants to merge 64 commits into
base: multithreaded
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
37c73c8
Reverted last commit
Apr 14, 2020
33842ae
Removed multi-threading
Apr 14, 2020
70efe43
Removed multi-threading
Apr 14, 2020
5ef6afa
Better speed display
Apr 14, 2020
c3bdaf4
Multithreading
SeeSoftware Apr 14, 2020
e46949a
Update main.cu
SeeSoftware Apr 14, 2020
e3c51bb
Update main.cu
SeeSoftware Apr 14, 2020
29cb2ee
Update main.cu
SeeSoftware Apr 14, 2020
64b2a32
Update main.cu
SeeSoftware Apr 14, 2020
e49a7de
cleaning
SeeSoftware Apr 14, 2020
ab32d32
fix msvc defines
SeeSoftware Apr 14, 2020
a5b57b6
Update main.cu
SeeSoftware Apr 14, 2020
4c97933
Fix memory leak by balint
hube12 Apr 15, 2020
7656af9
Removed unnecessary heap allocation
human-0 Apr 15, 2020
5515755
Window fix
hube12 Apr 15, 2020
0e4be93
Fix looping counter (bad size)
hube12 Apr 15, 2020
39d3f25
Merge pull request #2 from human-0/master
BalintCsala Apr 15, 2020
393701d
Removed unneccessary delete[]
Apr 15, 2020
2f05ae7
Make nvcc shut up about printf wrong sizes
hube12 Apr 15, 2020
0b8b930
Unroll generateLeafPattern and only write 0, 4
riking Apr 15, 2020
d58ecd0
Remove pow2 check for random calls that are pow2
riking Apr 15, 2020
84fd744
Write all leaf results but keep unrolled
riking Apr 15, 2020
9a56170
Merge remote-tracking branch 'SeeSoftware/multithreaded' into mt-opt
riking Apr 15, 2020
46859f5
Merge pull request #4 from riking/patch-2
BalintCsala Apr 15, 2020
0843e79
Improve file write buffering
riking Apr 15, 2020
6be3645
Use wall clock time for progress reports
riking Apr 15, 2020
d7617e2
Merge branch 'wall-clock' into mt-opt
riking Apr 15, 2020
64e9469
fix compile for atomics
riking Apr 15, 2020
124e85f
Merge branch 'mt-opt'
riking Apr 15, 2020
4557a17
fixup to write buffer optimizations
riking Apr 15, 2020
b8756cb
Added uncheched mask for LCG modulo
human-0 Apr 15, 2020
9a22440
Removed extra calculations for ignored leaf results
human-0 Apr 15, 2020
d669226
Removed unnecessary leaf pattern generation
human-0 Apr 15, 2020
76bb4dd
Used lcg.combine to optimise skipping
human-0 Apr 15, 2020
7867d11
Merge pull request #6 from riking/wall-clock
hube12 Apr 15, 2020
165898d
Removed unecessary d
hube12 Apr 15, 2020
e48e71a
Create README.md
Earthcomputer Apr 15, 2020
70d6bfc
Merge branch 'master' of https://github.com/human-0/seed-reversal-mer…
Apr 15, 2020
69218f6
Merge branch 'human-0-master'
Apr 15, 2020
525099c
Merged #7
Apr 15, 2020
b821d83
Merge branch 'riking-mt-opt-pr'
Apr 15, 2020
98be03a
Revert "Multithreading + file write optimizations"
BalintCsala Apr 16, 2020
e6c5a23
Merge pull request #11 from pack-png-mods/revert-7-mt-opt-pr
BalintCsala Apr 16, 2020
a7cb803
static fix
Apr 13, 2020
f6cbf75
Revert balint synchronous to async
hube12 Apr 13, 2020
f1bf36e
Removed multi-threading
Apr 14, 2020
95cdfe5
Basic multithreading
hube12 Apr 13, 2020
e91a955
Removed extra calculations for ignored leaf results
human-0 Apr 15, 2020
672dc5a
Added multithreading
Apr 14, 2020
8d4827a
Multithreading
SeeSoftware Apr 14, 2020
db6f77c
Update main.cu
SeeSoftware Apr 14, 2020
b01493b
Update main.cu
SeeSoftware Apr 14, 2020
7d25308
Update main.cu
SeeSoftware Apr 14, 2020
0b9c358
Update main.cu
SeeSoftware Apr 14, 2020
eedfa08
cleaning
SeeSoftware Apr 14, 2020
f1c3fab
fix msvc defines
SeeSoftware Apr 14, 2020
2e0270e
Update main.cu
SeeSoftware Apr 14, 2020
55b1800
Improve file write buffering
riking Apr 15, 2020
babbd16
fix compile for atomics
riking Apr 15, 2020
7daf7be
fixup to write buffer optimizations
riking Apr 15, 2020
e55bb3c
Standardized
Apr 16, 2020
da00d60
lockfree thread loop
SeeSoftware Apr 17, 2020
e085773
Merge remote-tracking branch 'upstream/master' into multithreaded
SeeSoftware Apr 17, 2020
bbc13b6
lockfree thread loop
SeeSoftware Apr 17, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,11 @@ cmake-build-debug
*.txt
merged
*.out
program*
*.zip
/build
/cmake-build-*
/CMakeFiles
Makefile
*.cmake
*.cbp
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# seed-reversal-merged
A merged version of seed-reversal-gpu and seed-tester-native

This repository is part of the effort to reverse the seed of the pack.png image. For more information on how this code works, please refer to the relevant section in https://bit.ly/packpng-details
196 changes: 114 additions & 82 deletions generator.cpp
Original file line number Diff line number Diff line change
@@ -1,82 +1,114 @@
#include "generator.h"

#define WATERFALL_Z 10
#define TREE1_X -5 // Left tree on the image
#define TREE1_Z WATERFALL_Z - 8
#define TREE1_HEIGHT 5
#define TREE2_X -3 // right tree on the image
#define TREE2_Z WATERFALL_Z + 3
#define TREE2_HEIGHT 5

bool generator::ChunkGenerator::isValidTreeSpot(int treeX, int treeZ, bool firstTreeFound, bool secondTreeFound, int waterfallX)
{
if (treeZ >= WATERFALL_Z - 1 && treeZ <= WATERFALL_Z + 1 && treeX <= waterfallX - 3 && treeX >= waterfallX - 5)
return true;
if (!firstTreeFound) {
if (treeX >= waterfallX + TREE1_X - 1 && treeX <= waterfallX + TREE1_X + 1 && treeZ >= TREE1_Z - 1 && treeZ <= TREE1_Z + 1)
return true;
}
if (!secondTreeFound) {
if (treeX >= waterfallX + TREE2_X - 1 && treeX <= waterfallX + TREE2_X + 1 && treeZ >= TREE2_Z - 1 && treeZ <= TREE2_Z + 1)
return true;
}
return false;
}

bool *generator::ChunkGenerator::generateLeafPattern(random_math::JavaRand& random)
{
bool *out = new bool[16];
for (int32_t i = 0; i < 16; i++) {
out[i] = random.nextInt(2) != 0;
}
return out;
}

int32_t generator::ChunkGenerator::checkTrees(random_math::JavaRand& random, int32_t maxTreeCount, int waterfallX)
{
bool treesFound[2] = {false, false};
int8_t foundTreeCount = 0;
for (int i = 0; i <= maxTreeCount; ++i) {
int32_t treeX = random.nextInt(16);
int32_t treeZ = random.nextInt(16);
int32_t height = random.nextInt(3) + 4;
if (!treesFound[0] && treeX == waterfallX + TREE1_X && treeZ == TREE1_Z && height == TREE1_HEIGHT) {
delete[] generator::ChunkGenerator::generateLeafPattern(random);
foundTreeCount++;
treesFound[0] = true;
} else if (!treesFound[1] && treeX == waterfallX + TREE2_X && treeZ == TREE2_Z && height == TREE2_HEIGHT) {
bool *leafPattern = generateLeafPattern(random);
if (!leafPattern[0] && leafPattern[4]) {
foundTreeCount++;
treesFound[1] = true;
} else {
return -1;
}
delete[] leafPattern;
} else {
if (isValidTreeSpot(treeX, treeZ, treesFound[0], treesFound[1], waterfallX))
return -1;
}
if (foundTreeCount == 2)
return i;
}
return -1;
}

bool generator::ChunkGenerator::populate(int64_t chunkSeed, int waterfallX)
{
random_math::JavaRand random(advance_3759.next(chunkSeed), false);

int32_t maxBaseTreeCount = 12;
if (random.nextInt(10) == 0)
return false;

int uTrees = ChunkGenerator::checkTrees(random, maxBaseTreeCount, waterfallX);
return uTrees != -1;
}

void generator::ChunkGenerator::init()
{
generator::ChunkGenerator::advance_3759 = random_math::JavaRand::lcg.combine(3759);
}
random_math::LCG generator::ChunkGenerator::advance_3759(1, 1, 1);
#include "generator.h"

#define WATERFALL_Z 10
#define TREE1_X -5 // Left tree on the image
#define TREE1_Z WATERFALL_Z - 8
#define TREE1_HEIGHT 5
#define TREE2_X -3 // right tree on the image
#define TREE2_Z WATERFALL_Z + 3
#define TREE2_HEIGHT 5

bool generator::ChunkGenerator::isValidTreeSpot(int treeX, int treeZ, bool firstTreeFound, bool secondTreeFound, int waterfallX)
{
if (treeZ >= WATERFALL_Z - 1 && treeZ <= WATERFALL_Z + 1 && treeX <= waterfallX - 3 && treeX >= waterfallX - 5)
return true;
if (!firstTreeFound) {
if (treeX >= waterfallX + TREE1_X - 1 && treeX <= waterfallX + TREE1_X + 1 && treeZ >= TREE1_Z - 1 && treeZ <= TREE1_Z + 1)
return true;
}
if (!secondTreeFound) {
if (treeX >= waterfallX + TREE2_X - 1 && treeX <= waterfallX + TREE2_X + 1 && treeZ >= TREE2_Z - 1 && treeZ <= TREE2_Z + 1)
return true;
}
return false;
}

void generator::ChunkGenerator::generateLeafPattern(random_math::JavaRand& random, bool *out)
{
out[0] = random.nextIntPow2Unchecked(2) != 0;
out[1] = random.nextIntPow2Unchecked(2) != 0;
out[2] = random.nextIntPow2Unchecked(2) != 0;
out[3] = random.nextIntPow2Unchecked(2) != 0;
out[4] = random.nextIntPow2Unchecked(2) != 0;
out[5] = random.nextIntPow2Unchecked(2) != 0;
out[6] = random.nextIntPow2Unchecked(2) != 0;
out[7] = random.nextIntPow2Unchecked(2) != 0;
out[8] = random.nextIntPow2Unchecked(2) != 0;
out[9] = random.nextIntPow2Unchecked(2) != 0;
out[10] = random.nextIntPow2Unchecked(2) != 0;
out[11] = random.nextIntPow2Unchecked(2) != 0;
out[12] = random.nextIntPow2Unchecked(2) != 0;
out[13] = random.nextIntPow2Unchecked(2) != 0;
out[14] = random.nextIntPow2Unchecked(2) != 0;
out[15] = random.nextIntPow2Unchecked(2) != 0;
}

void generator::ChunkGenerator::ignoreLeafPattern(random_math::JavaRand& random)
{
random.advance(advance_16);
}

bool generator::ChunkGenerator::leafPatternNot0And4(random_math::JavaRand& random)
{
bool _0 = random.nextIntPow2Unchecked(2) != 0;
random.advance(advance_3);

bool _4 = random.nextIntPow2Unchecked(2) != 0;
random.advance(advance_11);


return !_0 && _4;
}

int32_t generator::ChunkGenerator::checkTrees(random_math::JavaRand& random, int32_t maxTreeCount, int waterfallX)
{
bool treesFound[2] = {false, false};
int8_t foundTreeCount = 0;
for (int i = 0; i <= maxTreeCount; ++i) {
int32_t treeX = random.nextIntPow2Unchecked(16);
int32_t treeZ = random.nextIntPow2Unchecked(16);
int32_t height = random.nextInt(3) + 4;
if (!treesFound[0] && treeX == waterfallX + TREE1_X && treeZ == TREE1_Z && height == TREE1_HEIGHT) {
ignoreLeafPattern(random);
foundTreeCount++;
treesFound[0] = true;
} else if (!treesFound[1] && treeX == waterfallX + TREE2_X && treeZ == TREE2_Z && height == TREE2_HEIGHT) {
if (leafPatternNot0And4(random)) {
foundTreeCount++;
treesFound[1] = true;
} else {
return -1;
}
} else {
if (isValidTreeSpot(treeX, treeZ, treesFound[0], treesFound[1], waterfallX))
return -1;
}
if (foundTreeCount == 2)
return i;
}
return -1;
}

bool generator::ChunkGenerator::populate(int64_t chunkSeed, int waterfallX)
{
random_math::JavaRand random(advance_3759.nextMaskableUnchecked(chunkSeed), false);

int32_t maxBaseTreeCount = 12;
if (random.nextInt(10) == 0)
return false;

int uTrees = ChunkGenerator::checkTrees(random, maxBaseTreeCount, waterfallX);
return uTrees != -1;
}

void generator::ChunkGenerator::init()
{
generator::ChunkGenerator::advance_3 = random_math::JavaRand::lcg.combine(3);
generator::ChunkGenerator::advance_11 = random_math::JavaRand::lcg.combine(11);
generator::ChunkGenerator::advance_16 = random_math::JavaRand::lcg.combine(16);
generator::ChunkGenerator::advance_3759 = random_math::JavaRand::lcg.combine(3759);
}
random_math::LCG generator::ChunkGenerator::advance_3(1, 1, 1);
random_math::LCG generator::ChunkGenerator::advance_11(1, 1, 1);
random_math::LCG generator::ChunkGenerator::advance_16(1, 1, 1);
random_math::LCG generator::ChunkGenerator::advance_3759(1, 1, 1);
55 changes: 30 additions & 25 deletions generator.h
Original file line number Diff line number Diff line change
@@ -1,25 +1,30 @@
#ifndef SEED_TESTER_GENERATOR_H
#define SEED_TESTER_GENERATOR_H

#include "random.h"
#include <cstdint>

namespace generator
{

class ChunkGenerator
{
private:
static bool isValidTreeSpot(int treeX, int treeZ, bool firstTreeFound, bool secondTreeFound, int waterfallX);
static bool *generateLeafPattern(random_math::JavaRand& random);
static int32_t checkTrees(random_math::JavaRand& random, int32_t maxTreeCount, int waterfallX);
public:
static void init();
static random_math::LCG advance_3759;
static bool populate(int64_t chunkSeed, int waterfallX);

};
}


#endif //SEED_TESTER_GENERATOR_H
#ifndef SEED_TESTER_GENERATOR_H
#define SEED_TESTER_GENERATOR_H

#include "random.h"
#include <cstdint>

namespace generator
{

class ChunkGenerator
{
private:
static bool isValidTreeSpot(int treeX, int treeZ, bool firstTreeFound, bool secondTreeFound, int waterfallX);
static void generateLeafPattern(random_math::JavaRand& random, bool *out);
static void ignoreLeafPattern(random_math::JavaRand& random);
static bool leafPatternNot0And4(random_math::JavaRand& random);
static int32_t checkTrees(random_math::JavaRand& random, int32_t maxTreeCount, int waterfallX);
public:
static void init();
static random_math::LCG advance_3;
static random_math::LCG advance_11;
static random_math::LCG advance_16;
static random_math::LCG advance_3759;
static bool populate(int64_t chunkSeed, int waterfallX);

};
}


#endif //SEED_TESTER_GENERATOR_H
Loading