1
1
#pragma once
2
- #include " ../tsvd /utils.cuh"
2
+ #include " ../utils /utils.cuh"
3
3
#include " ../device/device_context.cuh"
4
4
#include " cusolverDn.h"
5
5
#include < ../../../cub/cub/cub.cuh>
6
6
7
- namespace tsvd
7
+ namespace matrix
8
8
{
9
-
10
- typedef float tsvd_float;
11
- typedef double tsvd_double;
9
+ using namespace h2o4gpu ;
12
10
13
11
/* *
14
12
* \class Matrix
@@ -275,19 +273,19 @@ namespace tsvd
275
273
276
274
void copy (const Matrix<T>& M)
277
275
{
278
- tsvd_check (M.rows () == this ->rows ()&&M.columns () == this ->columns (), " Cannot copy matrix. Dimensions are different." );
276
+ h2o4gpu_check (M.rows () == this ->rows ()&&M.columns () == this ->columns (), " Cannot copy matrix. Dimensions are different." );
279
277
thrust::copy (M.dptr (), M.dptr () + M.size (), this ->dptr ());
280
278
}
281
279
282
280
283
281
void print () const
284
282
{
285
- thrust::host_vector<T> h_tsvd (thrust::device_ptr<T>(_data), thrust::device_ptr<T>(_data + _n * _m));
283
+ thrust::host_vector<T> h_matrix (thrust::device_ptr<T>(_data), thrust::device_ptr<T>(_data + _n * _m));
286
284
for (auto i = 0 ; i < _m; i++)
287
285
{
288
286
for (auto j = 0 ; j < _n; j++)
289
287
{
290
- printf (" %1.2f " , h_tsvd [j * _m + i]);
288
+ printf (" %1.2f " , h_matrix [j * _m + i]);
291
289
}
292
290
printf (" \n " );
293
291
}
@@ -306,43 +304,43 @@ namespace tsvd
306
304
}
307
305
};
308
306
309
- void multiply_diag (const Matrix<tsvd_float >& A, const Matrix<tsvd_float >& B, Matrix<tsvd_float >& C, DeviceContext& context, bool left_diag);
310
- void multiply_diag (const Matrix<tsvd_double >& A, const Matrix<tsvd_double >& B, Matrix<tsvd_double >& C, DeviceContext& context, bool left_diag);
307
+ void multiply_diag (const Matrix<float >& A, const Matrix<float >& B, Matrix<float >& C, device:: DeviceContext& context, bool left_diag);
308
+ void multiply_diag (const Matrix<double >& A, const Matrix<double >& B, Matrix<double >& C, device:: DeviceContext& context, bool left_diag);
311
309
312
310
/* *
313
- * \fn void multiply(const Matrix<tsvd_float >& A, const Matrix<tsvd_float >& B, Matrix<tsvd_float >& C, DeviceContext& context, bool transpose_a = false, bool transpose_b = false, tsvd_float alpha=1.0f);
311
+ * \fn void multiply(const Matrix<float >& A, const Matrix<float >& B, Matrix<float >& C, device:: DeviceContext& context, bool transpose_a = false, bool transpose_b = false, float alpha=1.0f);
314
312
*
315
313
* \brief Matrix multiplication. ABa = C. A or B may be transposed. a is a scalar.
316
314
*
317
315
* \param A The Matrix<float> to process.
318
- * \param B The Matrix<tsvd_float > to process.
316
+ * \param B The Matrix<float > to process.
319
317
* \param [in,out] C The Matrix<float> to process.
320
318
* \param [in,out] context The context.
321
319
* \param transpose_a (Optional) True to transpose a.
322
320
* \param transpose_b (Optional) True to transpose b.
323
321
* \param alpha (Optional) The alpha.
324
322
*/
325
323
326
- void multiply (const Matrix<tsvd_float >& A, const Matrix<tsvd_float >& B, Matrix<tsvd_float >& C, DeviceContext& context, bool transpose_a = false , bool transpose_b = false , tsvd_float alpha = 1 .0f );
324
+ void multiply (const Matrix<float >& A, const Matrix<float >& B, Matrix<float >& C, device:: DeviceContext& context, bool transpose_a = false , bool transpose_b = false , float alpha = 1 .0f );
327
325
328
326
/* *
329
- * \fn void multiply(const Matrix<tsvd_double >& A, const Matrix<tsvd_double >& B, Matrix<tsvd_double >& C, DeviceContext& context, bool transpose_a = false, bool transpose_b = false, tsvd_double alpha=1.0f);
327
+ * \fn void multiply(const Matrix<double >& A, const Matrix<double >& B, Matrix<double >& C, device:: DeviceContext& context, bool transpose_a = false, bool transpose_b = false, double alpha=1.0f);
330
328
*
331
329
* \brief Matrix multiplication. ABa = C. A or B may be transposed. a is a scalar.
332
330
*
333
331
* \param A The Matrix<float> to process.
334
- * \param B The Matrix<tsvd_double > to process.
332
+ * \param B The Matrix<double > to process.
335
333
* \param [in,out] C The Matrix<float> to process.
336
334
* \param [in,out] context The context.
337
335
* \param transpose_a (Optional) True to transpose a.
338
336
* \param transpose_b (Optional) True to transpose b.
339
337
* \param alpha (Optional) The alpha.
340
338
*/
341
339
342
- void multiply (const Matrix<tsvd_double >& A, const Matrix<tsvd_double >& B, Matrix<tsvd_double >& C, DeviceContext& context, bool transpose_a = false , bool transpose_b = false , tsvd_double alpha = 1 .0f );
340
+ void multiply (const Matrix<double >& A, const Matrix<double >& B, Matrix<double >& C, device:: DeviceContext& context, bool transpose_a = false , bool transpose_b = false , double alpha = 1 .0f );
343
341
344
342
/* *
345
- * \fn void multiply(Matrix<tsvd_float >& A, const tsvd_float a ,DeviceContext& context);
343
+ * \fn void multiply(Matrix<float >& A, const float a ,device:: DeviceContext& context);
346
344
*
347
345
* \brief Matrix scalar multiplication.
348
346
*
@@ -352,97 +350,97 @@ namespace tsvd
352
350
*/
353
351
354
352
template <typename T, typename U>
355
- void multiply (Matrix<T>& A, const U a, DeviceContext& context);
353
+ void multiply (Matrix<T>& A, const U a, device:: DeviceContext& context);
356
354
357
355
/* *
358
- * \fn void matrix_sub(const Matrix<tsvd_float >& A, const Matrix<float>& B, Matrix<float>& C, DeviceContext& context)
356
+ * \fn void matrix_sub(const Matrix<float >& A, const Matrix<float>& B, Matrix<float>& C, device:: DeviceContext& context)
359
357
*
360
358
* \brief Matrix subtraction. A - B = C.
361
359
*
362
360
*/
363
361
364
362
template <typename T>
365
- void subtract (const Matrix<T>& A, const Matrix<T>& B, Matrix<T>& C, DeviceContext& context);
363
+ void subtract (const Matrix<T>& A, const Matrix<T>& B, Matrix<T>& C, device:: DeviceContext& context);
366
364
367
365
/* *
368
- * \fn void add(const Matrix<tsvd_float >& A, const Matrix<tsvd_float >& B, Matrix<tsvd_float >& C, DeviceContext& context);
366
+ * \fn void add(const Matrix<float >& A, const Matrix<float >& B, Matrix<float >& C, device:: DeviceContext& context);
369
367
*
370
368
* \brief Matrix addition. A + B = C
371
369
*
372
- * \param A The Matrix<tsvd_float > to process.
373
- * \param B The Matrix<tsvd_float > to process.
374
- * \param [in,out] C The Matrix<tsvd_float > to process.
370
+ * \param A The Matrix<float > to process.
371
+ * \param B The Matrix<float > to process.
372
+ * \param [in,out] C The Matrix<float > to process.
375
373
* \param [in,out] context The context.
376
374
*/
377
375
378
376
template <typename T>
379
- void add (const Matrix<T>& A, const Matrix<T>& B, Matrix<T>& C, DeviceContext& context);
377
+ void add (const Matrix<T>& A, const Matrix<T>& B, Matrix<T>& C, device:: DeviceContext& context);
380
378
381
379
/* *
382
- * \fn void transpose(const Matrix<tsvd_float >&A, Matrix<tsvd_float >&B, DeviceContext& context)
380
+ * \fn void transpose(const Matrix<float >&A, Matrix<float >&B, device:: DeviceContext& context)
383
381
*
384
382
* \brief Transposes matrix A into matrix B.
385
383
*
386
- * \param A The Matrix<tsvd_float > to process.
387
- * \param [in,out] B The Matrix<tsvd_float > to process.
384
+ * \param A The Matrix<float > to process.
385
+ * \param [in,out] B The Matrix<float > to process.
388
386
* \param [in,out] context The context.
389
387
*/
390
388
391
- void transpose (const Matrix<tsvd_float >& A, Matrix<tsvd_float >& B, DeviceContext& context);
389
+ void transpose (const Matrix<float >& A, Matrix<float >& B, device:: DeviceContext& context);
392
390
393
391
/* *
394
- * \fn void transpose(const Matrix<tsvd_double >&A, Matrix<tsvd_double >&B, DeviceContext& context)
392
+ * \fn void transpose(const Matrix<double >&A, Matrix<double >&B, device:: DeviceContext& context)
395
393
*
396
394
* \brief Transposes matrix A into matrix B.
397
395
*
398
- * \param A The Matrix<tsvd_double > to process.
399
- * \param [in,out] B The Matrix<tsvd_double > to process.
396
+ * \param A The Matrix<double > to process.
397
+ * \param [in,out] B The Matrix<double > to process.
400
398
* \param [in,out] context The context.
401
399
*/
402
400
403
- void transpose (const Matrix<tsvd_double >& A, Matrix<tsvd_double >& B, DeviceContext& context);
401
+ void transpose (const Matrix<double >& A, Matrix<double >& B, device:: DeviceContext& context);
404
402
405
403
/* *
406
- * \fn void normalize_columns(Matrix<tsvd_float >& M, Matrix<tsvd_float >& M_temp, Matrix<tsvd_float >& column_length, Matrix<tsvd_float >& ones, DeviceContext& context);
404
+ * \fn void normalize_columns(Matrix<float >& M, Matrix<float >& M_temp, Matrix<float >& column_length, Matrix<float >& ones, device:: DeviceContext& context);
407
405
*
408
406
* \brief Normalize matrix columns.
409
407
*
410
- * \param [in,out] M The Matrix<tsvd_float > to process.
408
+ * \param [in,out] M The Matrix<float > to process.
411
409
* \param [in,out] M_temp Temporary storage matrix of size >= M.
412
410
* \param [in,out] column_length Temporary storage matrix with one element per column.
413
411
* \param [in,out] ones Matrix of ones of length M.columns().
414
412
* \param [in,out] context The context.
415
413
*/
416
414
417
- void normalize_columns (Matrix<tsvd_float >& M, Matrix<tsvd_float >& M_temp, Matrix<tsvd_float >& column_length, const Matrix<tsvd_float >& ones, DeviceContext& context);
418
- void normalize_columns (Matrix<tsvd_double >& M, Matrix<tsvd_double >& M_temp, Matrix<tsvd_double >& column_length, const Matrix<tsvd_double >& ones, DeviceContext& context);
415
+ void normalize_columns (Matrix<float >& M, Matrix<float >& M_temp, Matrix<float >& column_length, const Matrix<float >& ones, device:: DeviceContext& context);
416
+ void normalize_columns (Matrix<double >& M, Matrix<double >& M_temp, Matrix<double >& column_length, const Matrix<double >& ones, device:: DeviceContext& context);
419
417
420
- void normalize_columns (Matrix<tsvd_float >& M, DeviceContext& context);
421
- void normalize_columns (Matrix<tsvd_double >& M, DeviceContext& context);
418
+ void normalize_columns (Matrix<float >& M, device:: DeviceContext& context);
419
+ void normalize_columns (Matrix<double >& M, device:: DeviceContext& context);
422
420
423
421
/* *
424
- * \fn void normalize_vector_cublas(Matrix<tsvd_float >& M, DeviceContext& context)
422
+ * \fn void normalize_vector_cublas(Matrix<float >& M, device:: DeviceContext& context)
425
423
*
426
424
* \brief Normalize a vector utilizing cuBLAS
427
425
*
428
426
* \param [in,out] M The vector to process
429
427
* \param [in,out] context Device context.
430
428
*/
431
- void normalize_vector_cublas (Matrix<tsvd_float >& M, DeviceContext& context);
429
+ void normalize_vector_cublas (Matrix<float >& M, device:: DeviceContext& context);
432
430
433
431
/* *
434
- * \fn void normalize_vector_cublas(Matrix<tsvd_double >& M, DeviceContext& context)
432
+ * \fn void normalize_vector_cublas(Matrix<double >& M, device:: DeviceContext& context)
435
433
*
436
434
* \brief Normalize a vector utilizing cuBLAS
437
435
*
438
436
* \param [in,out] M The vector to process
439
437
* \param [in,out] context Device context.
440
438
*/
441
- void normalize_vector_cublas (Matrix<tsvd_double >& M, DeviceContext& context);
439
+ void normalize_vector_cublas (Matrix<double >& M, device:: DeviceContext& context);
442
440
443
441
444
442
/* *
445
- * \fn void normalize_vector_thrust(Matrix<tsvd_float >& M, DeviceContext& context)
443
+ * \fn void normalize_vector_thrust(Matrix<float >& M, device:: DeviceContext& context)
446
444
*
447
445
* \brief Normalize a vector utilizng Thrust
448
446
*
@@ -451,45 +449,45 @@ namespace tsvd
451
449
*/
452
450
453
451
template <typename T>
454
- void normalize_vector_thrust (Matrix<T>& M, DeviceContext& context);
452
+ void normalize_vector_thrust (Matrix<T>& M, device:: DeviceContext& context);
455
453
456
454
/* *
457
- * \fn void residual(const Matrix<tsvd_float >&X, const Matrix<tsvd_float >&D, const Matrix<tsvd_float >&S, Matrix<tsvd_float >&R, DeviceContext & context);
455
+ * \fn void residual(const Matrix<float >&X, const Matrix<float >&D, const Matrix<float >&S, Matrix<float >&R, device:: DeviceContext & context);
458
456
*
459
457
* \brief Calculate residual R = X - DS
460
458
*
461
459
*/
462
460
463
- void residual (const Matrix<tsvd_float >& X, const Matrix<tsvd_float >& D, const Matrix<tsvd_float >& S, Matrix<tsvd_float >& R, DeviceContext& context);
464
- void residual (const Matrix<tsvd_double >& X, const Matrix<tsvd_double >& D, const Matrix<tsvd_double >& S, Matrix<tsvd_double >& R, DeviceContext& context);
461
+ void residual (const Matrix<float >& X, const Matrix<float >& D, const Matrix<float >& S, Matrix<float >& R, device:: DeviceContext& context);
462
+ void residual (const Matrix<double >& X, const Matrix<double >& D, const Matrix<double >& S, Matrix<double >& R, device:: DeviceContext& context);
465
463
466
- void calculate_eigen_pairs_exact (const Matrix<tsvd_float >& X, Matrix<tsvd_float >& Q, Matrix<tsvd_float >& w, DeviceContext& context);
467
- void calculate_eigen_pairs_exact (const Matrix<tsvd_double >& X, Matrix<tsvd_double >& Q, Matrix<tsvd_double >& w, DeviceContext& context);
464
+ void calculate_eigen_pairs_exact (const Matrix<float >& X, Matrix<float >& Q, Matrix<float >& w, device:: DeviceContext& context);
465
+ void calculate_eigen_pairs_exact (const Matrix<double >& X, Matrix<double >& Q, Matrix<double >& w, device:: DeviceContext& context);
468
466
469
- void dot_product (Matrix<tsvd_float >& b_k1, Matrix<tsvd_float >& b_k, float * eigen_value_estimate, DeviceContext& context);
470
- void dot_product (Matrix<tsvd_double >& b_k1, Matrix<tsvd_double >& b_k, double * eigen_value_estimate, DeviceContext& context);
467
+ void dot_product (Matrix<float >& b_k1, Matrix<float >& b_k, float * eigen_value_estimate, device:: DeviceContext& context);
468
+ void dot_product (Matrix<double >& b_k1, Matrix<double >& b_k, double * eigen_value_estimate, device:: DeviceContext& context);
471
469
472
- void max_index_per_column (Matrix<tsvd_float >& A, std::vector<int >& result_array, DeviceContext& context);
473
- void max_index_per_column (Matrix<tsvd_double >& A, std::vector<int >& result_array, DeviceContext& context);
470
+ void max_index_per_column (Matrix<float >& A, std::vector<int >& result_array, device:: DeviceContext& context);
471
+ void max_index_per_column (Matrix<double >& A, std::vector<int >& result_array, device:: DeviceContext& context);
474
472
475
473
// ----------------------------------------------------------------------------------------------------------------------------------------------------------------------
476
474
// Stricly floating point operations that are not used
477
475
478
476
/* *
479
- * \fn void linear_solve(const Matrix<tsvd_float >& A, Matrix<tsvd_float >& X, const Matrix<tsvd_float >& B, DeviceContext& context)
477
+ * \fn void linear_solve(const Matrix<float >& A, Matrix<float >& X, const Matrix<float >& B, device:: DeviceContext& context)
480
478
*
481
479
* \brief Solve linear system AX=B to find B.
482
480
*
483
- * \param A The Matrix<tsvd_float > to process.
484
- * \param [in,out] X The Matrix<tsvd_float > to process.
485
- * \param B The Matrix<tsvd_float > to process.
481
+ * \param A The Matrix<float > to process.
482
+ * \param [in,out] X The Matrix<float > to process.
483
+ * \param B The Matrix<float > to process.
486
484
* \param [in,out] context The context.
487
485
*/
488
486
489
- void linear_solve (const Matrix<tsvd_float >& A, Matrix<tsvd_float >& X, const Matrix<tsvd_float >& B, DeviceContext& context);
487
+ void linear_solve (const Matrix<float >& A, Matrix<float >& X, const Matrix<float >& B, device:: DeviceContext& context);
490
488
491
489
/* *
492
- * \fn void pseudoinverse(const Matrix<tsvd_float >& A, Matrix<tsvd_float >& pinvA, DeviceContext& context)
490
+ * \fn void pseudoinverse(const Matrix<float >& A, Matrix<float >& pinvA, device:: DeviceContext& context)
493
491
*
494
492
* \brief Calculate Moore-Penrose seudoinverse using the singular value decomposition method.
495
493
*
@@ -498,6 +496,6 @@ namespace tsvd
498
496
* \param [in,out] context Device context.
499
497
*/
500
498
501
- void pseudoinverse (const Matrix<tsvd_float >& A, Matrix<tsvd_float >& pinvA, DeviceContext& context);
499
+ void pseudoinverse (const Matrix<float >& A, Matrix<float >& pinvA, device:: DeviceContext& context);
502
500
503
501
}
0 commit comments