Skip to content

Commit

Permalink
#37 Handle chunks of different sizes in filter_largest
Browse files Browse the repository at this point in the history
  • Loading branch information
carljohnsen committed Mar 20, 2024
1 parent 264ff1b commit db4940c
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/lib/cpp/cpu/connected_components.cc
Original file line number Diff line number Diff line change
Expand Up @@ -474,8 +474,9 @@ void filter_largest(const std::string &base_path, bool *__restrict__ mask, const
global_size = global_shape.z * global_shape.y * global_shape.x,
chunks = renames.size(),
largest_chunk = std::max(global_shape.z, (total_shape.z - (total_shape.z / global_shape.z) * global_shape.z) + global_shape.z),
chunk_size = largest_chunk * global_shape.y * global_shape.x,
aligned_chunk_size = (chunk_size / disk_block_size) * disk_block_size;
chunk_size = global_shape.z * global_shape.y * global_shape.x,
largest_chunk_size = largest_chunk * global_shape.y * global_shape.x,
aligned_chunk_size = ((largest_chunk_size + disk_block_size-1) / disk_block_size) * disk_block_size;

// Generate the paths to the different chunks
std::vector<std::string> paths(chunks);
Expand All @@ -486,7 +487,7 @@ void filter_largest(const std::string &base_path, bool *__restrict__ mask, const
int64_t *chunk = (int64_t *) aligned_alloc(disk_block_size, aligned_chunk_size * sizeof(int64_t));

for (int64_t i = 0; i < chunks; i++) {
int64_t this_chunk_size = (i == chunks-1) ? chunk_size - (chunks*chunk_size - global_size) : chunk_size;
int64_t this_chunk_size = (i == chunks-1) ? largest_chunk_size : chunk_size;

auto load_start = std::chrono::high_resolution_clock::now();
load_file(chunk, paths[i], 0, this_chunk_size);
Expand All @@ -507,6 +508,7 @@ void filter_largest(const std::string &base_path, bool *__restrict__ mask, const
auto filter_start = std::chrono::high_resolution_clock::now();

for (int64_t j = 0; j < this_chunk_size; j++) {
assert (i*global_size + j < (total_shape.z * total_shape.y * total_shape.x) && "Index out of bounds");
mask[i*global_size + j] = chunk[j] == largest;
}
auto filter_end = std::chrono::high_resolution_clock::now();
Expand Down

0 comments on commit db4940c

Please sign in to comment.