Mentions légales du service
Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
faust
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Admin message
GitLab upgrade completed. Current version is 17.11.4.
Show more breadcrumbs
faust group
faust
Commits
1eb0c3d6
Commit
1eb0c3d6
authored
2 years ago
by
hhakim
Browse files
Options
Downloads
Patches
Plain Diff
Add a unit test for the GPU partial svd (batched_svd).
parent
90ae7a46
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
misc/test/src/C++/faust_test_gpu_svd.cpp.in
+72
-12
72 additions, 12 deletions
misc/test/src/C++/faust_test_gpu_svd.cpp.in
with
72 additions
and
12 deletions
misc/test/src/C++/faust_test_gpu_svd.cpp.in
+
72
−
12
View file @
1eb0c3d6
...
...
@@ -7,36 +7,35 @@ using namespace std;
using namespace Faust;
typedef @TEST_FPP@ FPP;
int main()
void test_batched_full_svd()
{
Faust::enable_gpu_mod();
int m = 16, n = 18; // TODO: option with default values
int
n
batch
es
= 32; // TODO: option with default values
int batch
_sz
= 32; // TODO: option with default values
const int minmn = (m < n) ? m : n; /* min(m,n) */
MatDense<FPP, Cpu>* As = MatDense<FPP, Cpu>::randMat(m, n * nbatches);
MatDense<FPP, Cpu> Us, Vs, Ss;
MatDense<FPP, Cpu>* As = MatDense<FPP, Cpu>::randMat(m, n * batch_sz);
MatDense<FPP, Cpu> Us, Vs;
MatDense<Real<FPP>, Cpu> Ss;
MatDense<FPP, GPU2> gpu_As(*As);
MatDense<FPP, GPU2> gpu_Us(m, m *
n
batch
es
);
MatDense<FPP, GPU2> gpu_Vs(n, n *
n
batch
es
);
MatDense<FPP, GPU2> gpu_Ss(minmn,
n
batch
es
);
batched_svd(gpu_As,
n
batch
es
, gpu_Us, gpu_Vs, gpu_Ss/*, rank*/);
MatDense<FPP, GPU2> gpu_Us(m, m * batch
_sz
);
MatDense<FPP, GPU2> gpu_Vs(n, n * batch
_sz
);
MatDense<
Real<
FPP
>
, GPU2> gpu_Ss(minmn, batch
_sz
);
batched_svd(gpu_As, batch
_sz
, gpu_Us, gpu_Vs, gpu_Ss/*, rank*/);
gpu_Us.tocpu(Us);
gpu_Vs.tocpu(Vs);
gpu_Ss.tocpu(Ss);
for(int i=0;i <
n
batch
es
; i++)
for(int i=0;i < batch
_sz
; i++)
{
auto A = As->get_cols(i * n, n);
auto U = Us.get_cols(i * m, m);
auto V = Vs.get_cols(i * n, n);
auto S = Ss.get_cols(i, 1);
MatDense<FPP, Cpu> SD(m, n);
MatDense<
Real<
FPP
>
, Cpu> SD(m, n);
SD.setZeros();
for(int j=0;j<minmn;j++)
SD.getData()[j * m + j] = (*S)(j);
...
...
@@ -55,5 +54,66 @@ int main()
delete S;
}
delete As;
}
void test_batched_partial_svd()
{
int m = 4, n = 5; // TODO: option with default values
int batch_sz = 3; // TODO: option with default values
const int minmn = (m < n) ? m : n; /* min(m,n) */
int rank = 1;
MatDense<FPP, Cpu> As(m, n * batch_sz);
for(int i = 0; i < batch_sz; i++)
{
auto v1 = MatDense<FPP, Cpu>::randMat(m, 1);
auto v2 = MatDense<FPP, Cpu>::randMat(1, n);
auto A = *v2;
v1->multiply(A, 'N');
delete v1;
delete v2;
memcpy(As.getData() + i * m * n, A.getData(), sizeof(FPP) * m * n);
}
MatDense<FPP, Cpu> Us(m, batch_sz * rank), Vs(n, batch_sz * rank);
MatDense<Real<FPP>, Cpu> Ss(minmn, batch_sz * rank);
batched_svd(As, batch_sz, Us, Vs, Ss, /* rank */ 1);
for(int i=0;i < batch_sz; i++)
{
auto A = As.get_cols(i * n, n);
A->print_mat("A:");
auto U = Us.get_cols(i * rank, 1);
auto V = Vs.get_cols(i * rank, 1);
auto S = Ss(i);
cout << "S:" << S << endl;
U->print_mat("U:");
V->print_mat("V:");
auto E = *A;
auto P = *U;
P.scalarMultiply(S);
V->adjoint();
P.multiplyRight(*V);
E -= P;
auto err = E.norm() / A->norm();
cout << "err:" << err << endl;
assert(err < 1e-7);
delete A;
delete U;
delete V;
}
}
int main()
{
Faust::enable_gpu_mod();
test_batched_full_svd();
test_batched_partial_svd();
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment