You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fix stride indexing bugs in reorg and reorg_gradient functions (CPU & CUDA) (davisking#3012)
* Fix Stride Indexing Bugs in `reorg` and `reorg_gradient` Functions (CPU & CUDA) and Add `add_to` Parameter
* 'add_to' parameter missing in cuda call reorg_gradient.launch_kernel()
* Cleanup: remove using namespace std; (davisking#3016)
* remove using namespace std from headers
* more std::
* more std::
* more std:: on windows stuff
* remove uses of using namespace std::chrono
* do not use C++17 features
* Add Davis suggestion
* revert some more stuff
* revert removing include
* more std::chrono stuff
* fix build error
* Adjust comment formatting to be like other dlib comments
---------
Co-authored-by: Adrià <1671644+arrufat@users.noreply.github.com>
Co-authored-by: Davis King <davis@dlib.net>
DLIB_CASSERT(!is_same_object(grad, gradient_input), "Grad and gradient_input must be distinct objects.");
2390
+
DLIB_CASSERT(grad.nr() % row_stride == 0, "The number of rows in grad must be divisible by row_stride.");
2391
+
DLIB_CASSERT(grad.nc() % col_stride == 0, "The number of columns in grad must be divisible by col_stride.");
2392
+
DLIB_CASSERT(grad.num_samples() == gradient_input.num_samples(), "The number of samples in grad and gradient_input must match.");
2393
+
DLIB_CASSERT(grad.k() == gradient_input.k() / row_stride / col_stride, "The number of channels in grad must be gradient_input.k() divided by row_stride and col_stride.");
2394
+
DLIB_CASSERT(grad.nr() == gradient_input.nr() * row_stride, "The number of rows in grad must be gradient_input.nr() multiplied by row_stride.");
2395
+
DLIB_CASSERT(grad.nc() == gradient_input.nc() * col_stride, "The number of columns in grad must be gradient_input.nc() multiplied by col_stride.");
2396
+
2388
2397
constfloat* gi = gradient_input.host();
2389
2398
float* g = grad.host();
2390
2399
@@ -2396,13 +2405,15 @@ namespace dlib
2396
2405
{
2397
2406
for (long c = 0; c < gradient_input.nc(); ++c)
2398
2407
{
2399
-
constauto in_idx = tensor_index(gradient_input, n, k, r, c);
2400
-
constauto out_idx = tensor_index(grad,
2401
-
n,
2402
-
k % grad.k(),
2403
-
r * row_stride + (k / grad.k()) / row_stride,
2404
-
c * col_stride + (k / grad.k()) % col_stride);
2405
-
g[out_idx] += gi[in_idx];
2408
+
constauto in_idx = tensor_index(gradient_input, n, k, r, c);
DLIB_CASSERT(!is_same_object(grad, gradient_input), "Grad and gradient_input must be distinct objects.");
2079
+
DLIB_CASSERT(grad.nr() % row_stride == 0, "The number of rows in grad must be divisible by row_stride.");
2080
+
DLIB_CASSERT(grad.nc() % col_stride == 0, "The number of columns in grad must be divisible by col_stride.");
2081
+
DLIB_CASSERT(grad.num_samples() == gradient_input.num_samples(), "The number of samples in grad and gradient_input must match.");
2082
+
DLIB_CASSERT(grad.k() == gradient_input.k() / row_stride / col_stride, "The number of channels in grad must be gradient_input.k() divided by row_stride and col_stride.");
2083
+
DLIB_CASSERT(grad.nr() == gradient_input.nr() * row_stride, "The number of rows in grad must be gradient_input.nr() multiplied by row_stride.");
2084
+
DLIB_CASSERT(grad.nc() == gradient_input.nc() * col_stride, "The number of columns in grad must be gradient_input.nc() multiplied by col_stride.");
0 commit comments