![]() |
Ansel 0.0
A darktable fork - bloat + design vision
|
#include "common/nn_model.h"#include "system/target_clones.h"#include <glib/gstdio.h>#include <json-glib/json-glib.h>#include <limits.h>#include <math.h>#include <stdint.h>#include <stdio.h>#include <stdlib.h>#include <string.h>Go to the source code of this file.
Data Structures | |
| struct | nn_conv_t |
| struct | nn_unet_t |
| struct | dt_nn_model_t |
| struct | nn_header_t |
| struct | dt_nn_cl_t |
Macros | |
| #define | NN_MAX_DEPTH 8 |
| #define | NN_MIN(a, b) |
| #define | NN_MAX_DEVICES 16 |
| #define | NN_OC_BLOCK 4 |
| #define | NN_LEDGER(delta) |
| #define | NN_CL_ALLOC(var, floats) |
| #define | NN_CL_FREE(var) |
Typedefs | |
| typedef struct nn_conv_t | nn_conv_t |
| typedef struct nn_unet_t | nn_unet_t |
| typedef struct nn_header_t | nn_header_t |
Functions | |
| void | dt_nn_set_allocator (dt_nn_alloc_f alloc_fn, dt_nn_free_f free_fn) |
| void | dt_nn_set_cancel (dt_nn_cancel_f cancel_fn) |
| static void * | _nn_alloc (size_t floats, int long_lived) |
| static void | _nn_free (void *p) |
| static void | _err (char *err, size_t err_len, const char *msg) |
| static int | _wire_conv (const nn_header_t *h, const char *prefix, int out_ch, int in_ch, int k, nn_conv_t *cv, char *err, size_t err_len) |
| static int | _wire_unet (const nn_header_t *h, const char *stage_prefix, int base, int depth, int in_ch, int out_ch, nn_unet_t *u, char *err, size_t err_len) |
| static int | _read_net_cfg (JsonObject *cfg, int out_ch_max, int *base, int *depth, int *in_ch, int *out_ch) |
| dt_nn_model_t * | dt_nn_model_load (const char *path, char *err, size_t err_len) |
| static void | dt_nn_model_free_cl (dt_nn_model_t *m) |
| void | dt_nn_model_free (dt_nn_model_t *m) |
| int | dt_nn_model_in_channels (const dt_nn_model_t *m) |
| int | dt_nn_model_out_channels (const dt_nn_model_t *m) |
| int | dt_nn_model_bin (const dt_nn_model_t *m, const int is_xtrans) |
| int | dt_nn_model_coarse_in_channels (const dt_nn_model_t *m) |
| int | dt_nn_model_coarse_out_channels (const dt_nn_model_t *m) |
| int | dt_nn_model_anchor (const dt_nn_model_t *m) |
| static int | _lcm (int a, int b) |
| int | dt_nn_model_alignment (const dt_nn_model_t *m) |
| static __DT_CLONE_TARGETS__ void | _conv2d (const nn_conv_t *cv, const float *in, int w, int h, int stride, int pad, float *out) |
| static __DT_CLONE_TARGETS__ void | _gelu (float *x, size_t n) |
| static size_t | _unet_peak_floats (const nn_unet_t *u, size_t wh, int cl_variant) |
| static float | _scratch_per_px (const dt_nn_model_t *m, int cl_variant) |
| float | dt_nn_unet_scratch_per_px (const dt_nn_model_t *m) |
| float | dt_nn_unet_scratch_per_px_cl (const dt_nn_model_t *m) |
| float | dt_nn_unet_scratch_maxblock_per_px (const dt_nn_model_t *m) |
| size_t | dt_nn_unet_scratch_bytes (const dt_nn_model_t *m, int width, int height) |
| static __DT_CLONE_TARGETS__ void | _conv2d_cat2 (const nn_conv_t *cv, const float *a, int in_ch_a, const float *b, int w, int h, float *out) |
| static int | _unet_forward (const nn_unet_t *u, const float *in, float *out, int width, int height, int residual_ch) |
| int | dt_nn_unet_apply (const dt_nn_model_t *m, const float *in, float *out, int width, int height) |
| int | dt_nn_unet_apply_stage (const dt_nn_model_t *m, int stage, const float *in, float *out, int width, int height, int apply_residual) |
| __DT_CLONE_TARGETS__ void | dt_nn_bin_planes (const float *planes, int pw, int ph, int bin, float *out_rgb, float *out_cnt) |
| __DT_CLONE_TARGETS__ void | dt_nn_upsample_nearest (const float *in, int ch, int w, int h, int factor, float *out) |
| dt_nn_cl_t * | dt_nn_cl_create (int program) |
| void | dt_nn_cl_destroy (dt_nn_cl_t *cl) |
| static cl_mem | _weights_cl (const dt_nn_model_t *m, int devid) |
| static int | _conv_cl (dt_nn_cl_t *cl, int devid, cl_mem weights, const float *blob_base, cl_mem in, cl_mem out, int w, int h, const nn_conv_t *cv, int stride, int pad, int do_gelu) |
| static int | _upsample_cl (dt_nn_cl_t *cl, int devid, cl_mem in, cl_mem out, int w, int h, int ch) |
| static int | _unet_forward_cl (const dt_nn_model_t *m, const nn_unet_t *u, dt_nn_cl_t *cl, int devid, cl_mem dev_in, cl_mem dev_out, int width, int height) |
| int | dt_nn_unet_apply_stage_cl (const dt_nn_model_t *m, int stage, dt_nn_cl_t *cl, int devid, cl_mem dev_in, cl_mem dev_out, int width, int height) |
Variables | |
| static dt_nn_alloc_f | _nn_alloc_fn = NULL |
| static dt_nn_free_f | _nn_free_fn = NULL |
| static dt_nn_cancel_f | _nn_cancel_fn = NULL |
| #define NN_CL_ALLOC | ( | var, | |
| floats ) |
Referenced by _unet_forward_cl().
| #define NN_CL_FREE | ( | var | ) |
Referenced by _unet_forward_cl().
| #define NN_LEDGER | ( | delta | ) |
Referenced by _unet_peak_floats().
| #define NN_MAX_DEPTH 8 |
Definition at line 33 of file nn_model.c.
Referenced by _read_net_cfg(), _unet_forward(), and _unet_forward_cl().
| #define NN_MAX_DEVICES 16 |
Definition at line 44 of file nn_model.c.
Referenced by _weights_cl(), and dt_nn_model_free_cl().
| #define NN_MIN | ( | a, | |
| b ) |
Definition at line 34 of file nn_model.c.
Referenced by _conv2d(), _conv2d_cat2(), _conv_cl(), _scratch_per_px(), dt_nn_unet_scratch_bytes(), and dt_nn_unet_scratch_maxblock_per_px().
| #define NN_OC_BLOCK 4 |
Definition at line 499 of file nn_model.c.
Referenced by _conv2d(), and _conv2d_cat2().
| typedef struct nn_conv_t nn_conv_t |
| typedef struct nn_header_t nn_header_t |
| typedef struct nn_unet_t nn_unet_t |
|
static |
Definition at line 520 of file nn_model.c.
References nn_conv_t::b, in, nn_conv_t::in_ch, k, nn_conv_t::k, memcpy(), NN_MIN, NN_OC_BLOCK, out, nn_conv_t::out_ch, r, nn_conv_t::w, w1, w2, and w3.
Referenced by _unet_forward().
|
static |
Definition at line 767 of file nn_model.c.
References nn_conv_t::b, nn_conv_t::in_ch, k, nn_conv_t::k, memcpy(), NN_MIN, NN_OC_BLOCK, out, nn_conv_t::out_ch, r, nn_conv_t::w, w1, w2, and w3.
Referenced by _unet_forward().
|
static |
Definition at line 1164 of file nn_model.c.
References nn_conv_t::b, dt_opencl_enqueue_kernel_2d_with_local(), dt_opencl_set_kernel_arg(), in, nn_conv_t::in_ch, nn_conv_t::k, dt_nn_cl_t::kernel_conv, dt_nn_cl_t::kernel_conv3x3, NN_MIN, out, nn_conv_t::out_ch, and nn_conv_t::w.
Referenced by _unet_forward_cl().
|
static |
Definition at line 116 of file nn_model.c.
Referenced by _wire_conv(), and dt_nn_model_load().
|
static |
|
static |
Definition at line 455 of file nn_model.c.
Referenced by dt_nn_model_alignment().
|
static |
Definition at line 107 of file nn_model.c.
References _nn_free_fn, and p.
Referenced by _unet_forward().
|
static |
Definition at line 232 of file nn_model.c.
References NN_MAX_DEPTH.
Referenced by dt_nn_model_load().
|
static |
Definition at line 696 of file nn_model.c.
References _unet_peak_floats(), m, and NN_MIN.
Referenced by dt_nn_unet_scratch_per_px(), and dt_nn_unet_scratch_per_px_cl().
|
static |
Definition at line 889 of file nn_model.c.
References _conv2d(), _conv2d_cat2(), _gelu(), _nn_alloc(), _nn_cancel_fn, _nn_free(), nn_unet_t::base, nn_unet_t::bot1, nn_unet_t::bot2, nn_unet_t::dec1, nn_unet_t::dec2, nn_unet_t::depth, nn_unet_t::down, DT_NN_CANCELLED, nn_unet_t::enc1, nn_unet_t::enc2, nn_unet_t::head, height, i, in, memcpy(), NN_MAX_DEPTH, out, nn_conv_t::out_ch, nn_unet_t::out_ch, nn_unet_t::up, v, and width.
Referenced by dt_nn_unet_apply(), and dt_nn_unet_apply_stage().
|
static |
Definition at line 1259 of file nn_model.c.
References _conv_cl(), _nn_cancel_fn, _upsample_cl(), _weights_cl(), nn_unet_t::base, nn_unet_t::bot1, nn_unet_t::bot2, cleanup(), nn_unet_t::dec1, nn_unet_t::dec2, nn_unet_t::depth, nn_unet_t::down, DT_NN_CANCELLED, dt_opencl_enqueue_copy_buffer_to_buffer(), dt_opencl_finish(), dt_opencl_release_mem_object(), nn_unet_t::enc1, nn_unet_t::enc2, nn_unet_t::head, height, i, m, NN_CL_ALLOC, NN_CL_FREE, NN_MAX_DEPTH, nn_conv_t::out_ch, nn_unet_t::up, v, and width.
Referenced by dt_nn_unet_apply_stage_cl().
|
static |
Definition at line 636 of file nn_model.c.
References nn_unet_t::base, nn_unet_t::depth, i, NN_LEDGER, and nn_unet_t::out_ch.
Referenced by _scratch_per_px(), and dt_nn_unet_scratch_bytes().
|
static |
Definition at line 1231 of file nn_model.c.
References ch, dt_opencl_enqueue_kernel_2d(), dt_opencl_set_kernel_arg(), in, dt_nn_cl_t::kernel_upsample, out, ROUNDUPDHT, and ROUNDUPDWD.
Referenced by _unet_forward_cl().
|
static |
Definition at line 1144 of file nn_model.c.
References dt_nn_model_t::cl_lock, dt_nn_model_t::dev_weights, dt_opencl_alloc_device_buffer(), dt_opencl_release_mem_object(), dt_opencl_write_buffer_to_device(), dt_pthread_mutex_lock(), dt_pthread_mutex_unlock(), m, and NN_MAX_DEVICES.
Referenced by _unet_forward_cl().
|
static |
Definition at line 134 of file nn_model.c.
References _err(), nn_conv_t::b, i, nn_conv_t::in_ch, k, nn_conv_t::k, n, name, nn_conv_t::out_ch, nn_header_t::payload, nn_header_t::payload_size, size, t, nn_header_t::tensors, and nn_conv_t::w.
Referenced by _wire_unet().
|
static |
Definition at line 187 of file nn_model.c.
References _wire_conv(), nn_unet_t::base, nn_unet_t::bot1, nn_unet_t::bot2, nn_unet_t::dec1, nn_unet_t::dec2, nn_unet_t::depth, nn_unet_t::down, nn_unet_t::enc1, nn_unet_t::enc2, nn_unet_t::head, i, nn_unet_t::in_ch, nn_unet_t::out_ch, and nn_unet_t::up.
Referenced by dt_nn_model_load().
| __DT_CLONE_TARGETS__ void dt_nn_bin_planes | ( | const float * | planes, |
| int | pw, | ||
| int | ph, | ||
| int | bin, | ||
| float * | out_rgb, | ||
| float * | out_cnt ) |
Definition at line 1057 of file nn_model.c.
Referenced by _k_bin_planes(), and main().
| dt_nn_cl_t * dt_nn_cl_create | ( | int | program | ) |
Definition at line 1123 of file nn_model.c.
References dt_opencl_create_kernel(), dt_nn_cl_t::kernel_conv, dt_nn_cl_t::kernel_conv3x3, and dt_nn_cl_t::kernel_upsample.
Referenced by init_global(), and main().
| void dt_nn_cl_destroy | ( | dt_nn_cl_t * | cl | ) |
Definition at line 1133 of file nn_model.c.
References dt_opencl_free_kernel(), dt_nn_cl_t::kernel_conv, dt_nn_cl_t::kernel_conv3x3, and dt_nn_cl_t::kernel_upsample.
Referenced by cleanup_global(), and main().
| int dt_nn_model_alignment | ( | const dt_nn_model_t * | m | ) |
Definition at line 468 of file nn_model.c.
References _lcm(), DT_NN_FUSION_COARSEST, and m.
Referenced by main(), process(), process_cl(), and tiling_callback().
| int dt_nn_model_anchor | ( | const dt_nn_model_t * | m | ) |
| int dt_nn_model_bin | ( | const dt_nn_model_t * | m, |
| const int | is_xtrans ) |
Definition at line 434 of file nn_model.c.
References m.
Referenced by main(), process(), process_cl(), and tiling_callback().
| int dt_nn_model_coarse_in_channels | ( | const dt_nn_model_t * | m | ) |
| int dt_nn_model_coarse_out_channels | ( | const dt_nn_model_t * | m | ) |
| void dt_nn_model_free | ( | dt_nn_model_t * | m | ) |
Definition at line 413 of file nn_model.c.
References dt_nn_model_free_cl(), dt_pthread_mutex_destroy(), and m.
Referenced by cleanup_global(), main(), and main().
|
static |
Definition at line 402 of file nn_model.c.
References d, dt_opencl_release_mem_object(), m, and NN_MAX_DEVICES.
Referenced by dt_nn_model_free().
| int dt_nn_model_in_channels | ( | const dt_nn_model_t * | m | ) |
Definition at line 424 of file nn_model.c.
References m.
Referenced by commit_params(), main(), main(), process(), process_cl(), and tiling_callback().
| dt_nn_model_t * dt_nn_model_load | ( | const char * | path, |
| char * | err, | ||
| size_t | err_len ) |
Definition at line 245 of file nn_model.c.
References _err(), _read_net_cfg(), _wire_unet(), dt_pthread_mutex_destroy(), dt_pthread_mutex_init(), f, m, and out.
Referenced by _get_custom_model(), _get_model(), main(), and main().
| int dt_nn_model_out_channels | ( | const dt_nn_model_t * | m | ) |
| void dt_nn_set_allocator | ( | dt_nn_alloc_f | alloc_fn, |
| dt_nn_free_f | free_fn ) |
Definition at line 77 of file nn_model.c.
References _nn_alloc_fn, and _nn_free_fn.
Referenced by cleanup_global(), and init_global().
| void dt_nn_set_cancel | ( | dt_nn_cancel_f | cancel_fn | ) |
Definition at line 86 of file nn_model.c.
References _nn_cancel_fn.
Referenced by cleanup_global(), and init_global().
| int dt_nn_unet_apply | ( | const dt_nn_model_t * | m, |
| const float * | in, | ||
| float * | out, | ||
| int | width, | ||
| int | height ) |
Definition at line 1039 of file nn_model.c.
References _unet_forward(), height, in, m, out, and width.
Referenced by main().
| int dt_nn_unet_apply_stage | ( | const dt_nn_model_t * | m, |
| int | stage, | ||
| const float * | in, | ||
| float * | out, | ||
| int | width, | ||
| int | height, | ||
| int | apply_residual ) |
| int dt_nn_unet_apply_stage_cl | ( | const dt_nn_model_t * | m, |
| int | stage, | ||
| dt_nn_cl_t * | cl, | ||
| int | devid, | ||
| cl_mem | dev_in, | ||
| cl_mem | dev_out, | ||
| int | width, | ||
| int | height ) |
Definition at line 1395 of file nn_model.c.
References _unet_forward_cl(), height, m, and width.
Referenced by main(), and process_cl().
| size_t dt_nn_unet_scratch_bytes | ( | const dt_nn_model_t * | m, |
| int | width, | ||
| int | height ) |
Definition at line 744 of file nn_model.c.
References _unet_peak_floats(), height, m, NN_MIN, and width.
| float dt_nn_unet_scratch_maxblock_per_px | ( | const dt_nn_model_t * | m | ) |
Definition at line 725 of file nn_model.c.
| float dt_nn_unet_scratch_per_px | ( | const dt_nn_model_t * | m | ) |
Definition at line 715 of file nn_model.c.
References _scratch_per_px(), and m.
Referenced by tiling_callback().
| float dt_nn_unet_scratch_per_px_cl | ( | const dt_nn_model_t * | m | ) |
Definition at line 720 of file nn_model.c.
References _scratch_per_px(), and m.
Referenced by tiling_callback().
| __DT_CLONE_TARGETS__ void dt_nn_upsample_nearest | ( | const float * | in, |
| int | ch, | ||
| int | w, | ||
| int | h, | ||
| int | factor, | ||
| float * | out ) |
|
static |
Definition at line 74 of file nn_model.c.
Referenced by _nn_alloc(), and dt_nn_set_allocator().
|
static |
Definition at line 84 of file nn_model.c.
Referenced by _unet_forward(), _unet_forward_cl(), and dt_nn_set_cancel().
|
static |
Definition at line 75 of file nn_model.c.
Referenced by _nn_free(), and dt_nn_set_allocator().