This repository has been archived by the owner on Jul 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
kronmult3_pbatched.hpp
78 lines (63 loc) · 2.2 KB
/
kronmult3_pbatched.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#ifndef KRONMULT3_PBATCHED_HPP
#define KRONMULT3_PBATCHED_HPP 1
#include "kroncommon.hpp"
#include "kronmult3.hpp"
// --------------------------------------------------------------------
// Performs Y(:,k) += kron(A1(k),...,A6(k)) * X(:,k), k=1:batchCount
// Note result in Y but X and W may be modified as temporary work space
// --------------------------------------------------------------------
template<typename T>
GLOBAL_FUNCTION
void kronmult3_pbatched(
int const n,
T const Aarray_[],
T* pX_[],
T* pY_[],
T* pW_[],
int const batchCount)
//
// conceptual shape of Aarray is (n,n,6,batchCount)
//
// pX_[] is array of pointers to X[], each of size n^3
// pY_[] is array of pointers to Y[], each of size n^3
// pW_[] is array of pointers to Z[], each of size n^3
//
// Y is the output
// X is the input (but may be modified)
// W is workspace
//
//
{
#ifdef USE_GPU
// -------------------------------------------
// note 1-based matlab convention for indexing
// -------------------------------------------
int const iz_start = blockIdx.x + 1;
int const iz_size = gridDim.x;
expect( gridDim.y == 1);
expect( gridDim.z == 1);
#else
int const iz_start = 1;
int const iz_size = 1;
#endif
auto Aarray = [&] (int const i1,
int const i2,
int const i3,
int const i4) -> T const & {
return( Aarray_[ indx4f(i1,i2,i3,i4, n,n,3 ) ] );
};
#ifndef USE_GPU
#pragma omp parallel for
#endif
for(int ibatch=iz_start; ibatch <= batchCount; ibatch += iz_size) {
T* const Xp = pX_[ (ibatch-1) ];
T* const Yp = pY_[ (ibatch-1) ];
T* const Wp = pW_[ (ibatch-1) ];
T const * const A1 = &(Aarray(1,1,1,ibatch));
T const * const A2 = &(Aarray(1,1,2,ibatch));
T const * const A3 = &(Aarray(1,1,3,ibatch));
int const nvec = 1;
kronmult3( n, nvec, A1,A2,A3, Xp, Yp, Wp );
};
}
#endif