CudaTypesBase.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifndef SOFA_GPU_CUDA_CUDATYPES_BASE_H
00026 #define SOFA_GPU_CUDA_CUDATYPES_BASE_H
00027
00028 #include "CudaTypes.h"
00029 #include <sofa/component/linearsolver/FullMatrix.h>
00030
00031
00032
00033 namespace sofa {
00034 namespace gpu {
00035 namespace cuda {
00036
00037 using namespace sofa::defaulttype;
00038
00039 template <class T>
00040 class CudaBaseMatrix : public BaseMatrix {
00041 public :
00042
00043 CudaMatrix<T> & getCudaMatrix() {
00044 return m;
00045 }
00046
00047 void resize(int nbCol, int nbRow) {
00048 m.resize(nbCol,nbRow,BSIZE);
00049 }
00050
00051 void resize(int nbCol, int nbRow,int ws) {
00052 m.resize(nbCol,nbRow,ws);
00053 }
00054
00055 int rowSize() const {
00056 return m.getSizeY();
00057 }
00058
00059 int colSize() const {
00060 return m.getSizeX();
00061 }
00062
00063 SReal element(int i, int j) const {
00064 return m[i][j];
00065 }
00066
00067 void clear() {
00068 for (unsigned j=0; j<m.getSizeX(); j++) {
00069 for (unsigned i=0; i<m.getSizeY(); i++) {
00070 m[j][i] = (T)(0.0);
00071 }
00072 }
00073 }
00074
00075 void set(int j, int i, double v) {
00076 #ifdef DEBUG_BASE
00077 if ((j>=rowSize()) || (i>=colSize())) {
00078 printf("forbidden acces %d %d\n",j,i);
00079 exit(1);
00080 }
00081 #endif
00082 m[j][i] = (T)v;
00083 }
00084
00085 void add(int j, int i, double v) {
00086 #ifdef DEBUG_BASE
00087 if ((j>=rowSize()) || (i>=colSize())) {
00088 printf("forbidden acces %d %d\n",j,i);
00089 exit(1);
00090 }
00091 #endif
00092 m[j][i] += (T)v;
00093 }
00094
00095 private :
00096 CudaMatrix<T> m;
00097 };
00098
00099 template <class T>
00100 class CudaBaseVector : public BaseVector {
00101
00102 public :
00103 CudaVector<T>& getCudaVector() {
00104 return v;
00105 }
00106
00107 T& operator[](int i) {
00108 return v[i];
00109 }
00110
00111 const T& operator[](int i) const {
00112 return v[i];
00113 }
00114
00115 void resize(int nbRow) {
00116 v.resize(nbRow);
00117 }
00118
00119 void resize(int nbRow,int warp_size) {
00120 v.resize(nbRow,warp_size);
00121 }
00122
00123 int size() const {
00124 return v.size();
00125 }
00126
00127 SReal element(int i) const {
00128 return v[i];
00129 }
00130
00131 void clear() {
00132 for (int i=0; i<size(); i++) v[i]=(T)(0.0);
00133 }
00134
00135 void set(int i, SReal val) {
00136 v[i] = (T) val;
00137 }
00138
00139 void add(int i, SReal val) {
00140 v[i] += (T)val;
00141 }
00142
00143 private :
00144 CudaVector<T> v;
00145 };
00146
00147 }
00148 }
00149 }
00150
00151 #endif