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 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282
|
/***************************************************************************
ucl_print.h
-------------------
W. Michael Brown
Routines for printing debugging output for matrix/vector data
__________________________________________________________________________
This file is part of the Geryon Unified Coprocessor Library (UCL)
__________________________________________________________________________
begin : Mon Jan 11 2010
copyright : (C) 2010 by W. Michael Brown
email : brownw@ornl.gov
***************************************************************************/
/* -----------------------------------------------------------------------
Copyright (2010) Sandia Corporation. Under the terms of Contract
DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains
certain rights in this software. This software is distributed under
the Simplified BSD License.
----------------------------------------------------------------------- */
// Only allow this file to be included by nvc_memory.h and ocl_memory.h
#ifdef UCL_PRINT_ALLOW
template <int mem> struct _ucl_print;
template <> struct _ucl_print<1> {
template <class mat_type>
static inline void p(mat_type &mat, const size_t n, std::ostream &out,
const std::string delim) {
for (size_t i=0; i<n-1; i++)
out << mat[i] << delim;
out << mat[n-1];
}
template <class mat_type>
static inline void p(const mat_type &mat, const size_t n, std::ostream &out,
const std::string delim, UCL_Device &dev) {
p(mat,n,out,delim);
}
template <class mat_type>
static inline void p(mat_type &mat, const size_t rows, const size_t cols,
std::ostream &out, const std::string delim,
const std::string row_delim) {
int offset=0;
int row_size=cols;
if (mat_type::VECTOR==0)
row_size=mat.row_size();
for (size_t j=0; j<rows; j++) {
size_t lend=offset+cols-1;
for (size_t i=offset; i<lend; i++)
out << mat[i] << delim;
out << mat[lend];
if (j!=rows-1)
out << row_delim;
offset+=row_size;
}
}
template <class mat_type>
static inline void p(const mat_type &mat,const size_t rows,const size_t cols,
std::ostream &out,const std::string delim,
const std::string row_delim, UCL_Device &dev) {
p(mat,rows,cols,out,delim,row_delim);
}
};
template <int mem> struct _ucl_print {
template <class mat_type>
static inline void p(mat_type &mat, const size_t n, std::ostream &out,
const std::string delim) {
UCL_H_Vec<typename mat_type::data_type> temp;
temp.alloc(n,mat);
ucl_copy(temp,mat,n,false);
_ucl_print<1>::p(temp,n,out,delim);
}
template <class mat_type>
static inline void p(const mat_type &mat, const size_t n, std::ostream &out,
const std::string delim, UCL_Device &dev) {
UCL_H_Vec<typename mat_type::data_type> temp;
temp.alloc(n,dev);
ucl_copy(temp,mat,n,false);
_ucl_print<1>::p(temp,n,out,delim);
}
template <class mat_type>
static inline void p(mat_type &mat, const size_t rows, const size_t cols,
std::ostream &out, const std::string delim,
const std::string row_delim) {
UCL_H_Vec<typename mat_type::data_type> temp;
temp.alloc(mat.rows()*mat.cols(),mat);
if (mat_type::VECTOR==1)
ucl_copy(temp,mat,rows*cols,false);
else
ucl_copy(temp,mat,rows,cols,false);
_ucl_print<1>::p(temp,rows,cols,out,delim,row_delim);
}
template <class mat_type>
static inline void p(const mat_type &mat, const size_t rows,
const size_t cols,std::ostream &out,
const std::string delim,
const std::string row_delim, UCL_Device &dev) {
UCL_H_Vec<typename mat_type::data_type> temp;
temp.alloc(mat.rows()*mat.cols(),dev);
if (mat_type::VECTOR==1)
ucl_copy(temp,mat,rows*cols,false);
else
ucl_copy(temp,mat,rows,cols,false);
_ucl_print<1>::p(temp,rows,cols,out,delim,row_delim);
}
};
// -------------------------------------------------------------------------
// - Non-const routines that do not require a device object
// -------------------------------------------------------------------------
/// Outputs n elements of mat delimited by the string delim
template <class mat_type>
inline void ucl_print(mat_type &mat, const size_t n, std::ostream &out,
const std::string delim) {
if (n>mat.numel()) {
std::cerr << "Attempted to ucl_print " << n << " elements of matrix "
<< "that only has " << mat.numel() << " elements.";
UCL_GERYON_EXIT;
}
_ucl_print<mat_type::MEM_TYPE>::p(mat,n,out,delim);
}
/// Outputs n elements of mat delimited by a space
template <class mat_type>
inline void ucl_print(mat_type &mat, const size_t n, std::ostream &out) {
ucl_print(mat,n,out," ");
}
/// Outputs n elements of mat delimited by a space to standard out
template <class mat_type>
inline void ucl_print(mat_type &mat, const size_t n) {
ucl_print(mat,n,std::cout," ");
}
/// Outputs upper left rows and cols of mat delimited by the string delim
template <class mat_type>
inline void ucl_print(mat_type &mat, const size_t rows, const size_t cols,
std::ostream &out, const std::string delim,
const std::string row_delim) {
if (rows*cols>mat.numel()) {
std::cerr << "Attempted to ucl_print " << rows*cols << " elements of matrix "
<< "that only has " << mat.numel() << " elements.";
UCL_GERYON_EXIT;
}
_ucl_print<mat_type::MEM_TYPE>::p(mat,rows,cols,out,delim,row_delim);
}
/// Outputs upper left rows and cols of mat delimited by a space
template <class mat_type>
inline void ucl_print(mat_type &mat, const size_t rows, const size_t cols,
std::ostream &out) {
ucl_print(mat,rows,cols,out," ","\n");
}
/// Outputs upper left rows and cols of mat delimited by a space to std out
template <class mat_type>
inline void ucl_print(mat_type &mat, const size_t rows,
const size_t cols) {
ucl_print(mat,rows,cols,std::cout," ","\n");
}
/// Outputs mat delimited by a space to standard out
template <class mat_type>
inline void ucl_print(mat_type &mat) {
ucl_print(mat,std::cout);
}
/// Outputs mat delimited by a space
template <class mat_type>
inline void ucl_print(mat_type &mat, std::ostream &out) {
if (mat_type::VECTOR==1)
ucl_print(mat,mat.cols(),out," ");
else
ucl_print(mat,mat.rows(),mat.cols(),out," ","\n");
}
// -------------------------------------------------------------------------
// - Const routines that do not require a device object
// -------------------------------------------------------------------------
/// Outputs n elements of mat delimited by the string delim
template <class mat_type>
inline void ucl_print(const mat_type &mat, const size_t n, std::ostream &out,
const std::string delim, UCL_Device &dev) {
if (n>mat.numel()) {
std::cerr << "Attempted to ucl_print " << n << " elements of matrix "
<< "that only has " << mat.numel() << " elements.";
UCL_GERYON_EXIT;
}
_ucl_print<mat_type::MEM_TYPE>::p(mat,n,out,delim,dev);
}
/// Outputs n elements of mat delimited by a space
template <class mat_type>
inline void ucl_print(const mat_type &mat, const size_t n, std::ostream &out,
UCL_Device &dev) {
ucl_print(mat,n,out," ",dev);
}
/// Outputs n elements of mat delimited by a space to standard out
template <class mat_type>
inline void ucl_print(const mat_type &mat, const size_t n,
UCL_Device &dev) {
ucl_print(mat,n,std::cout," ",dev);
}
/// Outputs upper left rows and cols of mat delimited by the string delim
template <class mat_type>
inline void ucl_print(const mat_type &mat,const size_t rows,const size_t cols,
std::ostream &out, const std::string delim,
const std::string row_delim, UCL_Device &dev) {
if (rows*cols>mat.numel()) {
std::cerr << "Attempted to ucl_print " << rows*cols << " elements of matrix "
<< "that only has " << mat.numel() << " elements.";
UCL_GERYON_EXIT;
}
_ucl_print<mat_type::MEM_TYPE>::p(mat,rows,cols,out,delim,row_delim,dev);
}
/// Outputs upper left rows and cols of mat delimited by a space
template <class mat_type>
inline void ucl_print(const mat_type &mat,const size_t rows,const size_t cols,
std::ostream &out, UCL_Device &dev) {
ucl_print(mat,rows,cols,out," ","\n",dev);
}
/// Outputs upper left rows and cols of mat delimited by a space to std out
template <class mat_type>
inline void ucl_print(const mat_type &mat, const size_t rows,
const size_t cols, UCL_Device &dev) {
ucl_print(mat,rows,cols,std::cout," ","\n",dev);
}
/// Outputs mat delimited by a space to standard out
template <class mat_type>
inline void ucl_print(const mat_type &mat, UCL_Device &dev) {
ucl_print(mat,std::cout,dev);
}
/// Outputs mat delimited by a space
template <class mat_type>
inline void ucl_print(const mat_type &mat, std::ostream &out, UCL_Device &dev) {
if (mat_type::VECTOR==1)
ucl_print(mat,mat.cols(),out," ",dev);
else
ucl_print(mat,mat.rows(),mat.cols(),out," ","\n",dev);
}
// -------------------------------------------------------------------------
// - Operator << Overloading
// -------------------------------------------------------------------------
template <class numtyp>
inline std::ostream & operator << (std::ostream &out, UCL_H_Vec<numtyp> &mat)
{ ucl_print(mat,out); return out; }
template <class numtyp>
inline std::ostream & operator << (std::ostream &out, UCL_H_Mat<numtyp> &mat)
{ ucl_print(mat,out); return out; }
template <class numtyp>
inline std::ostream & operator << (std::ostream &out, UCL_D_Vec<numtyp> &mat)
{ ucl_print(mat,out); return out; }
template <class numtyp>
inline std::ostream & operator << (std::ostream &out, UCL_D_Mat<numtyp> &mat)
{ ucl_print(mat,out); return out; }
template <class t1, class t2>
inline std::ostream & operator << (std::ostream &out, UCL_Vector<t1,t2> &mat)
{ ucl_print(mat.host,out); return out; }
template <class t1, class t2>
inline std::ostream & operator << (std::ostream &out, UCL_Matrix<t1,t2> &mat)
{ ucl_print(mat.host,out); return out; }
#endif
|