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

feat : add argument numthreads #575

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 2 additions & 1 deletion Converter/include/chunker_countsort_laszip.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include "Vector3.h"
#include "Attributes.h"
#include "converter_utils.h"

using std::string;
using std::vector;
Expand All @@ -15,6 +16,6 @@ class State;

namespace chunker_countsort_laszip {

void doChunking(vector<Source> sources, string targetDir, Vector3 min, Vector3 max, State& state, Attributes outputAttributes);
void doChunking(vector<Source> sources, string targetDir, Vector3 min, Vector3 max, State& state, Attributes outputAttributes, Options& options);

}
2 changes: 2 additions & 0 deletions Converter/include/converter_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -173,4 +173,6 @@ struct Options {
bool noChunking = false;
bool noIndexing = false;

int numThreads = 0;

};
4 changes: 0 additions & 4 deletions Converter/include/indexer.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,6 @@ namespace indexer{
//constexpr int numFlushThreads = 36;
constexpr int maxPointsPerChunk = 10'000;

inline int numSampleThreads() {
return getCpuData().numProcessors;
}

struct Hierarchy {
int64_t stepSize = 0;
vector<uint8_t> buffer;
Expand Down
14 changes: 8 additions & 6 deletions Converter/src/chunker_countsort_laszip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,8 @@ namespace fs = std::filesystem;

namespace chunker_countsort_laszip {

auto numChunkerThreads = getCpuData().numProcessors;
auto numFlushThreads = getCpuData().numProcessors;

// auto numChunkerThreads = 1;
// auto numFlushThreads = 1;
auto numChunkerThreads = 0;
auto numFlushThreads = 0;

int maxPointsPerChunk = 5'000'000;
int gridSize = 128;
Expand Down Expand Up @@ -1183,10 +1180,15 @@ namespace chunker_countsort_laszip {
return {gridSize, lut};
}

void doChunking(vector<Source> sources, string targetDir, Vector3 min, Vector3 max, State& state, Attributes outputAttributes) {
void doChunking(vector<Source> sources, string targetDir, Vector3 min, Vector3 max, State& state, Attributes outputAttributes, Options& options) {

auto tStart = now();

numChunkerThreads = options.numThreads;
numFlushThreads = options.numThreads;
cout << "numChunkerThreads: " << numChunkerThreads << endl;
cout << "numFlushThreads: " << numFlushThreads << endl;

int64_t tmp = state.pointsTotal / 20;
maxPointsPerChunk = std::min(tmp, int64_t(10'000'000));
cout << "maxPointsPerChunk: " << maxPointsPerChunk << endl;
Expand Down
2 changes: 1 addition & 1 deletion Converter/src/indexer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1528,7 +1528,7 @@ void doIndexing(string targetDir, State& state, Options& options, Sampler& sampl
atomic_int64_t activeThreads = 0;
mutex mtx_nodes;
vector<shared_ptr<Node>> nodes;
TaskPool<Task> pool(numSampleThreads(), [&writeAndUnload, &state, &options, &activeThreads, tStart, &lastReport, &totalPoints, totalBytes, &pointsProcessed, chunks, &indexer, &nodes, &mtx_nodes, &sampler](auto task) {
TaskPool<Task> pool(options.numThreads, [&writeAndUnload, &state, &options, &activeThreads, tStart, &lastReport, &totalPoints, totalBytes, &pointsProcessed, chunks, &indexer, &nodes, &mtx_nodes, &sampler](auto task) {

auto chunk = task->chunk;
auto chunkRoot = make_shared<Node>(chunk->id, chunk->min, chunk->max);
Expand Down
17 changes: 13 additions & 4 deletions Converter/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ Options parseArguments(int argc, char** argv) {
args.addArgument("attributes", "Attributes in output file");
args.addArgument("generate-page,p", "Generate a ready to use web page with the given name");
args.addArgument("title", "Page title used when generating a web page");
args.addArgument("numthreads,t", "Number of concurrent threads to use (default to one thread per vcpu on host)");

if (args.has("help")) {
cout << "PotreeConverter <source> -o <outdir>" << endl;
Expand Down Expand Up @@ -115,6 +116,12 @@ Options parseArguments(int argc, char** argv) {
bool noChunking = args.has("no-chunking");
bool noIndexing = args.has("no-indexing");

auto cpuData = getCpuData();
int numThreads = cpuData.numProcessors;
if (args.has("numthreads")) {
numThreads = args.get("numthreads").as<int>();
}

Options options;
options.source = source;
options.outdir = outdir;
Expand All @@ -131,6 +138,8 @@ Options parseArguments(int argc, char** argv) {
options.noChunking = noChunking;
options.noIndexing = noIndexing;

options.numThreads = numThreads;

//cout << "flags: ";
//for (string flag : options.flags) {
// cout << flag << ", ";
Expand Down Expand Up @@ -346,7 +355,7 @@ void chunking(Options& options, vector<Source>& sources, string targetDir, Stats

if (options.chunkMethod == "LASZIP") {

chunker_countsort_laszip::doChunking(sources, targetDir, stats.min, stats.max, state, outputAttributes);
chunker_countsort_laszip::doChunking(sources, targetDir, stats.min, stats.max, state, outputAttributes, options);

} else if (options.chunkMethod == "LAS_CUSTOM") {

Expand Down Expand Up @@ -426,6 +435,7 @@ void createReport(Options& options, vector<Source> sources, string targetDir, St
cout << "throughput (MB/s) " << formatNumber(throughputMB) << "MB" << endl;
cout << "throughput (points/s) " << formatNumber(throughputP, 1) << "M" << endl;
cout << "output location: " << targetDir << endl;
cout << "#threads: " << formatNumber(options.numThreads) << endl;



Expand Down Expand Up @@ -496,12 +506,11 @@ int main(int argc, char** argv) {
auto exePath = fs::canonical(fs::absolute(argv[0])).parent_path().string();

launchMemoryChecker(2 * 1024, 0.1);
auto cpuData = getCpuData();

cout << "#threads: " << cpuData.numProcessors << endl;

auto options = parseArguments(argc, argv);

cout << "#threads: " << options.numThreads << endl;

auto [name, sources] = curateSources(options.source);
if (options.name.size() == 0) {
options.name = name;
Expand Down