imate
C++/CUDA Reference
cu_vector_operations.h
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: Copyright 2021, Siavash Ameli <sameli@berkeley.edu>
3  * SPDX-License-Identifier: BSD-3-Clause
4  * SPDX-FileType: SOURCE
5  *
6  * This program is free software: you can redistribute it and/or modify it
7  * under the terms of the license found in the LICENSE.txt file in the root
8  * directory of this source tree.
9  */
10 
11 
12 #ifndef _CU_BASIC_ALGEBRA_CU_VECTOR_OPERATIONS_H_
13 #define _CU_BASIC_ALGEBRA_CU_VECTOR_OPERATIONS_H_
14 
15 // =======
16 // Headers
17 // =======
18 
19 #include <cublas_v2.h>
20 #include "../_definitions/types.h" // LongIndexType
21 
22 
23 // =================
24 // Vector Operations
25 // =================
26 
34 
35 template <typename DataType>
37 {
38  public:
39 
40  // copy vector
41  static void copy_vector(
42  cublasHandle_t cublas_handle,
43  const DataType* input_vector,
44  const LongIndexType vector_size,
45  DataType* output_vector);
46 
47  // copy scaled vector
48  static void copy_scaled_vector(
49  cublasHandle_t cublas_handle,
50  const DataType* input_vector,
51  const LongIndexType vector_size,
52  const DataType scale,
53  DataType* output_vector);
54 
55  // subtract scaled vector
56  static void subtract_scaled_vector(
57  cublasHandle_t cublas_handle,
58  const DataType* input_vector,
59  const LongIndexType vector_size,
60  const DataType scale,
61  DataType* output_vector);
62 
63  // inner product
64  static DataType inner_product(
65  cublasHandle_t cublas_handle,
66  const DataType* vector1,
67  const DataType* vector2,
68  const LongIndexType vector_size);
69 
70  // euclidean norm
71  static DataType euclidean_norm(
72  cublasHandle_t cublas_handle,
73  const DataType* vector,
74  const LongIndexType vector_size);
75 
76  // normalize vector in place
77  static DataType normalize_vector_in_place(
78  cublasHandle_t cublas_handle,
79  DataType* vector,
80  const LongIndexType vector_size);
81 
82  // normalize vector and copy
83  static DataType normalize_vector_and_copy(
84  cublasHandle_t cublas_handle,
85  const DataType* vector,
86  const LongIndexType vector_size,
87  DataType* output_vector);
88 };
89 
90 #endif // _CU_BASIC_ALGEBRA_CU_VECTOR_OPERATIONS_H_
A static class for vector operations, similar to level-1 operations of the BLAS library....
static void copy_vector(cublasHandle_t cublas_handle, const DataType *input_vector, const LongIndexType vector_size, DataType *output_vector)
Copies a vector to a new vector. Result is written in-place.
static void copy_scaled_vector(cublasHandle_t cublas_handle, const DataType *input_vector, const LongIndexType vector_size, const DataType scale, DataType *output_vector)
Scales a vector and stores to a new vector.
static void subtract_scaled_vector(cublasHandle_t cublas_handle, const DataType *input_vector, const LongIndexType vector_size, const DataType scale, DataType *output_vector)
Subtracts the scaled input vector from the output vector.
static DataType normalize_vector_in_place(cublasHandle_t cublas_handle, DataType *vector, const LongIndexType vector_size)
Normalizes a vector based on Euclidean 2-norm. The result is written in-place.
static DataType inner_product(cublasHandle_t cublas_handle, const DataType *vector1, const DataType *vector2, const LongIndexType vector_size)
Computes Euclidean inner product of two vectors.
static DataType normalize_vector_and_copy(cublasHandle_t cublas_handle, const DataType *vector, const LongIndexType vector_size, DataType *output_vector)
Normalizes a vector based on Euclidean 2-norm. The result is written into another vector.
static DataType euclidean_norm(cublasHandle_t cublas_handle, const DataType *vector, const LongIndexType vector_size)
Computes the Euclidean 2-norm of a 1D array.
int LongIndexType
Definition: types.h:60