/usr/include/sofa/gpu/cuda/CudaMechanicalObject.inl is in libsofa1-dev 1.0~beta4-10ubuntu2.
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 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 | /******************************************************************************
* SOFA, Simulation Open-Framework Architecture, version 1.0 beta 4 *
* (c) 2006-2009 MGH, INRIA, USTL, UJF, CNRS *
* *
* This library 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. *
*******************************************************************************
* SOFA :: Modules *
* *
* Authors: The SOFA Team and external contributors (see Authors.txt) *
* *
* Contact information: contact@sofa-framework.org *
******************************************************************************/
#ifndef SOFA_GPU_CUDA_CUDAMECHANICALOBJECT_INL
#define SOFA_GPU_CUDA_CUDAMECHANICALOBJECT_INL
#include "CudaMechanicalObject.h"
#include <sofa/component/container/MechanicalObject.inl>
namespace sofa
{
namespace gpu
{
namespace cuda
{
extern "C"
{
void MechanicalObjectCudaVec3f_vAssign(unsigned int size, void* res, const void* a);
void MechanicalObjectCudaVec3f_vClear(unsigned int size, void* res);
void MechanicalObjectCudaVec3f_vMEq(unsigned int size, void* res, float f);
void MechanicalObjectCudaVec3f_vEqBF(unsigned int size, void* res, const void* b, float f);
void MechanicalObjectCudaVec3f_vPEq(unsigned int size, void* res, const void* a);
void MechanicalObjectCudaVec3f_vPEqBF(unsigned int size, void* res, const void* b, float f);
void MechanicalObjectCudaVec3f_vAdd(unsigned int size, void* res, const void* a, const void* b);
void MechanicalObjectCudaVec3f_vOp(unsigned int size, void* res, const void* a, const void* b, float f);
void MechanicalObjectCudaVec3f_vIntegrate(unsigned int size, const void* a, void* v, void* x, float f_v_v, float f_v_a, float f_x_x, float f_x_v);
void MechanicalObjectCudaVec3f_vPEqBF2(unsigned int size, void* res1, const void* b1, float f1, void* res2, const void* b2, float f2);
void MechanicalObjectCudaVec3f_vPEq4BF2(unsigned int size, void* res1, const void* b11, float f11, const void* b12, float f12, const void* b13, float f13, const void* b14, float f14,
void* res2, const void* b21, float f21, const void* b22, float f22, const void* b23, float f23, const void* b24, float f24);
void MechanicalObjectCudaVec3f_vOp2(unsigned int size, void* res1, const void* a1, const void* b1, float f1, void* res2, const void* a2, const void* b2, float f2);
int MechanicalObjectCudaVec3f_vDotTmpSize(unsigned int size);
void MechanicalObjectCudaVec3f_vDot(unsigned int size, float* res, const void* a, const void* b, void* tmp, float* cputmp);
void MechanicalObjectCudaVec3f1_vAssign(unsigned int size, void* res, const void* a);
void MechanicalObjectCudaVec3f1_vClear(unsigned int size, void* res);
void MechanicalObjectCudaVec3f1_vMEq(unsigned int size, void* res, float f);
void MechanicalObjectCudaVec3f1_vEqBF(unsigned int size, void* res, const void* b, float f);
void MechanicalObjectCudaVec3f1_vPEq(unsigned int size, void* res, const void* a);
void MechanicalObjectCudaVec3f1_vPEqBF(unsigned int size, void* res, const void* b, float f);
void MechanicalObjectCudaVec3f1_vAdd(unsigned int size, void* res, const void* a, const void* b);
void MechanicalObjectCudaVec3f1_vOp(unsigned int size, void* res, const void* a, const void* b, float f);
void MechanicalObjectCudaVec3f1_vIntegrate(unsigned int size, const void* a, void* v, void* x, float f_v_v, float f_v_a, float f_x_x, float f_x_v);
void MechanicalObjectCudaVec3f1_vPEqBF2(unsigned int size, void* res1, const void* b1, float f1, void* res2, const void* b2, float f2);
void MechanicalObjectCudaVec3f1_vPEq4BF2(unsigned int size, void* res1, const void* b11, float f11, const void* b12, float f12, const void* b13, float f13, const void* b14, float f14,
void* res2, const void* b21, float f21, const void* b22, float f22, const void* b23, float f23, const void* b24, float f24);
void MechanicalObjectCudaVec3f1_vOp2(unsigned int size, void* res1, const void* a1, const void* b1, float f1, void* res2, const void* a2, const void* b2, float f2);
int MechanicalObjectCudaVec3f1_vDotTmpSize(unsigned int size);
void MechanicalObjectCudaVec3f1_vDot(unsigned int size, float* res, const void* a, const void* b, void* tmp, float* cputmp);
#ifdef SOFA_GPU_CUDA_DOUBLE
void MechanicalObjectCudaVec3d_vAssign(unsigned int size, void* res, const void* a);
void MechanicalObjectCudaVec3d_vClear(unsigned int size, void* res);
void MechanicalObjectCudaVec3d_vMEq(unsigned int size, void* res, double f);
void MechanicalObjectCudaVec3d_vEqBF(unsigned int size, void* res, const void* b, double f);
void MechanicalObjectCudaVec3d_vPEq(unsigned int size, void* res, const void* a);
void MechanicalObjectCudaVec3d_vPEqBF(unsigned int size, void* res, const void* b, double f);
void MechanicalObjectCudaVec3d_vAdd(unsigned int size, void* res, const void* a, const void* b);
void MechanicalObjectCudaVec3d_vOp(unsigned int size, void* res, const void* a, const void* b, double f);
void MechanicalObjectCudaVec3d_vIntegrate(unsigned int size, const void* a, void* v, void* x, double f_v_v, double f_v_a, double f_x_x, double f_x_v);
void MechanicalObjectCudaVec3d_vPEqBF2(unsigned int size, void* res1, const void* b1, double f1, void* res2, const void* b2, double f2);
void MechanicalObjectCudaVec3d_vPEq4BF2(unsigned int size, void* res1, const void* b11, double f11, const void* b12, double f12, const void* b13, double f13, const void* b14, double f14,
void* res2, const void* b21, double f21, const void* b22, double f22, const void* b23, double f23, const void* b24, double f24);
void MechanicalObjectCudaVec3d_vOp2(unsigned int size, void* res1, const void* a1, const void* b1, double f1, void* res2, const void* a2, const void* b2, double f2);
int MechanicalObjectCudaVec3d_vDotTmpSize(unsigned int size);
void MechanicalObjectCudaVec3d_vDot(unsigned int size, double* res, const void* a, const void* b, void* tmp, double* cputmp);
void MechanicalObjectCudaVec3d1_vAssign(unsigned int size, void* res, const void* a);
void MechanicalObjectCudaVec3d1_vClear(unsigned int size, void* res);
void MechanicalObjectCudaVec3d1_vMEq(unsigned int size, void* res, double f);
void MechanicalObjectCudaVec3d1_vEqBF(unsigned int size, void* res, const void* b, double f);
void MechanicalObjectCudaVec3d1_vPEq(unsigned int size, void* res, const void* a);
void MechanicalObjectCudaVec3d1_vPEqBF(unsigned int size, void* res, const void* b, double f);
void MechanicalObjectCudaVec3d1_vAdd(unsigned int size, void* res, const void* a, const void* b);
void MechanicalObjectCudaVec3d1_vOp(unsigned int size, void* res, const void* a, const void* b, double f);
void MechanicalObjectCudaVec3d1_vIntegrate(unsigned int size, const void* a, void* v, void* x, double f_v_v, double f_v_a, double f_x_x, double f_x_v);
void MechanicalObjectCudaVec3d1_vPEqBF2(unsigned int size, void* res1, const void* b1, double f1, void* res2, const void* b2, double f2);
void MechanicalObjectCudaVec3d1_vPEq4BF2(unsigned int size, void* res1, const void* b11, double f11, const void* b12, double f12, const void* b13, double f13, const void* b14, double f14,
void* res2, const void* b21, double f21, const void* b22, double f22, const void* b23, double f23, const void* b24, double f24);
void MechanicalObjectCudaVec3d1_vOp2(unsigned int size, void* res1, const void* a1, const void* b1, double f1, void* res2, const void* a2, const void* b2, double f2);
int MechanicalObjectCudaVec3d1_vDotTmpSize(unsigned int size);
void MechanicalObjectCudaVec3d1_vDot(unsigned int size, double* res, const void* a, const void* b, void* tmp, double* cputmp);
#endif // SOFA_GPU_CUDA_DOUBLE
} // extern "C"
template<>
class CudaKernelsMechanicalObject<CudaVec3fTypes>
{
public:
static void vAssign(unsigned int size, void* res, const void* a)
{ MechanicalObjectCudaVec3f_vAssign(size, res, a); }
static void vClear(unsigned int size, void* res)
{ MechanicalObjectCudaVec3f_vClear(size, res); }
static void vMEq(unsigned int size, void* res, float f)
{ MechanicalObjectCudaVec3f_vMEq(size, res, f); }
static void vEqBF(unsigned int size, void* res, const void* b, float f)
{ MechanicalObjectCudaVec3f_vEqBF(size, res, b, f); }
static void vPEq(unsigned int size, void* res, const void* a)
{ MechanicalObjectCudaVec3f_vPEq(size, res, a); }
static void vPEqBF(unsigned int size, void* res, const void* b, float f)
{ MechanicalObjectCudaVec3f_vPEqBF(size, res, b, f); }
static void vAdd(unsigned int size, void* res, const void* a, const void* b)
{ MechanicalObjectCudaVec3f_vAdd(size, res, a, b); }
static void vOp(unsigned int size, void* res, const void* a, const void* b, float f)
{ MechanicalObjectCudaVec3f_vOp(size, res, a, b, f); }
static void vIntegrate(unsigned int size, const void* a, void* v, void* x, float f_v_v, float f_v_a, float f_x_x, float f_x_v)
{ MechanicalObjectCudaVec3f_vIntegrate(size, a, v, x, f_v_v, f_v_a, f_x_x, f_x_v); }
static void vPEqBF2(unsigned int size, void* res1, const void* b1, float f1, void* res2, const void* b2, float f2)
{ MechanicalObjectCudaVec3f_vPEqBF2(size, res1, b1, f1, res2, b2, f2); }
static void vPEq4BF2(unsigned int size, void* res1, const void* b11, float f11, const void* b12, float f12, const void* b13, float f13, const void* b14, float f14,
void* res2, const void* b21, float f21, const void* b22, float f22, const void* b23, float f23, const void* b24, float f24)
{ MechanicalObjectCudaVec3f_vPEq4BF2(size, res1, b11, f11, b12, f12, b13, f13, b14, f14,
res2, b21, f21, b22, f22, b23, f23, b24, f24); }
static void vOp2(unsigned int size, void* res1, const void* a1, const void* b1, float f1, void* res2, const void* a2, const void* b2, float f2)
{ MechanicalObjectCudaVec3f_vOp2(size, res1, a1, b1, f1, res2, a2, b2, f2); }
static int vDotTmpSize(unsigned int size)
{ return MechanicalObjectCudaVec3f_vDotTmpSize(size); }
static void vDot(unsigned int size, float* res, const void* a, const void* b, void* tmp, float* cputmp)
{ MechanicalObjectCudaVec3f_vDot(size, res, a, b, tmp, cputmp); }
};
template<>
class CudaKernelsMechanicalObject<CudaVec3f1Types>
{
public:
static void vAssign(unsigned int size, void* res, const void* a)
{ MechanicalObjectCudaVec3f1_vAssign(size, res, a); }
static void vClear(unsigned int size, void* res)
{ MechanicalObjectCudaVec3f1_vClear(size, res); }
static void vMEq(unsigned int size, void* res, float f)
{ MechanicalObjectCudaVec3f1_vMEq(size, res, f); }
static void vEqBF(unsigned int size, void* res, const void* b, float f)
{ MechanicalObjectCudaVec3f1_vEqBF(size, res, b, f); }
static void vPEq(unsigned int size, void* res, const void* a)
{ MechanicalObjectCudaVec3f1_vPEq(size, res, a); }
static void vPEqBF(unsigned int size, void* res, const void* b, float f)
{ MechanicalObjectCudaVec3f1_vPEqBF(size, res, b, f); }
static void vAdd(unsigned int size, void* res, const void* a, const void* b)
{ MechanicalObjectCudaVec3f1_vAdd(size, res, a, b); }
static void vOp(unsigned int size, void* res, const void* a, const void* b, float f)
{ MechanicalObjectCudaVec3f1_vOp(size, res, a, b, f); }
static void vIntegrate(unsigned int size, const void* a, void* v, void* x, float f_v_v, float f_v_a, float f_x_x, float f_x_v)
{ MechanicalObjectCudaVec3f1_vIntegrate(size, a, v, x, f_v_v, f_v_a, f_x_x, f_x_v); }
static void vPEqBF2(unsigned int size, void* res1, const void* b1, float f1, void* res2, const void* b2, float f2)
{ MechanicalObjectCudaVec3f1_vPEqBF2(size, res1, b1, f1, res2, b2, f2); }
static void vPEq4BF2(unsigned int size, void* res1, const void* b11, float f11, const void* b12, float f12, const void* b13, float f13, const void* b14, float f14,
void* res2, const void* b21, float f21, const void* b22, float f22, const void* b23, float f23, const void* b24, float f24)
{ MechanicalObjectCudaVec3f1_vPEq4BF2(size, res1, b11, f11, b12, f12, b13, f13, b14, f14,
res2, b21, f21, b22, f22, b23, f23, b24, f24); }
static void vOp2(unsigned int size, void* res1, const void* a1, const void* b1, float f1, void* res2, const void* a2, const void* b2, float f2)
{ MechanicalObjectCudaVec3f1_vOp2(size, res1, a1, b1, f1, res2, a2, b2, f2); }
static int vDotTmpSize(unsigned int size)
{ return MechanicalObjectCudaVec3f1_vDotTmpSize(size); }
static void vDot(unsigned int size, float* res, const void* a, const void* b, void* tmp, float* cputmp)
{ MechanicalObjectCudaVec3f1_vDot(size, res, a, b, tmp, cputmp); }
};
#ifdef SOFA_GPU_CUDA_DOUBLE
template<>
class CudaKernelsMechanicalObject<CudaVec3dTypes>
{
public:
static void vAssign(unsigned int size, void* res, const void* a)
{ MechanicalObjectCudaVec3d_vAssign(size, res, a); }
static void vClear(unsigned int size, void* res)
{ MechanicalObjectCudaVec3d_vClear(size, res); }
static void vMEq(unsigned int size, void* res, double f)
{ MechanicalObjectCudaVec3d_vMEq(size, res, f); }
static void vEqBF(unsigned int size, void* res, const void* b, double f)
{ MechanicalObjectCudaVec3d_vEqBF(size, res, b, f); }
static void vPEq(unsigned int size, void* res, const void* a)
{ MechanicalObjectCudaVec3d_vPEq(size, res, a); }
static void vPEqBF(unsigned int size, void* res, const void* b, double f)
{ MechanicalObjectCudaVec3d_vPEqBF(size, res, b, f); }
static void vAdd(unsigned int size, void* res, const void* a, const void* b)
{ MechanicalObjectCudaVec3d_vAdd(size, res, a, b); }
static void vOp(unsigned int size, void* res, const void* a, const void* b, double f)
{ MechanicalObjectCudaVec3d_vOp(size, res, a, b, f); }
static void vIntegrate(unsigned int size, const void* a, void* v, void* x, double f_v_v, double f_v_a, double f_x_x, double f_x_v)
{ MechanicalObjectCudaVec3d_vIntegrate(size, a, v, x, f_v_v, f_v_a, f_x_x, f_x_v); }
static void vPEqBF2(unsigned int size, void* res1, const void* b1, double f1, void* res2, const void* b2, double f2)
{ MechanicalObjectCudaVec3d_vPEqBF2(size, res1, b1, f1, res2, b2, f2); }
static void vPEq4BF2(unsigned int size, void* res1, const void* b11, double f11, const void* b12, double f12, const void* b13, double f13, const void* b14, double f14,
void* res2, const void* b21, double f21, const void* b22, double f22, const void* b23, double f23, const void* b24, double f24)
{ MechanicalObjectCudaVec3d_vPEq4BF2(size, res1, b11, f11, b12, f12, b13, f13, b14, f14,
res2, b21, f21, b22, f22, b23, f23, b24, f24); }
static void vOp2(unsigned int size, void* res1, const void* a1, const void* b1, double f1, void* res2, const void* a2, const void* b2, double f2)
{ MechanicalObjectCudaVec3d_vOp2(size, res1, a1, b1, f1, res2, a2, b2, f2); }
static int vDotTmpSize(unsigned int size)
{ return MechanicalObjectCudaVec3d_vDotTmpSize(size); }
static void vDot(unsigned int size, double* res, const void* a, const void* b, void* tmp, double* cputmp)
{ MechanicalObjectCudaVec3d_vDot(size, res, a, b, tmp, cputmp); }
};
template<>
class CudaKernelsMechanicalObject<CudaVec3d1Types>
{
public:
static void vAssign(unsigned int size, void* res, const void* a)
{ MechanicalObjectCudaVec3d1_vAssign(size, res, a); }
static void vClear(unsigned int size, void* res)
{ MechanicalObjectCudaVec3d1_vClear(size, res); }
static void vMEq(unsigned int size, void* res, double f)
{ MechanicalObjectCudaVec3d1_vMEq(size, res, f); }
static void vEqBF(unsigned int size, void* res, const void* b, double f)
{ MechanicalObjectCudaVec3d1_vEqBF(size, res, b, f); }
static void vPEq(unsigned int size, void* res, const void* a)
{ MechanicalObjectCudaVec3d1_vPEq(size, res, a); }
static void vPEqBF(unsigned int size, void* res, const void* b, double f)
{ MechanicalObjectCudaVec3d1_vPEqBF(size, res, b, f); }
static void vAdd(unsigned int size, void* res, const void* a, const void* b)
{ MechanicalObjectCudaVec3d1_vAdd(size, res, a, b); }
static void vOp(unsigned int size, void* res, const void* a, const void* b, double f)
{ MechanicalObjectCudaVec3d1_vOp(size, res, a, b, f); }
static void vIntegrate(unsigned int size, const void* a, void* v, void* x, double f_v_v, double f_v_a, double f_x_x, double f_x_v)
{ MechanicalObjectCudaVec3d1_vIntegrate(size, a, v, x, f_v_v, f_v_a, f_x_x, f_x_v); }
static void vPEqBF2(unsigned int size, void* res1, const void* b1, double f1, void* res2, const void* b2, double f2)
{ MechanicalObjectCudaVec3d1_vPEqBF2(size, res1, b1, f1, res2, b2, f2); }
static void vPEq4BF2(unsigned int size, void* res1, const void* b11, double f11, const void* b12, double f12, const void* b13, double f13, const void* b14, double f14,
void* res2, const void* b21, double f21, const void* b22, double f22, const void* b23, double f23, const void* b24, double f24)
{ MechanicalObjectCudaVec3d1_vPEq4BF2(size, res1, b11, f11, b12, f12, b13, f13, b14, f14,
res2, b21, f21, b22, f22, b23, f23, b24, f24); }
static void vOp2(unsigned int size, void* res1, const void* a1, const void* b1, double f1, void* res2, const void* a2, const void* b2, double f2)
{ MechanicalObjectCudaVec3d1_vOp2(size, res1, a1, b1, f1, res2, a2, b2, f2); }
static int vDotTmpSize(unsigned int size)
{ return MechanicalObjectCudaVec3d1_vDotTmpSize(size); }
static void vDot(unsigned int size, double* res, const void* a, const void* b, void* tmp, double* cputmp)
{ MechanicalObjectCudaVec3d1_vDot(size, res, a, b, tmp, cputmp); }
};
#endif // SOFA_GPU_CUDA_DOUBLE
} // namespace cuda
} // namespace gpu
namespace component
{
using namespace gpu::cuda;
template<class TCoord, class TDeriv, class TReal>
void MechanicalObjectInternalData< gpu::cuda::CudaVectorTypes<TCoord,TDeriv,TReal> >::accumulateForce(Main* m)
{
if (!m->externalForces->empty())
{
Kernels::vAssign(m->externalForces->size(), m->f->deviceWrite(), m->externalForces->deviceRead());
}
}
template<class TCoord, class TDeriv, class TReal>
void MechanicalObjectInternalData< gpu::cuda::CudaVectorTypes<TCoord,TDeriv,TReal> >::vAlloc(Main* m, VecId v)
{
if (v.type == VecId::V_COORD && v.index >= VecId::V_FIRST_DYNAMIC_INDEX)
{
VecCoord* vec = m->getVecCoord(v.index);
vec->fastResize(m->vsize);
}
else if (v.type == VecId::V_DERIV && v.index >= VecId::V_FIRST_DYNAMIC_INDEX)
{
VecDeriv* vec = m->getVecDeriv(v.index);
vec->fastResize(m->vsize);
}
else
{
std::cerr << "Invalid alloc operation ("<<v<<")\n";
return;
}
//vOp(v); // clear vector
}
template<class TCoord, class TDeriv, class TReal>
void MechanicalObjectInternalData< gpu::cuda::CudaVectorTypes<TCoord,TDeriv,TReal> >::vOp(Main* m, VecId v, VecId a, VecId b, double f)
{
if(v.isNull())
{
// ERROR
std::cerr << "Invalid vOp operation ("<<v<<','<<a<<','<<b<<','<<f<<")\n";
return;
}
//std::cout << "> vOp operation ("<<v<<','<<a<<','<<b<<','<<f<<")\n";
if (a.isNull())
{
if (b.isNull())
{
// v = 0
if (v.type == VecId::V_COORD)
{
VecCoord* vv = m->getVecCoord(v.index);
vv->fastResize(m->vsize);
Kernels::vClear(vv->size(), vv->deviceWrite());
}
else
{
VecDeriv* vv = m->getVecDeriv(v.index);
vv->fastResize(m->vsize);
Kernels::vClear(vv->size(), vv->deviceWrite());
}
}
else
{
if (b.type != v.type)
{
// ERROR
std::cerr << "Invalid vOp operation ("<<v<<','<<a<<','<<b<<','<<f<<")\n";
return;
}
if (v == b)
{
// v *= f
if (v.type == VecId::V_COORD)
{
VecCoord* vv = m->getVecCoord(v.index);
Kernels::vMEq(vv->size(), vv->deviceWrite(), (Real) f);
}
else
{
VecDeriv* vv = m->getVecDeriv(v.index);
Kernels::vMEq(vv->size(), vv->deviceWrite(), (Real) f);
}
}
else
{
// v = b*f
if (v.type == VecId::V_COORD)
{
VecCoord* vv = m->getVecCoord(v.index);
VecCoord* vb = m->getVecCoord(b.index);
vv->fastResize(vb->size());
Kernels::vEqBF(vv->size(), vv->deviceWrite(), vb->deviceRead(), (Real) f);
}
else
{
VecDeriv* vv = m->getVecDeriv(v.index);
VecDeriv* vb = m->getVecDeriv(b.index);
vv->fastResize(vb->size());
Kernels::vEqBF(vv->size(), vv->deviceWrite(), vb->deviceRead(), (Real) f);
}
}
}
}
else
{
if (a.type != v.type)
{
// ERROR
std::cerr << "Invalid vOp operation ("<<v<<','<<a<<','<<b<<','<<f<<")\n";
return;
}
if (b.isNull())
{
// v = a
if (v.type == VecId::V_COORD)
{
VecCoord* vv = m->getVecCoord(v.index);
VecCoord* va = m->getVecCoord(a.index);
vv->fastResize(va->size());
Kernels::vAssign(vv->size(), vv->deviceWrite(), va->deviceRead());
}
else
{
VecDeriv* vv = m->getVecDeriv(v.index);
VecDeriv* va = m->getVecDeriv(a.index);
vv->fastResize(va->size());
Kernels::vAssign(vv->size(), vv->deviceWrite(), va->deviceRead());
}
}
else
{
if (v == a)
{
if (f==1.0)
{
// v += b
if (v.type == VecId::V_COORD)
{
VecCoord* vv = m->getVecCoord(v.index);
if (b.type == VecId::V_COORD)
{
VecCoord* vb = m->getVecCoord(b.index);
vv->resize(vb->size());
Kernels::vPEq(vv->size(), vv->deviceWrite(), vb->deviceRead());
}
else
{
VecDeriv* vb = m->getVecDeriv(b.index);
vv->resize(vb->size());
Kernels::vPEq(vv->size(), vv->deviceWrite(), vb->deviceRead());
}
}
else if (b.type == VecId::V_DERIV)
{
VecDeriv* vv = m->getVecDeriv(v.index);
VecDeriv* vb = m->getVecDeriv(b.index);
vv->resize(vb->size());
Kernels::vPEq(vv->size(), vv->deviceWrite(), vb->deviceRead());
}
else
{
// ERROR
std::cerr << "Invalid vOp operation ("<<v<<','<<a<<','<<b<<','<<f<<")\n";
return;
}
}
else
{
// v += b*f
if (v.type == VecId::V_COORD)
{
VecCoord* vv = m->getVecCoord(v.index);
if (b.type == VecId::V_COORD)
{
VecCoord* vb = m->getVecCoord(b.index);
vv->resize(vb->size());
Kernels::vPEqBF(vv->size(), vv->deviceWrite(), vb->deviceRead(), (Real)f);
}
else
{
VecDeriv* vb = m->getVecDeriv(b.index);
vv->resize(vb->size());
Kernels::vPEqBF(vv->size(), vv->deviceWrite(), vb->deviceRead(), (Real)f);
}
}
else if (b.type == VecId::V_DERIV)
{
VecDeriv* vv = m->getVecDeriv(v.index);
VecDeriv* vb = m->getVecDeriv(b.index);
vv->resize(vb->size());
Kernels::vPEqBF(vv->size(), vv->deviceWrite(), vb->deviceRead(), (Real)f);
}
else
{
// ERROR
std::cerr << "Invalid vOp operation ("<<v<<','<<a<<','<<b<<','<<f<<")\n";
return;
}
}
}
else
{
if (f==1.0)
{
// v = a+b
if (v.type == VecId::V_COORD)
{
VecCoord* vv = m->getVecCoord(v.index);
VecCoord* va = m->getVecCoord(a.index);
vv->fastResize(va->size());
if (b.type == VecId::V_COORD)
{
VecCoord* vb = m->getVecCoord(b.index);
Kernels::vAdd(vv->size(), vv->deviceWrite(), va->deviceRead(), vb->deviceRead());
}
else
{
VecDeriv* vb = m->getVecDeriv(b.index);
Kernels::vAdd(vv->size(), vv->deviceWrite(), va->deviceRead(), vb->deviceRead());
}
}
else if (b.type == VecId::V_DERIV)
{
VecDeriv* vv = m->getVecDeriv(v.index);
VecDeriv* va = m->getVecDeriv(a.index);
VecDeriv* vb = m->getVecDeriv(b.index);
vv->fastResize(va->size());
Kernels::vAdd(vv->size(), vv->deviceWrite(), va->deviceRead(), vb->deviceRead());
}
else
{
// ERROR
std::cerr << "Invalid vOp operation ("<<v<<','<<a<<','<<b<<','<<f<<")\n";
return;
}
}
else
{
// v = a+b*f
if (v.type == VecId::V_COORD)
{
VecCoord* vv = m->getVecCoord(v.index);
VecCoord* va = m->getVecCoord(a.index);
vv->fastResize(va->size());
if (b.type == VecId::V_COORD)
{
VecCoord* vb = m->getVecCoord(b.index);
Kernels::vOp(vv->size(), vv->deviceWrite(), va->deviceRead(), vb->deviceRead(), (Real)f);
}
else
{
VecDeriv* vb = m->getVecDeriv(b.index);
Kernels::vOp(vv->size(), vv->deviceWrite(), va->deviceRead(), vb->deviceRead(), (Real)f);
}
}
else if (b.type == VecId::V_DERIV)
{
VecDeriv* vv = m->getVecDeriv(v.index);
VecDeriv* va = m->getVecDeriv(a.index);
VecDeriv* vb = m->getVecDeriv(b.index);
vv->fastResize(va->size());
Kernels::vOp(vv->size(), vv->deviceWrite(), va->deviceRead(), vb->deviceRead(), (Real)f);
}
else
{
// ERROR
std::cerr << "Invalid vOp operation ("<<v<<','<<a<<','<<b<<','<<f<<")\n";
return;
}
}
}
}
}
//std::cout << "< vOp operation ("<<v<<','<<a<<','<<b<<','<<f<<")\n";
}
template<class TCoord, class TDeriv, class TReal>
void MechanicalObjectInternalData< gpu::cuda::CudaVectorTypes<TCoord,TDeriv,TReal> >::vMultiOp(Main* m, const VMultiOp& ops)
{
// optimize common integration case: v += a*dt, x += v*dt
if (ops.size() == 2 && ops[0].second.size() == 2 && ops[0].first == ops[0].second[0].first && ops[0].first.type == VecId::V_DERIV && ops[0].second[1].first.type == VecId::V_DERIV
&& ops[1].second.size() == 2 && ops[1].first == ops[1].second[0].first && ops[0].first == ops[1].second[1].first && ops[1].first.type == VecId::V_COORD)
{
VecDeriv* va = m->getVecDeriv(ops[0].second[1].first.index);
VecDeriv* vv = m->getVecDeriv(ops[0].first.index);
VecCoord* vx = m->getVecCoord(ops[1].first.index);
const unsigned int n = vx->size();
const double f_v_v = ops[0].second[0].second;
const double f_v_a = ops[0].second[1].second;
const double f_x_x = ops[1].second[0].second;
const double f_x_v = ops[1].second[1].second;
Kernels::vIntegrate(n, va->deviceRead(), vv->deviceWrite(), vx->deviceWrite(), (Real)f_v_v, (Real)f_v_a, (Real)f_x_x, (Real)f_x_v);
}
// optimize common CG step: x += a*p, q -= a*v
else if (ops.size() == 2 && ops[0].second.size() == 2 && ops[0].first == ops[0].second[0].first && ops[0].second[0].second == 1.0 && ops[0].first.type == VecId::V_DERIV && ops[0].second[1].first.type == VecId::V_DERIV
&& ops[1].second.size() == 2 && ops[1].first == ops[1].second[0].first && ops[1].second[0].second == 1.0 && ops[1].first.type == VecId::V_DERIV && ops[1].second[1].first.type == VecId::V_DERIV)
{
VecDeriv* vv1 = m->getVecDeriv(ops[0].second[1].first.index);
VecDeriv* vres1 = m->getVecDeriv(ops[0].first.index);
VecDeriv* vv2 = m->getVecDeriv(ops[1].second[1].first.index);
VecDeriv* vres2 = m->getVecDeriv(ops[1].first.index);
const unsigned int n = vres1->size();
const double f1 = ops[0].second[1].second;
const double f2 = ops[1].second[1].second;
Kernels::vPEqBF2(n, vres1->deviceWrite(), vv1->deviceRead(), f1, vres2->deviceWrite(), vv2->deviceRead(), f2);
}
// optimize a pair of generic vOps
else if (ops.size()==2 && ops[0].second.size()==2 && ops[0].second[0].second == 1.0 && ops[1].second.size()==2 && ops[1].second[0].second == 1.0)
{
const unsigned int n = m->getSize();
Kernels::vOp2(n,
(ops[0].first.type == VecId::V_COORD) ? m->getVecCoord(ops[0].first.index)->deviceWrite() : m->getVecDeriv(ops[0].first.index)->deviceWrite(),
(ops[0].second[0].first.type == VecId::V_COORD) ? m->getVecCoord(ops[0].second[0].first.index)->deviceRead() : m->getVecDeriv(ops[0].second[0].first.index)->deviceRead(),
(ops[0].second[1].first.type == VecId::V_COORD) ? m->getVecCoord(ops[0].second[1].first.index)->deviceRead() : m->getVecDeriv(ops[0].second[1].first.index)->deviceRead(),
ops[0].second[1].second,
(ops[1].first.type == VecId::V_COORD) ? m->getVecCoord(ops[1].first.index)->deviceWrite() : m->getVecDeriv(ops[1].first.index)->deviceWrite(),
(ops[1].second[0].first.type == VecId::V_COORD) ? m->getVecCoord(ops[1].second[0].first.index)->deviceRead() : m->getVecDeriv(ops[1].second[0].first.index)->deviceRead(),
(ops[1].second[1].first.type == VecId::V_COORD) ? m->getVecCoord(ops[1].second[1].first.index)->deviceRead() : m->getVecDeriv(ops[1].second[1].first.index)->deviceRead(),
ops[1].second[1].second);
}
// optimize a pair of 4-way accumulations (such as at the end of RK4)
else if (ops.size()==2 && ops[0].second.size()==5 && ops[0].second[0].first == ops[0].first && ops[0].second[0].second == 1.0 &&
ops[1].second.size()==5 && ops[1].second[0].first == ops[1].first && ops[1].second[0].second == 1.0)
{
const unsigned int n = m->getSize();
Kernels::vPEq4BF2(n,
(ops[0].first.type == VecId::V_COORD) ? m->getVecCoord(ops[0].first.index)->deviceWrite() : m->getVecDeriv(ops[0].first.index)->deviceWrite(),
(ops[0].second[1].first.type == VecId::V_COORD) ? m->getVecCoord(ops[0].second[1].first.index)->deviceRead() : m->getVecDeriv(ops[0].second[1].first.index)->deviceRead(),
ops[0].second[1].second,
(ops[0].second[2].first.type == VecId::V_COORD) ? m->getVecCoord(ops[0].second[2].first.index)->deviceRead() : m->getVecDeriv(ops[0].second[2].first.index)->deviceRead(),
ops[0].second[2].second,
(ops[0].second[3].first.type == VecId::V_COORD) ? m->getVecCoord(ops[0].second[3].first.index)->deviceRead() : m->getVecDeriv(ops[0].second[3].first.index)->deviceRead(),
ops[0].second[3].second,
(ops[0].second[4].first.type == VecId::V_COORD) ? m->getVecCoord(ops[0].second[4].first.index)->deviceRead() : m->getVecDeriv(ops[0].second[4].first.index)->deviceRead(),
ops[0].second[4].second,
(ops[1].first.type == VecId::V_COORD) ? m->getVecCoord(ops[1].first.index)->deviceWrite() : m->getVecDeriv(ops[1].first.index)->deviceWrite(),
(ops[1].second[1].first.type == VecId::V_COORD) ? m->getVecCoord(ops[1].second[1].first.index)->deviceRead() : m->getVecDeriv(ops[1].second[1].first.index)->deviceRead(),
ops[1].second[1].second,
(ops[1].second[2].first.type == VecId::V_COORD) ? m->getVecCoord(ops[1].second[2].first.index)->deviceRead() : m->getVecDeriv(ops[1].second[2].first.index)->deviceRead(),
ops[1].second[2].second,
(ops[1].second[3].first.type == VecId::V_COORD) ? m->getVecCoord(ops[1].second[3].first.index)->deviceRead() : m->getVecDeriv(ops[1].second[3].first.index)->deviceRead(),
ops[1].second[3].second,
(ops[1].second[4].first.type == VecId::V_COORD) ? m->getVecCoord(ops[1].second[4].first.index)->deviceRead() : m->getVecDeriv(ops[1].second[4].first.index)->deviceRead(),
ops[1].second[4].second);
}
else // no optimization for now for other cases
{
std::cout << "CUDA: unoptimized vMultiOp:"<<std::endl;
for (unsigned int i=0;i<ops.size();++i)
{
std::cout << ops[i].first << " =";
if (ops[i].second.empty())
std::cout << "0";
else
for (unsigned int j=0;j<ops[i].second.size();++j)
{
if (j) std::cout << " + ";
std::cout << ops[i].second[j].first << "*" << ops[i].second[j].second;
}
std::cout << endl;
}
{
using namespace sofa::core::componentmodel::behavior;
m->BaseMechanicalState::vMultiOp(ops);
}
}
}
template<class TCoord, class TDeriv, class TReal>
double MechanicalObjectInternalData< gpu::cuda::CudaVectorTypes<TCoord,TDeriv,TReal> >::vDot(Main* m, VecId a, VecId b)
{
Real r = 0.0f;
if (a.type == VecId::V_COORD && b.type == VecId::V_COORD)
{
VecCoord* va = m->getVecCoord(a.index);
VecCoord* vb = m->getVecCoord(b.index);
int tmpsize = Kernels::vDotTmpSize(va->size());
if (tmpsize == 0)
{
Kernels::vDot(va->size(), &r, va->deviceRead(), vb->deviceRead(), NULL, NULL);
}
else
{
m->data.tmpdot.fastResize(tmpsize);
Kernels::vDot(va->size(), &r, va->deviceRead(), vb->deviceRead(), m->data.tmpdot.deviceWrite(), (Real*)(&(m->data.tmpdot.getCached(0))));
}
}
else if (a.type == VecId::V_DERIV && b.type == VecId::V_DERIV)
{
VecDeriv* va = m->getVecDeriv(a.index);
VecDeriv* vb = m->getVecDeriv(b.index);
int tmpsize = Kernels::vDotTmpSize(va->size());
if (tmpsize == 0)
{
Kernels::vDot(va->size(), &r, va->deviceRead(), vb->deviceRead(), NULL, NULL);
}
else
{
m->data.tmpdot.fastResize(tmpsize);
Kernels::vDot(va->size(), &r, va->deviceRead(), vb->deviceRead(), m->data.tmpdot.deviceWrite(), (Real*)(&(m->data.tmpdot.getCached(0))));
}
#ifndef NDEBUG
// Check the result
//Real r2 = 0.0f;
//for (unsigned int i=0; i<va->size(); i++)
// r2 += (*va)[i] * (*vb)[i];
//std::cout << "CUDA vDot: GPU="<<r<<" CPU="<<r2<<" relative error="<<(fabsf(r2)>0.000001?fabsf(r-r2)/fabsf(r2):fabsf(r-r2))<<"\n";
#endif
}
else
{
std::cerr << "Invalid dot operation ("<<a<<','<<b<<")\n";
}
return r;
}
template<class TCoord, class TDeriv, class TReal>
void MechanicalObjectInternalData< gpu::cuda::CudaVectorTypes<TCoord,TDeriv,TReal> >::resetForce(Main* m)
{
VecDeriv& f= *m->getF();
Kernels::vClear(f.size(), f.deviceWrite());
}
// I know using macros is bad design but this is the only way not to repeat the code for all CUDA types
#define CudaMechanicalObject_ImplMethods(T) \
template<> void MechanicalObject< T >::accumulateForce() \
{ data.accumulateForce(this); } \
template<> void MechanicalObject< T >::vOp(VecId v, VecId a, VecId b, double f) \
{ data.vOp(this, v, a, b, f); } \
template<> void MechanicalObject< T >::vMultiOp(const VMultiOp& ops) \
{ data.vMultiOp(this, ops); } \
template<> double MechanicalObject< T >::vDot(VecId a, VecId b) \
{ return data.vDot(this, a, b); } \
template<> void MechanicalObject< T >::resetForce() \
{ data.resetForce(this); }
CudaMechanicalObject_ImplMethods(gpu::cuda::CudaVec3fTypes);
CudaMechanicalObject_ImplMethods(gpu::cuda::CudaVec3f1Types);
#ifdef SOFA_GPU_CUDA_DOUBLE
CudaMechanicalObject_ImplMethods(gpu::cuda::CudaVec3dTypes);
CudaMechanicalObject_ImplMethods(gpu::cuda::CudaVec3d1Types);
#endif // SOFA_GPU_CUDA_DOUBLE
#undef CudaMechanicalObject_ImplMethods
} // namespace component
} // namespace sofa
#endif
|