/usr/include/fflas-ffpack/paladin/blockcuts.inl is in fflas-ffpack-common 2.2.2-5.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 | /* -*- mode: C++; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
// vim:sts=4:sw=4:ts=4:noet:sr:cino=>s,f0,{0,g0,(0,\:0,t0,+0,=s
/* fflas/fflas_bounds.inl
* Copyright (C) 2013 Jean-Guillaume Dumas
*
* Written by Jean-Guillaume Dumas <Jean-Guillaume.Dumas@imag.fr>
*
*
* ========LICENCE========
* This file is part of the library FFLAS-FFPACK.
*
* FFLAS-FFPACK is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* ========LICENCE========
*.
*/
#ifndef __FFLASFFPACK_fflas_blockcuts_INL
#define __FFLASFFPACK_fflas_blockcuts_INL
#include <fflas-ffpack/fflas/fflas_enum.h>
#include <math.h>
#define __FFLASFFPACK_MINBLOCKCUTS ((size_t)256)
namespace FFLAS {
// enum CuttingStrategy {
// SINGLE ,
// ROW ,
// COLUMN ,
// BLOCK ,
// RECURSIVE
// };
// enum StrategyParameter {
// FIXED ,
// THREADS ,
// GRAIN ,
// TWO_D ,
// THREE_D_INPLACE ,
// THREE_D_ADAPT ,
// TWO_D_ADAPT ,
// THREE_D
// };
namespace CuttingStrategy{
struct Single{};
struct Row{};
struct Column{};
struct Block{};
struct Recursive{};
}
namespace StrategyParameter{
struct Fixed{};
struct Threads{};
struct Grain{};
struct TwoD{};
struct TwoDAdaptive{};
struct ThreeD{};
struct ThreeDInPlace{};
struct ThreeDAdaptive{};
}
/*! ParSeqHelper for both fgemm and ftrsm
*/
/*! ParSeqHelper for both fgemm and ftrsm
*/
namespace ParSeqHelper {
template <typename C=CuttingStrategy::Block, typename P=StrategyParameter::Threads>
struct Parallel{
typedef C Cut;
typedef P Param;
Parallel(size_t n=NUM_THREADS):_numthreads(n){}
friend std::ostream& operator<<(std::ostream& out, const Parallel& p) {
return out << "Parallel: " << p.numthreads();
}
size_t numthreads() const { return _numthreads; }
size_t& set_numthreads(size_t n) { return _numthreads=n; }
// CuttingStrategy method() const { return _method; }
// StrategyParameter strategy() const { return _param; }
private:
size_t _numthreads;
// CuttingStrategy _method;
// StrategyParameter _param;
};
struct Sequential{
Sequential() {}
template<class Cut,class Param>
Sequential(Parallel<Cut,Param>& ) {}
friend std::ostream& operator<<(std::ostream& out, const Sequential&) {
return out << "Sequential";
}
size_t numthreads() const { return 1; }
// CuttingStrategy method() const { return SINGLE; }
// // numthreads==1 ==> a single block
// StrategyParameter strategy() const { return THREADS; }
};
}
template<class Cut=CuttingStrategy::Block, class Strat=StrategyParameter::Threads>
inline void BlockCuts(size_t& RBLOCKSIZE, size_t& CBLOCKSIZE,
const size_t m, const size_t n,
const size_t numthreads);
template<>
inline void BlockCuts<CuttingStrategy::Single,StrategyParameter::Threads>(size_t& RBLOCKSIZE,
size_t& CBLOCKSIZE,
const size_t m, const size_t n,
const size_t numthreads) {
assert(numthreads==1);
RBLOCKSIZE = std::max(m,(size_t)1);
CBLOCKSIZE = std::max(n,(size_t)1);
}
template<>
inline void BlockCuts<CuttingStrategy::Row,StrategyParameter::Fixed>(size_t& RBLOCKSIZE,
size_t& CBLOCKSIZE,
const size_t m, const size_t n,
const size_t numthreads) {
RBLOCKSIZE = std::max(std::min(m,__FFLASFFPACK_MINBLOCKCUTS),(size_t)1);
CBLOCKSIZE = std::max(n,(size_t)1);
}
template<>
inline void BlockCuts<CuttingStrategy::Row,StrategyParameter::Grain>(size_t& RBLOCKSIZE,
size_t& CBLOCKSIZE,
const size_t m, const size_t n,
const size_t grainsize) {
RBLOCKSIZE = std::max(std::min(m,grainsize),(size_t)1);
CBLOCKSIZE = std::max(n,(size_t)1);
}
template<>
inline void BlockCuts<CuttingStrategy::Block,StrategyParameter::Grain>(size_t& RBLOCKSIZE,
size_t& CBLOCKSIZE,
const size_t m, const size_t n,
const size_t grainsize) {
RBLOCKSIZE = std::max(std::min(m,grainsize),(size_t)1);
CBLOCKSIZE = std::max(std::min(n,grainsize),(size_t)1);
}
template<>
inline void BlockCuts<CuttingStrategy::Column,StrategyParameter::Fixed>(size_t& RBLOCKSIZE,
size_t& CBLOCKSIZE,
const size_t m, const size_t n,
const size_t numthreads) {
RBLOCKSIZE = std::max(m,(size_t)1);
CBLOCKSIZE = std::max(std::min(n,__FFLASFFPACK_MINBLOCKCUTS),(size_t)1);
}
template<>
inline void BlockCuts<CuttingStrategy::Column,StrategyParameter::Grain>(size_t& RBLOCKSIZE,
size_t& CBLOCKSIZE,
const size_t m, const size_t n,
const size_t grainsize) {
RBLOCKSIZE = std::max(m,(size_t)1);
CBLOCKSIZE = std::max(std::min(n,grainsize),(size_t)1);
}
template<>
inline void BlockCuts<CuttingStrategy::Block,StrategyParameter::Fixed>(size_t& RBLOCKSIZE,
size_t& CBLOCKSIZE,
const size_t m, const size_t n,
const size_t numthreads) {
RBLOCKSIZE = std::max(std::min(m,__FFLASFFPACK_MINBLOCKCUTS),(size_t)1);
CBLOCKSIZE = std::max(std::min(n,__FFLASFFPACK_MINBLOCKCUTS),(size_t)1);
}
template<>
inline void BlockCuts<CuttingStrategy::Row,StrategyParameter::Threads>(size_t& RBLOCKSIZE,
size_t& CBLOCKSIZE,
const size_t m, const size_t n,
const size_t numthreads) {
RBLOCKSIZE = std::max(m/numthreads,(size_t)1);
CBLOCKSIZE = std::max(n,(size_t)1);
}
template<>
inline void BlockCuts<CuttingStrategy::Column,StrategyParameter::Threads>(size_t& RBLOCKSIZE,
size_t& CBLOCKSIZE,
const size_t m, const size_t n,
const size_t numthreads) {
RBLOCKSIZE = std::max(m,(size_t)1);
CBLOCKSIZE = std::max(n/numthreads,(size_t)1);
}
template<>
inline void BlockCuts<CuttingStrategy::Block,StrategyParameter::Threads>(size_t& RBLOCKSIZE,
size_t& CBLOCKSIZE,
const size_t m, const size_t n,
const size_t numthreads) {
if (numthreads<65) {
//CP: Let's not compute these values all the time
const short maxtc[64] = {1,2,3,2,5,3,7,4,3,5,11,4,13,7,5,4,17,6,19,5,7,11,23,6,5,13,9,7,29,6,31,8,11,17,7,6,37,19,13,8,41,7,43,11,9,23,47,8,7,10,17,13,53,9,11,8,19,29,59,10,61,31,9,8};
const short maxtr[64] = {1,1,1,2,1,2,1,2,3,2,1,3,1,2,3,4,1,3,1,4,3,2,1,4,5,2,3,4,1,5,1,4,3,2,5,6,1,2,3,5,1,6,1,4,5,2,1,6,7,5,3,4,1,6,5,7,3,2,1,6,1,2,7,8};
RBLOCKSIZE=std::max(m/(size_t)maxtr[numthreads-1],(size_t)1);
CBLOCKSIZE=std::max(n/(size_t)maxtc[numthreads-1],(size_t)1);
} else {
const size_t maxt = (size_t)sqrt((double)numthreads);
size_t maxtr=maxt,maxtc=maxt;
for(size_t i=maxt; i>=1; --i) {
size_t j=maxt;
size_t newpr = i*j;
for( ; newpr < numthreads; ++j, newpr+=i ) {}
if (newpr == numthreads) {
maxtc = j;
maxtr = i;
break;
}
}
RBLOCKSIZE=std::max(m/maxtr,(size_t)1);
CBLOCKSIZE=std::max(n/maxtc,(size_t)1);
}
}
// inline void BlockCuts(size_t& r, size_t& c,
// size_t m, size_t n,
// const CuttingStrategy method,
// const StrategyParameter strategy,
// const size_t t) {
// switch(method) {
// case CuttingStrategy::Block:
// switch(strategy) {
// case StrategyParameter::Threads: BlockCuts<CuttingStrategy::Block,StrategyParameter::Threads>(r,c,m,n,t); break;
// case StrategyParameter::Grain: BlockCuts<CuttingStrategy::Block,StrategyParameter::Grain>(r,c,m,n,t); break;
// case StrategyParameter::Fixed: BlockCuts<CuttingStrategy::Block,StrategyParameter::Fixed>(r,c,m,n,t); break;
// default: BlockCuts<CuttingStrategy::Block,StrategyParameter::Threads>(r,c,m,n,t);
// }
// break;
// case CuttingStrategy::Row:
// switch(strategy) {
// case StrategyParameter::Threads: BlockCuts<CuttingStrategy::Row,StrategyParameter::Threads>(r,c,m,n,t); break;
// case StrategyParameter::Grain: BlockCuts<CuttingStrategy::Row,StrategyParameter::Grain>(r,c,m,n,t); break;
// case StrategyParameter::Fixed: BlockCuts<CuttingStrategy::Row,StrategyParameter::Fixed>(r,c,m,n,t); break;
// default: BlockCuts<CuttingStrategy::Row,StrategyParameter::Threads>(r,c,m,n,t);
// }
// break;
// case CuttingStrategy::Column:
// switch(strategy) {
// case StrategyParameter::Threads: BlockCuts<CuttingStrategy::Column,StrategyParameter::Threads>(r,c,m,n,t); break;
// case StrategyParameter::Grain: BlockCuts<CuttingStrategy::Column,StrategyParameter::Grain>(r,c,m,n,t); break;
// case StrategyParameter::Fixed: BlockCuts<CuttingStrategy::Column,StrategyParameter::Fixed>(r,c,m,n,t); break;
// default: BlockCuts<CuttingStrategy::Column,StrategyParameter::Threads>(r,c,m,n,t);
// }
// break;
// default: BlockCuts<CuttingStrategy::Block,StrategyParameter::Threads>(r,c,m,n,t);
// };
// }
template<class Cut=CuttingStrategy::Block, class Param=StrategyParameter::Threads>
inline void BlockCuts(size_t& rowBlockSize, size_t& colBlockSize,
size_t& lastRBS, size_t& lastCBS,
size_t& changeRBS, size_t& changeCBS,
size_t& numRowBlock, size_t& numColBlock,
size_t m, size_t n,
// const CuttingStrategy method,
// const StrategyParameter strategy,
const size_t numthreads) {
BlockCuts<Cut,Param>(rowBlockSize, colBlockSize, m, n, numthreads);
numRowBlock = m/rowBlockSize;
numColBlock = n/colBlockSize;
changeRBS = m-rowBlockSize*numRowBlock;
lastRBS = rowBlockSize;
if (changeRBS) ++rowBlockSize;
changeCBS = n-colBlockSize*numColBlock;
lastCBS = colBlockSize;
if (changeCBS) ++colBlockSize;
/*
// Better preserve numRowBlock and numColBlock
if (lastRBS) {
lastRBS = m-rowBlockSize*numRowBlock;
++rowBlockSize;
} else lastRBS = rowBlockSize;
if (lastCBS) {
lastCBS = n-colBlockSize*numColBlock;
++colBlockSize;
} else lastCBS = colBlockSize;
*/
// // Better preserve rowBlockSize and colBlockSize
// lastRBS = m % rowBlockSize;
// lastCBS = n % colBlockSize;
// if (lastRBS) ++numRowBlock; else lastRBS = rowBlockSize;
// if (lastCBS) ++numColBlock; else lastCBS = colBlockSize;
}
}
namespace FFLAS {
template <typename blocksize_t=size_t, typename Cut=CuttingStrategy::Block, typename Param=StrategyParameter::Threads>
struct ForStrategy1D {
ForStrategy1D(const blocksize_t n, const ParSeqHelper::Parallel<Cut,Param> H) {
build(n,H);
}
ForStrategy1D(const blocksize_t b, const blocksize_t e, const ParSeqHelper::Parallel<Cut,Param> H) {
build(e-b,H);
}
void build(const blocksize_t n, const ParSeqHelper::Parallel<Cut,Param> H) {
// std::cout<<"FS1D n : "<<n<<std::endl;
// std::cout<<"FS1D method : "<<method<<std::endl;
// std::cout<<"FS1D numthreads : "<<numthreads<<std::endl;
if ( Protected::AreEqual<Param, StrategyParameter::Threads>::value ) {
numBlock = std::max((blocksize_t)(H.numthreads()),(blocksize_t)1);
} else if ( Protected::AreEqual<Param,StrategyParameter::Grain>::value ) {
numBlock = std::max(n/ (blocksize_t)(H.numthreads()), (blocksize_t)1);
} else {
numBlock = std::max(n/(blocksize_t)(__FFLASFFPACK_MINBLOCKCUTS),(blocksize_t)1);
}
firstBlockSize = n/numBlock;
if (firstBlockSize<1) {
firstBlockSize = (blocksize_t)1;
numBlock = n;
}
changeBS = n - numBlock*firstBlockSize;
lastBlockSize = firstBlockSize;
if (changeBS) ++firstBlockSize;
// std::cout<<"FS1D 1BLOCKSIZE : "<<firstBlockSize<<std::endl;
// std::cout<<"FS1D 2BLOCKSIZE : "<<lastBlockSize<<std::endl;
// std::cout<<"FS1D changeBS : "<<changeBS<<std::endl;
// std::cout<<"FS1D NBlocks : "<<numBlock<<std::endl;
}
blocksize_t initialize() {
ibeg = 0; iend = firstBlockSize;
// std::cout << "FS1D 0 : " << 0 << std::endl;
// std::cout << "FS1D ibeg: " << ibeg << std::endl;
// std::cout << "FS1D iend: " << iend << std::endl;
return current = 0;
}
bool isTerminated() const { return current == numBlock; }
blocksize_t begin() const { return ibeg; }
blocksize_t end() const { return iend; }
blocksize_t blocksize() const { return firstBlockSize; }
blocksize_t numblocks() const { return numBlock; }
blocksize_t operator++() {
ibeg = iend;
iend += (++current<changeBS?firstBlockSize:lastBlockSize);
// std::cout << "FS1D i : " << current << std::endl;
// std::cout << "FS1D ibeg: " << ibeg << std::endl;
// std::cout << "FS1D iend: " << iend << std::endl;
return current;
}
protected:
blocksize_t ibeg, iend;
blocksize_t current;
blocksize_t firstBlockSize,lastBlockSize;
blocksize_t changeBS;
blocksize_t numBlock;
};
template <typename blocksize_t=size_t, typename Cut=CuttingStrategy::Block, typename Param=StrategyParameter::Threads>
struct ForStrategy2D {
ForStrategy2D(const blocksize_t m, const blocksize_t n, const ParSeqHelper::Parallel<Cut,Param> H)
{
BlockCuts<Cut,Param>(rowBlockSize, colBlockSize,
lastRBS, lastCBS,
changeRBS, changeCBS,
numRowBlock, numColBlock,
m, n,
// H.method(), H.strategy(),
H.numthreads());
BLOCKS = numRowBlock * numColBlock;
}
blocksize_t initialize() {
_ibeg = 0; _iend = rowBlockSize;
_jbeg = 0; _jend = colBlockSize;
return current = 0;
}
bool isTerminated() const { return current == BLOCKS; }
blocksize_t ibegin() const { return _ibeg; }
blocksize_t jbegin() const { return _jbeg; }
blocksize_t iend() const { return _iend; }
blocksize_t jend() const { return _jend; }
blocksize_t operator++() {
++current;
blocksize_t icurr = current/numColBlock;
blocksize_t jcurr = current%numColBlock;
if (jcurr) {
_jbeg = _jend;
_jend += (jcurr<changeCBS?colBlockSize:lastCBS);
} else {
_ibeg = _iend;
_iend += (icurr<changeRBS?rowBlockSize:lastRBS);
_jbeg = 0;
_jend = colBlockSize;
}
return current;
}
friend std::ostream& operator<<(std::ostream& out, const ForStrategy2D& FS2D) {
out<<"RBLOCKSIZE: "<<FS2D.rowBlockSize<<std::endl;
out<<"CBLOCKSIZE: "<<FS2D.colBlockSize<<std::endl;
out<<"changeRBS : "<<FS2D.changeRBS<<std::endl;
out<<"changeCBS : "<<FS2D.changeCBS<<std::endl;
out<<"lastRBS : "<<FS2D.lastRBS<<std::endl;
out<<"lastCBS : "<<FS2D.lastCBS<<std::endl;
out<<"NrowBlocks: "<<FS2D.numRowBlock<<std::endl;
out<<"NcolBlocks: "<<FS2D.numColBlock<<std::endl;
out<<"curr: " << FS2D.current << '/' << FS2D.BLOCKS << std::endl;
out<<"_ibeg: " << FS2D._ibeg << std::endl;
out<<"_iend: " << FS2D._iend << std::endl;
out<<"_jbeg: " << FS2D._jbeg << std::endl;
out<<"_jend: " << FS2D._jend << std::endl;
return out;
}
blocksize_t rowblocksize() const { return rowBlockSize; }
blocksize_t rownumblocks() const { return numRowBlock; }
blocksize_t colblocksize() const { return colBlockSize; }
blocksize_t colnumblocks() const { return numColBlock; }
protected:
blocksize_t _ibeg, _iend, _jbeg, _jend;
blocksize_t rowBlockSize, colBlockSize;
blocksize_t current;
blocksize_t lastRBS; blocksize_t lastCBS;
blocksize_t changeRBS; blocksize_t changeCBS;
blocksize_t numRowBlock; blocksize_t numColBlock;
blocksize_t BLOCKS;
};
}
#endif
|