CoDiPack  3.1.0
A Code Differentiation Package
SciComp TU Kaiserslautern
Loading...
Searching...
No Matches
matrixMatrixMultiplication.hpp
1/*
2 * CoDiPack, a Code Differentiation Package
3 *
4 * Copyright (C) 2015-2026 Chair for Scientific Computing (SciComp), University of Kaiserslautern-Landau
5 * Homepage: http://scicomp.rptu.de
6 * Contact: Prof. Nicolas R. Gauger (codi@scicomp.uni-kl.de)
7 *
8 * Lead developers: Max Sagebaum, Johannes Blühdorn (SciComp, University of Kaiserslautern-Landau)
9 *
10 * This file is part of CoDiPack (http://scicomp.rptu.de/software/codi).
11 *
12 * CoDiPack is free software: you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation, either version 3 of the
15 * License, or (at your option) any later version.
16 *
17 * CoDiPack is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty
19 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
20 *
21 * See the GNU General Public License for more details.
22 * You should have received a copy of the GNU
23 * General Public License along with CoDiPack.
24 * If not, see <http://www.gnu.org/licenses/>.
25 *
26 * For other licensing options please contact us.
27 *
28 * Authors:
29 * - SciComp, University of Kaiserslautern-Landau:
30 * - Max Sagebaum
31 * - Johannes Blühdorn
32 * - Former members:
33 * - Tim Albring
34 */
35#pragma once
36
37#include <codi/config.h>
38
39#include <codi/misc/macros.hpp>
40#include <codi/tools/lowlevelFunctions/eigenWrappers.hpp>
41#include <codi/tools/lowlevelFunctions/generationHelperCoDiPack.hpp>
42#include <codi/tools/lowlevelFunctions/lowLevelFunctionCreationUtilities.hpp>
43
45namespace codi {
47 template<Eigen::StorageOptions eigenStore, typename Type>
49 using Real = typename Type::Real;
50 using Identifier = typename Type::Identifier;
54 using Tape = typename Type::Tape;
55
58
61
63 CODI_INLINE static void forward(Tape* tape, codi::ByteDataView& dataStore, AdjointVectorAccess adjoints) {
64 codi::TemporaryMemory& allocator = tape->getTemporaryMemory();
65 codiAssert(allocator.isEmpty()); // No memory should be allocated. We would free it at the end.
67
68 // Traits for arguments.
69 using Trait_A = typename LLFH::ActiveStoreTrait<Type*>;
70 using Trait_B = typename LLFH::ActiveStoreTrait<Type*>;
71 using Trait_R = typename LLFH::ActiveStoreTrait<Type*>;
72 using Trait_n = typename LLFH::PassiveStoreTrait<int, uint8_t>;
73 using Trait_k = typename LLFH::PassiveStoreTrait<int, uint8_t>;
74 using Trait_m = typename LLFH::PassiveStoreTrait<int, uint8_t>;
75
76 // Declare variables.
77 typename LLFH::ActivityStoreType activityStore = {};
78 typename Trait_A::ArgumentStore A_store = {};
79 typename Trait_B::ArgumentStore B_store = {};
80 typename Trait_R::ArgumentStore R_store = {};
81 typename Trait_n::Store n = {};
82 typename Trait_k::Store k = {};
83 typename Trait_m::Store m = {};
84
85 bool active_A = false;
86 bool active_B = false;
87
88 // Restore data.
89 LLFH::restoreActivity(&dataStore, activityStore);
90 active_A = LLFH::getActivity(activityStore, 0);
91 active_B = LLFH::getActivity(activityStore, 1);
92 Trait_n::restore(&dataStore, allocator, 1, true, n);
93 Trait_k::restore(&dataStore, allocator, 1, true, k);
94 Trait_m::restore(&dataStore, allocator, 1, true, m);
95 Trait_A::restore(&dataStore, allocator, n * k, LLFH::createRestoreActions(true, false, active_A, active_B),
96 A_store);
97 Trait_B::restore(&dataStore, allocator, k * m, LLFH::createRestoreActions(true, false, active_B, active_A),
98 B_store);
99 Trait_R::restore(&dataStore, allocator, n * m, LLFH::createRestoreActions(false, true, false, true), R_store);
100
101 if (Tape::HasPrimalValues) {
102 // Get primal values for inputs.
103 if (active_A && active_B) {
104 Trait_A::getPrimalsFromVector(adjoints, n * k, A_store.identifierIn(), A_store.primal());
105 }
106 if (active_B && active_A) {
107 Trait_B::getPrimalsFromVector(adjoints, k * m, B_store.identifierIn(), B_store.primal());
108 }
109 }
110
111 for (size_t curDim = 0; curDim < adjoints->getVectorSize(); curDim += 1) {
112 // Get input gradients.
113 if (active_A) {
114 Trait_A::getGradients(adjoints, n * k, false, A_store.identifierIn(), A_store.gradientIn(), curDim);
115 }
116 if (active_B) {
117 Trait_B::getGradients(adjoints, k * m, false, B_store.identifierIn(), B_store.gradientIn(), curDim);
118 }
119 if (Tape::HasPrimalValues && 0 == curDim) {
120 if (!Tape::LinearIndexHandling) {
121 // Update old primal values.
122 Trait_R::getPrimalsFromVector(adjoints, n * m, R_store.identifierOut(), R_store.oldPrimal());
123 }
124
125 // Set new primal values.
126 Trait_R::setPrimalsIntoVector(adjoints, n * m, R_store.identifierOut(), R_store.primal());
127 }
128
129 // Evaluate forward mode.
130 callForward(A_store.primal(), active_A, A_store.gradientIn(), B_store.primal(), active_B,
131 B_store.gradientIn(), R_store.primal(), R_store.gradientOut(), n, k, m);
132
133 Trait_R::setGradients(adjoints, n * m, false, R_store.identifierOut(), R_store.gradientOut(), curDim);
134 }
135
136 allocator.free();
137 }
138
140 CODI_INLINE static void callForward(typename codi::ActiveArgumentStoreTraits<Type*>::Real const* A, bool active_A,
142 typename codi::ActiveArgumentStoreTraits<Type*>::Real const* B, bool active_B,
149 codi::CODI_UNUSED(A, active_A, A_d_in, B, active_B, B_d_in, R, R_d_out, n, k, m);
150 if (active_A) {
151 mapEigen<eigenStore>(R_d_out, n, m) += mapEigen<eigenStore>(A_d_in, n, k) * mapEigen<eigenStore>(B, k, m);
152 }
153 if (active_B) {
154 mapEigen<eigenStore>(R_d_out, n, m) += mapEigen<eigenStore>(A, n, k) * mapEigen<eigenStore>(B_d_in, k, m);
155 }
157 }
158
160 CODI_INLINE static void reverse(Tape* tape, codi::ByteDataView& dataStore, AdjointVectorAccess adjoints) {
161 codi::TemporaryMemory& allocator = tape->getTemporaryMemory();
162 codiAssert(allocator.isEmpty()); // No memory should be allocated. We would free it at the end.
164
165 // Traits for arguments.
166 using Trait_A = typename LLFH::ActiveStoreTrait<Type*>;
167 using Trait_B = typename LLFH::ActiveStoreTrait<Type*>;
168 using Trait_R = typename LLFH::ActiveStoreTrait<Type*>;
169 using Trait_n = typename LLFH::PassiveStoreTrait<int, uint8_t>;
170 using Trait_k = typename LLFH::PassiveStoreTrait<int, uint8_t>;
171 using Trait_m = typename LLFH::PassiveStoreTrait<int, uint8_t>;
172
173 // Declare variables.
174 typename LLFH::ActivityStoreType activityStore = {};
175 typename Trait_A::ArgumentStore A_store = {};
176 typename Trait_B::ArgumentStore B_store = {};
177 typename Trait_R::ArgumentStore R_store = {};
178 typename Trait_n::Store n = {};
179 typename Trait_k::Store k = {};
180 typename Trait_m::Store m = {};
181
182 bool active_A = false;
183 bool active_B = false;
184
185 // Restore data.
186 LLFH::restoreActivity(&dataStore, activityStore);
187 active_A = LLFH::getActivity(activityStore, 0);
188 active_B = LLFH::getActivity(activityStore, 1);
189 Trait_n::restore(&dataStore, allocator, 1, true, n);
190 Trait_k::restore(&dataStore, allocator, 1, true, k);
191 Trait_m::restore(&dataStore, allocator, 1, true, m);
192 Trait_A::restore(&dataStore, allocator, n * k, LLFH::createRestoreActions(true, false, active_A, active_B),
193 A_store);
194 Trait_B::restore(&dataStore, allocator, k * m, LLFH::createRestoreActions(true, false, active_B, active_A),
195 B_store);
196 Trait_R::restore(&dataStore, allocator, n * m, LLFH::createRestoreActions(false, true, false, true), R_store);
197
198 if (Tape::HasPrimalValues) {
199 if (!Tape::LinearIndexHandling) {
200 // Restore old primal values from outputs.
201 Trait_R::setPrimalsIntoVector(adjoints, n * m, R_store.identifierOut(), R_store.oldPrimal());
202 }
203
204 // Get primal values for inputs.
205 if (active_A && active_B) {
206 Trait_A::getPrimalsFromVector(adjoints, n * k, A_store.identifierIn(), A_store.primal());
207 }
208 if (active_B && active_A) {
209 Trait_B::getPrimalsFromVector(adjoints, k * m, B_store.identifierIn(), B_store.primal());
210 }
211 }
212
213 for (size_t curDim = 0; curDim < adjoints->getVectorSize(); curDim += 1) {
214 // Get output gradients.
215 Trait_R::getGradients(adjoints, n * m, true, R_store.identifierOut(), R_store.gradientOut(), curDim);
216
217 // Evaluate reverse mode.
218 callReverse(A_store.primal(), active_A, A_store.gradientIn(), B_store.primal(), active_B,
219 B_store.gradientIn(), R_store.primal(), R_store.gradientOut(), n, k, m);
220
221 if (active_A) {
222 Trait_A::setGradients(adjoints, n * k, true, A_store.identifierIn(), A_store.gradientIn(), curDim);
223 }
224 if (active_B) {
225 Trait_B::setGradients(adjoints, k * m, true, B_store.identifierIn(), B_store.gradientIn(), curDim);
226 }
227 }
228
229 allocator.free();
230 }
231
233 CODI_INLINE static void callReverse(typename codi::ActiveArgumentStoreTraits<Type*>::Real const* A, bool active_A,
235 typename codi::ActiveArgumentStoreTraits<Type*>::Real const* B, bool active_B,
242 codi::CODI_UNUSED(A, active_A, A_b_in, B, active_B, B_b_in, R, R_b_out, n, k, m);
243 if (active_A) {
244 mapEigen<eigenStore>(A_b_in, n, k) =
245 mapEigen<eigenStore>(R_b_out, n, m) * mapEigen<eigenStore>(B, k, m).transpose();
246 }
247 if (active_B) {
248 mapEigen<eigenStore>(B_b_in, k, m) =
249 mapEigen<eigenStore>(A, n, k).transpose() * mapEigen<eigenStore>(R_b_out, n, m);
250 }
251 }
252
254 CODI_INLINE static void del(Tape* tape, codi::ByteDataView& dataStore) {
255 codi::TemporaryMemory& allocator = tape->getTemporaryMemory();
256 codiAssert(allocator.isEmpty()); // No memory should be allocated. We would free it at the end.
258
259 // Traits for arguments.
260 using Trait_A = typename LLFH::ActiveStoreTrait<Type*>;
261 using Trait_B = typename LLFH::ActiveStoreTrait<Type*>;
262 using Trait_R = typename LLFH::ActiveStoreTrait<Type*>;
263 using Trait_n = typename LLFH::PassiveStoreTrait<int, uint8_t>;
264 using Trait_k = typename LLFH::PassiveStoreTrait<int, uint8_t>;
265 using Trait_m = typename LLFH::PassiveStoreTrait<int, uint8_t>;
266
267 // Declare variables.
268 typename LLFH::ActivityStoreType activityStore = {};
269 typename Trait_A::ArgumentStore A_store = {};
270 typename Trait_B::ArgumentStore B_store = {};
271 typename Trait_R::ArgumentStore R_store = {};
272 typename Trait_n::Store n = {};
273 typename Trait_k::Store k = {};
274 typename Trait_m::Store m = {};
275
276 bool active_A = false;
277 bool active_B = false;
278
279 // Restore data.
280 LLFH::restoreActivity(&dataStore, activityStore);
281 active_A = LLFH::getActivity(activityStore, 0);
282 active_B = LLFH::getActivity(activityStore, 1);
283 Trait_n::restore(&dataStore, allocator, 1, true, n);
284 Trait_k::restore(&dataStore, allocator, 1, true, k);
285 Trait_m::restore(&dataStore, allocator, 1, true, m);
286 Trait_A::restore(&dataStore, allocator, n * k, LLFH::createRestoreActions(true, false, active_A, active_B),
287 A_store);
288 Trait_B::restore(&dataStore, allocator, k * m, LLFH::createRestoreActions(true, false, active_B, active_A),
289 B_store);
290 Trait_R::restore(&dataStore, allocator, n * m, LLFH::createRestoreActions(false, true, false, true), R_store);
291
292 allocator.free();
293 }
294
295 private:
296 CODI_INLINE static void iterateIds(Identifier* ids, size_t size, IterCallback func, void* userData) {
297 for (size_t i = 0; i < size; i += 1) {
298 func(&ids[i], userData);
299 }
300 }
301
302 public:
304 CODI_INLINE static void iterateInputs(Tape* tape, codi::ByteDataView& dataStore, IterCallback func,
305 void* userData) {
306 codi::TemporaryMemory& allocator = tape->getTemporaryMemory();
307 codiAssert(allocator.isEmpty()); // No memory should be allocated. We would free it at the end.
309
310 // Traits for arguments.
311 using Trait_A = typename LLFH::ActiveStoreTrait<Type*>;
312 using Trait_B = typename LLFH::ActiveStoreTrait<Type*>;
313 using Trait_R = typename LLFH::ActiveStoreTrait<Type*>;
314 using Trait_n = typename LLFH::PassiveStoreTrait<int, uint8_t>;
315 using Trait_k = typename LLFH::PassiveStoreTrait<int, uint8_t>;
316 using Trait_m = typename LLFH::PassiveStoreTrait<int, uint8_t>;
317
318 // Declare variables.
319 typename LLFH::ActivityStoreType activityStore = {};
320 typename Trait_A::ArgumentStore A_store = {};
321 typename Trait_B::ArgumentStore B_store = {};
322 typename Trait_R::ArgumentStore R_store = {};
323 typename Trait_n::Store n = {};
324 typename Trait_k::Store k = {};
325 typename Trait_m::Store m = {};
326
327 bool active_A = false;
328 bool active_B = false;
329
330 // Restore data.
331 LLFH::restoreActivity(&dataStore, activityStore);
332 active_A = LLFH::getActivity(activityStore, 0);
333 active_B = LLFH::getActivity(activityStore, 1);
334 Trait_n::restore(&dataStore, allocator, 1, true, n);
335 Trait_k::restore(&dataStore, allocator, 1, true, k);
336 Trait_m::restore(&dataStore, allocator, 1, true, m);
337 Trait_A::restore(&dataStore, allocator, n * k, LLFH::createRestoreActions(true, false, active_A, active_B),
338 A_store);
339 Trait_B::restore(&dataStore, allocator, k * m, LLFH::createRestoreActions(true, false, active_B, active_A),
340 B_store);
341 Trait_R::restore(&dataStore, allocator, n * m, LLFH::createRestoreActions(false, true, false, true), R_store);
342
343 if (active_A) {
344 iterateIds(A_store.identifierIn(), n * k, func, userData);
345 }
346 if (active_B) {
347 iterateIds(B_store.identifierIn(), k * m, func, userData);
348 }
349
350 allocator.free();
351 }
352
354 CODI_INLINE static void iterateOutputs(Tape* tape, codi::ByteDataView& dataStore, IterCallback func,
355 void* userData) {
356 codi::TemporaryMemory& allocator = tape->getTemporaryMemory();
357 codiAssert(allocator.isEmpty()); // No memory should be allocated. We would free it at the end.
359
360 // Traits for arguments.
361 using Trait_A = typename LLFH::ActiveStoreTrait<Type*>;
362 using Trait_B = typename LLFH::ActiveStoreTrait<Type*>;
363 using Trait_R = typename LLFH::ActiveStoreTrait<Type*>;
364 using Trait_n = typename LLFH::PassiveStoreTrait<int, uint8_t>;
365 using Trait_k = typename LLFH::PassiveStoreTrait<int, uint8_t>;
366 using Trait_m = typename LLFH::PassiveStoreTrait<int, uint8_t>;
367
368 // Declare variables.
369 typename LLFH::ActivityStoreType activityStore = {};
370 typename Trait_A::ArgumentStore A_store = {};
371 typename Trait_B::ArgumentStore B_store = {};
372 typename Trait_R::ArgumentStore R_store = {};
373 typename Trait_n::Store n = {};
374 typename Trait_k::Store k = {};
375 typename Trait_m::Store m = {};
376
377 bool active_A = false;
378 bool active_B = false;
379
380 // Restore data.
381 LLFH::restoreActivity(&dataStore, activityStore);
382 active_A = LLFH::getActivity(activityStore, 0);
383 active_B = LLFH::getActivity(activityStore, 1);
384 Trait_n::restore(&dataStore, allocator, 1, true, n);
385 Trait_k::restore(&dataStore, allocator, 1, true, k);
386 Trait_m::restore(&dataStore, allocator, 1, true, m);
387 Trait_A::restore(&dataStore, allocator, n * k, LLFH::createRestoreActions(true, false, active_A, active_B),
388 A_store);
389 Trait_B::restore(&dataStore, allocator, k * m, LLFH::createRestoreActions(true, false, active_B, active_A),
390 B_store);
391 Trait_R::restore(&dataStore, allocator, n * m, LLFH::createRestoreActions(false, true, false, true), R_store);
392
393 iterateIds(R_store.identifierOut(), n * m, func, userData);
394
395 allocator.free();
396 }
397
399 CODI_INLINE static void evalAndStore(Type const* A, Type const* B, Type* R, int n, int k, int m) {
400 Tape& tape = Type::getTape();
401 codi::TemporaryMemory& allocator = tape.getTemporaryMemory();
403
404 // Traits for arguments.
405 using Trait_A = typename LLFH::ActiveStoreTrait<Type*>;
406 using Trait_B = typename LLFH::ActiveStoreTrait<Type*>;
407 using Trait_R = typename LLFH::ActiveStoreTrait<Type*>;
408 using Trait_n = typename LLFH::PassiveStoreTrait<int, uint8_t>;
409 using Trait_k = typename LLFH::PassiveStoreTrait<int, uint8_t>;
410 using Trait_m = typename LLFH::PassiveStoreTrait<int, uint8_t>;
411
412 // Declare variables.
413 typename LLFH::ActivityStoreType activityStore = {};
414 typename Trait_A::ArgumentStore A_store = {};
415 typename Trait_B::ArgumentStore B_store = {};
416 typename Trait_R::ArgumentStore R_store = {};
417
418 // Detect activity.
419 bool active_A = Trait_A::isActive(A, n * k);
420 bool active_B = Trait_B::isActive(B, k * m);
421 bool active = active_A | active_B;
422
423 if (active) {
424 // Store function.
426
427 // Count data size.
428 size_t dataSize = LLFH::countActivitySize();
429 dataSize += Trait_n::countSize(n, 1, true);
430 dataSize += Trait_k::countSize(k, 1, true);
431 dataSize += Trait_m::countSize(m, 1, true);
432 dataSize += Trait_A::countSize(A, n * k, LLFH::createStoreActions(active, true, false, active_A, active_B));
433 dataSize += Trait_B::countSize(B, k * m, LLFH::createStoreActions(active, true, false, active_B, active_A));
434 dataSize += Trait_R::countSize(R, n * m, LLFH::createStoreActions(active, false, true, false, true));
435
436 // Reserve data.
437 codi::ByteDataView dataStore = {};
438 tape.pushLowLevelFunction(ID, dataSize, dataStore);
439
440 // Store data.
441 LLFH::setActivity(activityStore, 0, active_A);
442 LLFH::setActivity(activityStore, 1, active_B);
443 LLFH::storeActivity(&dataStore, activityStore);
444 Trait_n::store(&dataStore, allocator, n, 1, true);
445 Trait_k::store(&dataStore, allocator, k, 1, true);
446 Trait_m::store(&dataStore, allocator, m, 1, true);
447 Trait_A::store(&dataStore, allocator, A, n * k,
448 LLFH::createStoreActions(active, true, false, active_A, active_B), A_store);
449 Trait_B::store(&dataStore, allocator, B, k * m,
450 LLFH::createStoreActions(active, true, false, active_B, active_A), B_store);
451 Trait_R::store(&dataStore, allocator, R, n * m, LLFH::createStoreActions(active, false, true, false, true),
452 R_store);
453 } else {
454 // Prepare passive evaluation.
455 Trait_A::store(nullptr, allocator, A, n * k,
456 LLFH::createStoreActions(active, true, false, active_A, active_B), A_store);
457 Trait_B::store(nullptr, allocator, B, k * m,
458 LLFH::createStoreActions(active, true, false, active_B, active_A), B_store);
459 Trait_R::store(nullptr, allocator, R, n * m, LLFH::createStoreActions(active, false, true, false, true),
460 R_store);
461 }
462
463 callPrimal(active, A_store.primal(), active_A, A_store.identifierIn(), B_store.primal(), active_B,
464 B_store.identifierIn(), R_store.primal(), R_store.identifierOut(), n, k, m);
465
466 Trait_R::setExternalFunctionOutput(active, R, n * m, R_store.identifierOut(), R_store.primal(),
467 R_store.oldPrimal());
468
469 allocator.free();
470 }
471
473 CODI_INLINE static void callPrimal(bool active, typename codi::ActiveArgumentStoreTraits<Type*>::Real const* A,
474 bool active_A,
476 typename codi::ActiveArgumentStoreTraits<Type*>::Real const* B, bool active_B,
480 int k, int m) {
481 codi::CODI_UNUSED(active, A, active_A, A_i_in, B, active_B, B_i_in, R, R_i_out, n, k, m);
483
484 // User defined activity update.
485 if (active) {
486 mapEigen<eigenStore>(R_i_out, n, m).setZero();
487 if (active_A) {
488 mapEigen<eigenStore>(R_i_out, n, m).colwise() += mapEigen<eigenStore>(A_i_in, n, k).rowwise().any();
489 }
490 if (active_B) {
491 mapEigen<eigenStore>(R_i_out, n, m).rowwise() += mapEigen<eigenStore>(B_i_in, k, m).colwise().any();
492 }
493 }
494 }
495
500 ID = Type::getTape().registerLowLevelFunction(
501 Entry(reverse, forward, nullptr, del, iterateInputs, iterateOutputs));
502 }
503 }
504 };
505
506 template<Eigen::StorageOptions eigenStore, typename Type>
509
518 template<Eigen::StorageOptions eigenStore, typename Type>
519 void matrixMatrixMultiplication(Type const* A, Type const* B, Type* R, int n, int k, int m) {
521 }
522
529 template<typename Type>
530 void matrixMatrixMultiplicationRowMajor(Type const* A, Type const* B, Type* R, int n, int k, int m) {
532 }
533
539 template<typename Type>
540 void matrixMatrixMultiplicationColMajor(Type const* A, Type const* B, Type* R, int n, int k, int m) {
542 }
543}
#define CODI_INLINE
See codi::Config::ForcedInlines.
Definition config.h:469
#define codiAssert(x)
See codi::Config::EnableAssert.
Definition config.h:441
uint16_t LowLevelFunctionToken
Token type for low level functions in the tapes.
Definition config.h:108
size_t constexpr LowLevelFunctionTokenInvalid
Invalid low level function token.
Definition config.h:114
CoDiPack - Code Differentiation Package.
Definition codi.hpp:97
MapEigenMatrix< T, store > mapEigen(T *p, int rows, int cols)
Create a mapped Eigen matrix with specified storing option.
Definition eigenWrappers.hpp:66
void matrixMatrixMultiplicationRowMajor(Type const *A, Type const *B, Type *R, int n, int k, int m)
Definition matrixMatrixMultiplication.hpp:530
void matrixMatrixMultiplication(Type const *A, Type const *B, Type *R, int n, int k, int m)
Definition matrixMatrixMultiplication.hpp:519
inlinevoid CODI_UNUSED(Args const &...)
Disable unused warnings for an arbitrary number of arguments.
Definition macros.hpp:55
void matrixMatrixMultiplicationColMajor(Type const *A, Type const *B, Type *R, int n, int k, int m)
Definition matrixMatrixMultiplication.hpp:540
double Real
The type with no CoDiPack values.
Definition activeArgumentStoreTraits.hpp:207
int Identifier
The type for holding the identifiers.
Definition activeArgumentStoreTraits.hpp:208
Real Gradient
The type that can represent the gradient values.
Definition activeArgumentStoreTraits.hpp:209
Definition byteDataView.hpp:51
Low level function generation for matrixMatrixMultiplication.
Definition matrixMatrixMultiplication.hpp:48
static CODI_INLINE void callPrimal(bool active, typename codi::ActiveArgumentStoreTraits< Type * >::Real const *A, bool active_A, typename codi::ActiveArgumentStoreTraits< Type * >::Identifier const *A_i_in, typename codi::ActiveArgumentStoreTraits< Type * >::Real const *B, bool active_B, typename codi::ActiveArgumentStoreTraits< Type * >::Identifier const *B_i_in, typename codi::ActiveArgumentStoreTraits< Type * >::Real *R, typename codi::ActiveArgumentStoreTraits< Type * >::Identifier *R_i_out, int n, int k, int m)
Primal computation function.
Definition matrixMatrixMultiplication.hpp:473
codi::VectorAccessInterface< Real, Identifier > * AdjointVectorAccess
Abbreviation for vector access interface.
Definition matrixMatrixMultiplication.hpp:52
static codi::Config::LowLevelFunctionToken ID
Id for this function.
Definition matrixMatrixMultiplication.hpp:60
static CODI_INLINE void callReverse(typename codi::ActiveArgumentStoreTraits< Type * >::Real const *A, bool active_A, typename codi::ActiveArgumentStoreTraits< Type * >::Gradient *A_b_in, typename codi::ActiveArgumentStoreTraits< Type * >::Real const *B, bool active_B, typename codi::ActiveArgumentStoreTraits< Type * >::Gradient *B_b_in, typename codi::ActiveArgumentStoreTraits< Type * >::Real *R, typename codi::ActiveArgumentStoreTraits< Type * >::Gradient *R_b_out, typename codi::PassiveArgumentStoreTraits< int, uint8_t >::Store n, typename codi::PassiveArgumentStoreTraits< int, uint8_t >::Store k, typename codi::PassiveArgumentStoreTraits< int, uint8_t >::Store m)
Reverse function for derivative evaluation.
Definition matrixMatrixMultiplication.hpp:233
static CODI_INLINE void reverse(Tape *tape, codi::ByteDataView &dataStore, AdjointVectorAccess adjoints)
Function for reverse interpretation.
Definition matrixMatrixMultiplication.hpp:160
typename LowLevelFunctionEntry< Tape, Real, Identifier >::IterCallback IterCallback
See LowLevelFunctionEntry.
Definition matrixMatrixMultiplication.hpp:57
static CODI_INLINE void evalAndStore(Type const *A, Type const *B, Type *R, int n, int k, int m)
Store on tape.
Definition matrixMatrixMultiplication.hpp:399
static CODI_INLINE void del(Tape *tape, codi::ByteDataView &dataStore)
Function for deletion of contents.
Definition matrixMatrixMultiplication.hpp:254
static CODI_INLINE void iterateOutputs(Tape *tape, codi::ByteDataView &dataStore, IterCallback func, void *userData)
Function for iteration over inputs.
Definition matrixMatrixMultiplication.hpp:354
static CODI_INLINE void iterateInputs(Tape *tape, codi::ByteDataView &dataStore, IterCallback func, void *userData)
Function for iteration over inputs.
Definition matrixMatrixMultiplication.hpp:304
static CODI_INLINE void callForward(typename codi::ActiveArgumentStoreTraits< Type * >::Real const *A, bool active_A, typename codi::ActiveArgumentStoreTraits< Type * >::Gradient *A_d_in, typename codi::ActiveArgumentStoreTraits< Type * >::Real const *B, bool active_B, typename codi::ActiveArgumentStoreTraits< Type * >::Gradient *B_d_in, typename codi::ActiveArgumentStoreTraits< Type * >::Real *R, typename codi::ActiveArgumentStoreTraits< Type * >::Gradient *R_d_out, typename codi::PassiveArgumentStoreTraits< int, uint8_t >::Store n, typename codi::PassiveArgumentStoreTraits< int, uint8_t >::Store k, typename codi::PassiveArgumentStoreTraits< int, uint8_t >::Store m)
Forward function for derivative evaluation.
Definition matrixMatrixMultiplication.hpp:140
typename Type::Real Real
Real of the type.
Definition matrixMatrixMultiplication.hpp:49
static CODI_INLINE void forward(Tape *tape, codi::ByteDataView &dataStore, AdjointVectorAccess adjoints)
Function for forward interpretation.
Definition matrixMatrixMultiplication.hpp:63
static CODI_INLINE void registerOnTape()
Register function on tape.
Definition matrixMatrixMultiplication.hpp:497
typename Type::Tape Tape
Abbreviation for tape.
Definition matrixMatrixMultiplication.hpp:54
typename Type::Identifier Identifier
Definition matrixMatrixMultiplication.hpp:50
Helper structure for storing low level functions and their arguments on a tape.
Definition lowLevelFunctionCreationUtilities.hpp:128
Low level function entry on the tape. See LowLevelFunctionTapeInterface for details.
Definition lowLevelFunctionEntry.hpp:69
void(*)(Identifier *id, void *userData) IterCallback
Callback function for the identifier iteration.
Definition lowLevelFunctionEntry.hpp:81
T Store
Type for the variable declaration for restoring the data.
Definition passiveArgumentStoreTraits.hpp:61
Allocator for temporary used memory.
Definition temporaryMemory.hpp:54
inlinevoid free()
Free all allocated memory. No destructors are called. Stored pointers and resources need to be deallo...
Definition temporaryMemory.hpp:110
inlinebool isEmpty()
Returns true if no data is currently allocated.
Definition temporaryMemory.hpp:71
Unified access to the adjoint vector and primal vector in a tape evaluation.
Definition vectorAccessInterface.hpp:94
virtual size_t getVectorSize() const =0
Vector size in the current tape evaluation.