Skip to content

Commit

Permalink
#5 Changed diffusion to work with uint16 instead of uint8
Browse files Browse the repository at this point in the history
  • Loading branch information
carljohnsen committed Apr 10, 2024
1 parent 0bb6cd3 commit d38fa70
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
10 changes: 5 additions & 5 deletions src/lib/cpp/gpu/diffusion.cc
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ namespace gpu {

void diffusion_step(const uint8_t *__restrict__ voxels, float *buf0, float *buf1, const shape_t &N, const float *__restrict__ kernel, const int64_t radius) {
for (int64_t dim = 0; dim < 3; dim++) {
diffusion_core(buf0, kernel, buf1, N, dim, radius, 0);
diffusion_core(buf0, kernel, buf1, N, dim, radius);
std::swap(buf0, buf1);
}
illuminate(voxels, buf0, N.z*N.y*N.x);
Expand All @@ -243,7 +243,7 @@ namespace gpu {
}
}

void diffusion_in_memory(const uint8_t *__restrict__ voxels, const shape_t &N, const float *__restrict__ kernel, const int64_t kernel_size, const int64_t repititions, uint8_t *__restrict__ output) {
void diffusion_in_memory(const uint8_t *__restrict__ voxels, const shape_t &N, const float *__restrict__ kernel, const int64_t kernel_size, const int64_t repititions, uint16_t *__restrict__ output) {
const int64_t
total_size = N.z*N.y*N.x,
radius = kernel_size / 2;
Expand All @@ -258,7 +258,7 @@ namespace gpu {
diffusion_step(voxels, buf0, buf1, N, kernel, radius);
std::swap(buf0, buf1);
}
convert_float_to_uint8(buf0, output, total_size);
convert_float_to_uint16(buf0, output, total_size);
}

delete[] buf0;
Expand Down Expand Up @@ -336,8 +336,8 @@ namespace gpu {
}
}

// Convert to uint8
convert_float_to_uint8(temp0, output_file, total_flat_size);
// Convert to uint16
convert_float_to_uint16(temp0, output_file, total_flat_size);

// Free memory
free(buf0);
Expand Down
2 changes: 1 addition & 1 deletion src/lib/cpp/include/diffusion.hh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace NS {
//void convert_uint8_to_float(const std::string &src, const std::string &dst, const int64_t total_flat_size);
//void diffusion(const std::string &input_file, const std::vector<float>& kernel, const std::string &output_file, const shape_t &total_shape, const shape_t &global_shape, const int64_t repititions, const bool verbose = false);
//void diffusion_core(const float *__restrict__ input, const float *__restrict__ kernel, float *__restrict__ output, const shape_t &N, const int64_t dim, const int64_t radius, const int64_t padding);
void diffusion_in_memory(const uint8_t *__restrict__ voxels, const shape_t &N, const double *__restrict__ kernel, const int64_t kernel_size, const int64_t repititions, uint8_t *__restrict__ output);
void diffusion_in_memory(const uint8_t *__restrict__ voxels, const shape_t &N, const double *__restrict__ kernel, const int64_t kernel_size, const int64_t repititions, uint16_t *__restrict__ output);
//void illuminate(const bool *__restrict__ mask, float *__restrict__ output, const int64_t local_flat_size);
//void store_mask(const float *__restrict__ input, bool *__restrict__ mask, const int64_t local_flat_size);
//void stage_to_device(float *__restrict__ stage, const float *__restrict__ src, const idx3drange &range, const shape_t &global_shape, const int64_t kernel_size);
Expand Down
2 changes: 1 addition & 1 deletion src/processing_steps/0900_generate_gauss_c.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
NA = np.newaxis

internal_type = np.float32
result_type = np.uint8
result_type = np.uint16

def toint(arr, dtype=np.uint8):
vmin, vmax = arr.min(), arr.max()
Expand Down
4 changes: 2 additions & 2 deletions src/pybind/diffusion-pybind.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

namespace python_api {

void diffusion_in_memory(const np_array<uint8_t> &np_voxels, const np_array<float> &np_kernel, np_array<uint8_t> &np_output, const int64_t repititions = 1) {
void diffusion_in_memory(const np_array<uint8_t> &np_voxels, const np_array<float> &np_kernel, np_array<uint16_t> &np_output, const int64_t repititions = 1) {
auto
voxels_info = np_voxels.request(),
kernel_info = np_kernel.request(),
output_info = np_output.request();

const uint8_t *voxels = static_cast<const uint8_t*>(voxels_info.ptr);
const float *kernel = static_cast<const float*>(kernel_info.ptr);
uint8_t *output = static_cast<uint8_t*>(output_info.ptr);
uint16_t *output = static_cast<uint16_t*>(output_info.ptr);

const shape_t N = {voxels_info.shape[0], voxels_info.shape[1], voxels_info.shape[2]};
const int64_t kernel_size = kernel_info.shape[0];
Expand Down

0 comments on commit d38fa70

Please sign in to comment.