arrayCpuGpu.cpp 23.6 KB
Newer Older
1
#include <openpose/core/arrayCpuGpu.hpp>
2 3 4 5 6 7 8 9 10 11 12
#ifdef USE_CAFFE
    #include <caffe/blob.hpp>
#endif
#include <openpose/utilities/errorAndLog.hpp>

namespace op
{
    template<typename T>
    struct ArrayCpuGpu<T>::ImplArrayCpuGpu
    {
        #ifdef USE_CAFFE
13 14 15 16 17 18 19
            #ifdef NV_CAFFE
                std::unique_ptr<caffe::TBlob<T>> upCaffeBlobT;
                caffe::TBlob<T>* pCaffeBlobT;
            #else
                std::unique_ptr<caffe::Blob<T>> upCaffeBlobT;
                caffe::Blob<T>* pCaffeBlobT;
            #endif
20 21 22 23 24 25 26 27 28 29 30
        #endif
    };

    const std::string constructorErrorMessage = "ArrayCpuGpu class only implemented for Caffe DL framework (enable"
        " `USE_CAFFE` in CMake-GUI).";
    template<typename T>
    ArrayCpuGpu<T>::ArrayCpuGpu()
    {
        try
        {
            #ifdef USE_CAFFE
G
gineshidalgo99 已提交
31
                // Construct spImpl
32
                spImpl.reset(new ImplArrayCpuGpu{});
33 34 35 36 37
                #ifdef NV_CAFFE
                    spImpl->upCaffeBlobT.reset(new caffe::TBlob<T>{});
                #else
                    spImpl->upCaffeBlobT.reset(new caffe::Blob<T>{});
                #endif
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
                spImpl->pCaffeBlobT = spImpl->upCaffeBlobT.get();
            #else
                error(constructorErrorMessage, __LINE__, __FUNCTION__, __FILE__);
            #endif
        }
        catch (const std::exception& e)
        {
            error(e.what(), __LINE__, __FUNCTION__, __FILE__);
        }
    }

    template<typename T>
    ArrayCpuGpu<T>::ArrayCpuGpu(const void* caffeBlobTPtr)
    {
        try
        {
            #ifdef USE_CAFFE
G
gineshidalgo99 已提交
55
                // Construct spImpl
56
                spImpl.reset(new ImplArrayCpuGpu{});
57 58 59 60 61
                #ifdef NV_CAFFE
                    spImpl->pCaffeBlobT = (caffe::TBlob<T>*)caffeBlobTPtr;
                #else
                    spImpl->pCaffeBlobT = (caffe::Blob<T>*)caffeBlobTPtr;
                #endif
62 63 64 65 66 67 68 69 70 71 72
            #else
                UNUSED(caffeBlobTPtr);
                error(constructorErrorMessage, __LINE__, __FUNCTION__, __FILE__);
            #endif
        }
        catch (const std::exception& e)
        {
            error(e.what(), __LINE__, __FUNCTION__, __FILE__);
        }
    }

G
gineshidalgo99 已提交
73 74 75 76 77 78
    template<typename T>
    ArrayCpuGpu<T>::ArrayCpuGpu(const Array<T>& array, const bool copyFromGpu)
    {
        try
        {
            #ifdef USE_CAFFE
79 80 81 82 83 84 85 86 87
                // Get updated size
                std::vector<int> arraySize;
                // If batch size = 1 --> E.g., array.getSize() == {78, 368, 368}
                if (array.getNumberDimensions() == 3)
                    // Add 1: arraySize = {1}
                    arraySize.emplace_back(1);
                // Add {78, 368, 368}: arraySize = {1, 78, 368, 368}
                for (const auto& sizeI : array.getSize())
                    arraySize.emplace_back(sizeI);
G
gineshidalgo99 已提交
88 89
                // Construct spImpl
                spImpl.reset(new ImplArrayCpuGpu{});
90 91 92 93 94
                #ifdef NV_CAFFE
                    spImpl->upCaffeBlobT.reset(new caffe::TBlob<T>{arraySize});
                #else
                    spImpl->upCaffeBlobT.reset(new caffe::Blob<T>{arraySize});
                #endif
G
gineshidalgo99 已提交
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118
                spImpl->pCaffeBlobT = spImpl->upCaffeBlobT.get();
                // Copy data
                // CPU copy
                if (!copyFromGpu)
                {
                    const auto* const arrayPtr = array.getConstPtr();
                    std::copy(arrayPtr, arrayPtr + array.getVolume(), spImpl->pCaffeBlobT->mutable_cpu_data());
                }
                // GPU copy
                else
                    error("Not implemented yet. Let us know you are interested on this function.",
                          __LINE__, __FUNCTION__, __FILE__);
            #else
                UNUSED(array);
                UNUSED(copyFromGpu);
                error(constructorErrorMessage, __LINE__, __FUNCTION__, __FILE__);
            #endif
        }
        catch (const std::exception& e)
        {
            error(e.what(), __LINE__, __FUNCTION__, __FILE__);
        }
    }

119 120 121 122 123 124
    template<typename T>
    ArrayCpuGpu<T>::ArrayCpuGpu(const int num, const int channels, const int height, const int width)
    {
        try
        {
            #ifdef USE_CAFFE
G
gineshidalgo99 已提交
125
                // Construct spImpl
126
                spImpl.reset(new ImplArrayCpuGpu{});
127 128 129 130 131
                #ifdef NV_CAFFE
                    spImpl->upCaffeBlobT.reset(new caffe::TBlob<T>{num, channels, height, width});
                #else
                    spImpl->upCaffeBlobT.reset(new caffe::Blob<T>{num, channels, height, width});
                #endif
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
                spImpl->pCaffeBlobT = spImpl->upCaffeBlobT.get();
            #else
                UNUSED(num);
                UNUSED(channels);
                UNUSED(height);
                UNUSED(width);
                error(constructorErrorMessage, __LINE__, __FUNCTION__, __FILE__);
            #endif
        }
        catch (const std::exception& e)
        {
            error(e.what(), __LINE__, __FUNCTION__, __FILE__);
        }
    }

    // template<typename T>
    // ArrayCpuGpu<T>::ArrayCpuGpu(const std::vector<int>& shape)
    // {
    //     try
    //     {
    //         #ifdef USE_CAFFE
    //             spImpl.reset(new ImplArrayCpuGpu{});
    //             spImpl->upCaffeBlobT.reset(new caffe::Blob<T>{shape});
    //             spImpl->pCaffeBlobT = spImpl->upCaffeBlobT.get();
    //         #else
    //             error(constructorErrorMessage, __LINE__, __FUNCTION__, __FILE__);
    //         #endif
    //     }
    //     catch (const std::exception& e)
    //     {
    //         error(e.what(), __LINE__, __FUNCTION__, __FILE__);
    //     }
    // }

    template<typename T>
    void ArrayCpuGpu<T>::Reshape(const int num, const int channels, const int height, const int width)
    {
        try
        {
            #ifdef USE_CAFFE
                spImpl->pCaffeBlobT->Reshape(num, channels, height, width);
            #else
                UNUSED(num);
                UNUSED(channels);
                UNUSED(height);
                UNUSED(width);
            #endif
        }
        catch (const std::exception& e)
        {
            error(e.what(), __LINE__, __FUNCTION__, __FILE__);
        }
    }

    template<typename T>
    void ArrayCpuGpu<T>::Reshape(const std::vector<int>& shape)
    {
        try
        {
            #ifdef USE_CAFFE
                spImpl->pCaffeBlobT->Reshape(shape);
            #else
                UNUSED(shape);
            #endif
        }
        catch (const std::exception& e)
        {
            error(e.what(), __LINE__, __FUNCTION__, __FILE__);
        }
    }

    template<typename T>
    std::string ArrayCpuGpu<T>::shape_string() const
    {
        try
        {
            #ifdef USE_CAFFE
                return spImpl->pCaffeBlobT->shape_string();
            #else
                return "";
            #endif
        }
        catch (const std::exception& e)
        {
            error(e.what(), __LINE__, __FUNCTION__, __FILE__);
            return "";
        }
    }

    std::vector<int> DUMB_VECTOR;
    template<typename T>
    const std::vector<int>& ArrayCpuGpu<T>::shape() const
    {
        try
        {
            #ifdef USE_CAFFE
                return spImpl->pCaffeBlobT->shape();
            #else
                return DUMB_VECTOR;
            #endif
        }
        catch (const std::exception& e)
        {
            error(e.what(), __LINE__, __FUNCTION__, __FILE__);
            return DUMB_VECTOR;
        }
    }

    template<typename T>
    int ArrayCpuGpu<T>::shape(const int index) const
    {
        try
        {
            #ifdef USE_CAFFE
                return spImpl->pCaffeBlobT->shape(index);
            #else
                UNUSED(index);
                return -1;
            #endif
        }
        catch (const std::exception& e)
        {
            error(e.what(), __LINE__, __FUNCTION__, __FILE__);
            return -1;
        }
    }

    template<typename T>
    int ArrayCpuGpu<T>::num_axes() const
    {
        try
        {
            #ifdef USE_CAFFE
                return spImpl->pCaffeBlobT->num_axes();
            #else
                return -1;
            #endif
        }
        catch (const std::exception& e)
        {
            error(e.what(), __LINE__, __FUNCTION__, __FILE__);
            return -1;
        }
    }

    template<typename T>
    int ArrayCpuGpu<T>::count() const
    {
        try
        {
            #ifdef USE_CAFFE
                return spImpl->pCaffeBlobT->count();
            #else
                return -1;
            #endif
        }
        catch (const std::exception& e)
        {
            error(e.what(), __LINE__, __FUNCTION__, __FILE__);
            return -1;
        }
    }

    template<typename T>
    int ArrayCpuGpu<T>::count(const int start_axis, const int end_axis) const
    {
        try
        {
            #ifdef USE_CAFFE
                return spImpl->pCaffeBlobT->count(start_axis, end_axis);
            #else
                UNUSED(start_axis);
                UNUSED(end_axis);
                return -1;
            #endif
        }
        catch (const std::exception& e)
        {
            error(e.what(), __LINE__, __FUNCTION__, __FILE__);
            return -1;
        }
    }

    template<typename T>
    int ArrayCpuGpu<T>::count(const int start_axis) const
    {
        try
        {
            #ifdef USE_CAFFE
                return spImpl->pCaffeBlobT->count(start_axis);
            #else
                UNUSED(start_axis);
                return -1;
            #endif
        }
        catch (const std::exception& e)
        {
            error(e.what(), __LINE__, __FUNCTION__, __FILE__);
            return -1;
        }
    }

    template<typename T>
    int ArrayCpuGpu<T>::CanonicalAxisIndex(const int axis_index) const
    {
        try
        {
            #ifdef USE_CAFFE
                return spImpl->pCaffeBlobT->CanonicalAxisIndex(axis_index);
            #else
                UNUSED(axis_index);
                return -1;
            #endif
        }
        catch (const std::exception& e)
        {
            error(e.what(), __LINE__, __FUNCTION__, __FILE__);
            return -1;
        }
    }

G
gineshidalgo99 已提交
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
    template<typename T>
    int ArrayCpuGpu<T>::num() const
    {
        try
        {
            #ifdef USE_CAFFE
                return spImpl->pCaffeBlobT->num();
            #else
                return -1;
            #endif
        }
        catch (const std::exception& e)
        {
            error(e.what(), __LINE__, __FUNCTION__, __FILE__);
            return -1;
        }
    }

    template<typename T>
    int ArrayCpuGpu<T>::channels() const
    {
        try
        {
            #ifdef USE_CAFFE
                return spImpl->pCaffeBlobT->channels();
            #else
                return -1;
            #endif
        }
        catch (const std::exception& e)
        {
            error(e.what(), __LINE__, __FUNCTION__, __FILE__);
            return -1;
        }
    }

    template<typename T>
    int ArrayCpuGpu<T>::height() const
    {
        try
        {
            #ifdef USE_CAFFE
                return spImpl->pCaffeBlobT->height();
            #else
                return -1;
            #endif
        }
        catch (const std::exception& e)
        {
            error(e.what(), __LINE__, __FUNCTION__, __FILE__);
            return -1;
        }
    }

    template<typename T>
    int ArrayCpuGpu<T>::width() const
    {
        try
        {
            #ifdef USE_CAFFE
                return spImpl->pCaffeBlobT->width();
            #else
                return -1;
            #endif
        }
        catch (const std::exception& e)
        {
            error(e.what(), __LINE__, __FUNCTION__, __FILE__);
            return -1;
        }
    }

    template<typename T>
    int ArrayCpuGpu<T>::LegacyShape(const int index) const
    {
        try
        {
            #ifdef USE_CAFFE
                return spImpl->pCaffeBlobT->LegacyShape(index);
            #else
                UNUSED(index);
                return -1;
            #endif
        }
        catch (const std::exception& e)
        {
            error(e.what(), __LINE__, __FUNCTION__, __FILE__);
            return -1;
        }
    }

    template<typename T>
    int ArrayCpuGpu<T>::offset(const int n, const int c, const int h, const int w) const
    {
        try
        {
            #ifdef USE_CAFFE
                return spImpl->pCaffeBlobT->offset(n, c, h, w);
            #else
                UNUSED(n);
                UNUSED(c);
                UNUSED(h);
                UNUSED(w);
                return -1;
            #endif
        }
        catch (const std::exception& e)
        {
            error(e.what(), __LINE__, __FUNCTION__, __FILE__);
            return -1;
        }
    }

    // template<typename T>
    // int ArrayCpuGpu<T>::offset(const std::vector<int>& indices) const
    // {
    //     try
    //     {
    //         #ifdef USE_CAFFE
    //             return spImpl->pCaffeBlobT->offset(indices);
    //         #else
    //             UNUSED(indices);
    //             return -1;
    //         #endif
    //     }
    //     catch (const std::exception& e)
    //     {
    //         error(e.what(), __LINE__, __FUNCTION__, __FILE__);
    //         return -1;
    //     }
    // }

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
    template<typename T>
    T ArrayCpuGpu<T>::data_at(const int n, const int c, const int h, const int w) const
    {
        try
        {
            #ifdef USE_CAFFE
                return spImpl->pCaffeBlobT->data_at(n, c, h, w);
            #else
                UNUSED(n);
                UNUSED(c);
                UNUSED(h);
                UNUSED(w);
                return T{0};
            #endif
        }
        catch (const std::exception& e)
        {
            error(e.what(), __LINE__, __FUNCTION__, __FILE__);
            return T{0};
        }
    }

    template<typename T>
    T ArrayCpuGpu<T>::diff_at(const int n, const int c, const int h, const int w) const
    {
        try
        {
            #ifdef USE_CAFFE
                return spImpl->pCaffeBlobT->diff_at(n, c, h, w);
            #else
                UNUSED(n);
                UNUSED(c);
                UNUSED(h);
                UNUSED(w);
                return T{0};
            #endif
        }
        catch (const std::exception& e)
        {
            error(e.what(), __LINE__, __FUNCTION__, __FILE__);
            return T{0};
        }
    }

    // template<typename T>
    // T ArrayCpuGpu<T>::data_at(const std::vector<int>& index) const
    // {
    //     try
    //     {
    //         #ifdef USE_CAFFE
    //             return spImpl->pCaffeBlobT->data_at(index);
    //         #else
    //             UNUSED(index);
    //             return T{0};
    //         #endif
    //     }
    //     catch (const std::exception& e)
    //     {
    //         error(e.what(), __LINE__, __FUNCTION__, __FILE__);
    //         return T{0};
    //     }
    // }

    // template<typename T>
    // T ArrayCpuGpu<T>::diff_at(const std::vector<int>& index) const
    // {
    //     try
    //     {
    //         #ifdef USE_CAFFE
    //             return spImpl->pCaffeBlobT->diff_at(index);
    //         #else
    //             UNUSED(index);
    //             return T{0};
    //         #endif
    //     }
    //     catch (const std::exception& e)
    //     {
    //         error(e.what(), __LINE__, __FUNCTION__, __FILE__);
    //         return T{0};
    //     }
    // }

    template<typename T>
    const T* ArrayCpuGpu<T>::cpu_data() const
    {
        try
        {
            #ifdef USE_CAFFE
                return spImpl->pCaffeBlobT->cpu_data();
            #else
                return nullptr;
            #endif
        }
        catch (const std::exception& e)
        {
            error(e.what(), __LINE__, __FUNCTION__, __FILE__);
            return nullptr;
        }
    }

    template<typename T>
    void ArrayCpuGpu<T>::set_cpu_data(T* data)
    {
        try
        {
            #ifdef USE_CAFFE
                spImpl->pCaffeBlobT->set_cpu_data(data);
            #else
                UNUSED(data);
            #endif
        }
        catch (const std::exception& e)
        {
            error(e.what(), __LINE__, __FUNCTION__, __FILE__);
        }
    }

602 603 604 605 606
    template<typename T>
    const int* ArrayCpuGpu<T>::gpu_shape() const
    {
        try
        {
R
Raaj 已提交
607
            #if defined(USE_CAFFE) && (defined(USE_CUDA) || defined(USE_OPENCL))
608 609 610 611 612 613 614 615 616 617 618 619
                return spImpl->pCaffeBlobT->gpu_shape();
            #else
                error("Required `USE_CAFFE` and `USE_CUDA` flags enabled.", __LINE__, __FUNCTION__, __FILE__);
                return nullptr;
            #endif
        }
        catch (const std::exception& e)
        {
            error(e.what(), __LINE__, __FUNCTION__, __FILE__);
            return nullptr;
        }
    }
620 621 622 623 624 625

    template<typename T>
    const T* ArrayCpuGpu<T>::gpu_data() const
    {
        try
        {
R
Raaj 已提交
626
            #if defined(USE_CAFFE) && (defined(USE_CUDA) || defined(USE_OPENCL))
627 628
                return spImpl->pCaffeBlobT->gpu_data();
            #else
629
                error("Required `USE_CAFFE` and `USE_CUDA` flags enabled.", __LINE__, __FUNCTION__, __FILE__);
630 631 632 633 634 635 636 637 638 639 640 641 642 643 644
                return nullptr;
            #endif
        }
        catch (const std::exception& e)
        {
            error(e.what(), __LINE__, __FUNCTION__, __FILE__);
            return nullptr;
        }
    }

    template<typename T>
    void ArrayCpuGpu<T>::set_gpu_data(T* data)
    {
        try
        {
R
Raaj 已提交
645
            #if defined(USE_CAFFE) && (defined(USE_CUDA) || defined(USE_OPENCL))
646 647 648
                spImpl->pCaffeBlobT->set_gpu_data(data);
            #else
                UNUSED(data);
649
                error("Required `USE_CAFFE` and `USE_CUDA` flags enabled.", __LINE__, __FUNCTION__, __FILE__);
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
            #endif
        }
        catch (const std::exception& e)
        {
            error(e.what(), __LINE__, __FUNCTION__, __FILE__);
        }
    }

    template<typename T>
    const T* ArrayCpuGpu<T>::cpu_diff() const
    {
        try
        {
            #ifdef USE_CAFFE
                return spImpl->pCaffeBlobT->cpu_diff();
            #else
                return nullptr;
            #endif
        }
        catch (const std::exception& e)
        {
            error(e.what(), __LINE__, __FUNCTION__, __FILE__);
            return nullptr;
        }
    }

    template<typename T>
    const T* ArrayCpuGpu<T>::gpu_diff() const
    {
        try
        {
R
Raaj 已提交
681
            #if defined(USE_CAFFE) && (defined(USE_CUDA) || defined(USE_OPENCL))
682 683
                return spImpl->pCaffeBlobT->gpu_diff();
            #else
684
                error("Required `USE_CAFFE` and `USE_CUDA` flags enabled.", __LINE__, __FUNCTION__, __FILE__);
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
                return nullptr;
            #endif
        }
        catch (const std::exception& e)
        {
            error(e.what(), __LINE__, __FUNCTION__, __FILE__);
            return nullptr;
        }
    }

    template<typename T>
    T* ArrayCpuGpu<T>::mutable_cpu_data()
    {
        try
        {
            #ifdef USE_CAFFE
                return spImpl->pCaffeBlobT->mutable_cpu_data();
            #else
                return nullptr;
            #endif
        }
        catch (const std::exception& e)
        {
            error(e.what(), __LINE__, __FUNCTION__, __FILE__);
            return nullptr;
        }
    }

    template<typename T>
    T* ArrayCpuGpu<T>::mutable_gpu_data()
    {
        try
        {
R
Raaj 已提交
718
            #if defined(USE_CAFFE) && (defined(USE_CUDA) || defined(USE_OPENCL))
719 720
                return spImpl->pCaffeBlobT->mutable_gpu_data();
            #else
721
                error("Required `USE_CAFFE` and `USE_CUDA` flags enabled.", __LINE__, __FUNCTION__, __FILE__);
722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754
                return nullptr;
            #endif
        }
        catch (const std::exception& e)
        {
            error(e.what(), __LINE__, __FUNCTION__, __FILE__);
            return nullptr;
        }
    }

    template<typename T>
    T* ArrayCpuGpu<T>::mutable_cpu_diff()
    {
        try
        {
            #ifdef USE_CAFFE
                return spImpl->pCaffeBlobT->mutable_cpu_diff();
            #else
                return nullptr;
            #endif
        }
        catch (const std::exception& e)
        {
            error(e.what(), __LINE__, __FUNCTION__, __FILE__);
            return nullptr;
        }
    }

    template<typename T>
    T* ArrayCpuGpu<T>::mutable_gpu_diff()
    {
        try
        {
R
Raaj 已提交
755
            #if defined(USE_CAFFE) && (defined(USE_CUDA) || defined(USE_OPENCL))
756 757
                return spImpl->pCaffeBlobT->mutable_gpu_diff();
            #else
758
                error("Required `USE_CAFFE` and `USE_CUDA` flags enabled.", __LINE__, __FUNCTION__, __FILE__);
759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783
                return nullptr;
            #endif
        }
        catch (const std::exception& e)
        {
            error(e.what(), __LINE__, __FUNCTION__, __FILE__);
            return nullptr;
        }
    }

    template<typename T>
    void ArrayCpuGpu<T>::Update()
    {
        try
        {
            #ifdef USE_CAFFE
                spImpl->pCaffeBlobT->Update();
            #endif
        }
        catch (const std::exception& e)
        {
            error(e.what(), __LINE__, __FUNCTION__, __FILE__);
        }
    }

G
gineshidalgo99 已提交
784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807
    template<typename T>
    T ArrayCpuGpu<T>::asum_data() const
    {
        try
        {
            #ifdef USE_CAFFE
                return spImpl->pCaffeBlobT->asum_data();
            #else
                return T{0};
            #endif
        }
        catch (const std::exception& e)
        {
            error(e.what(), __LINE__, __FUNCTION__, __FILE__);
            return T{0};
        }
    }

    template<typename T>
    T ArrayCpuGpu<T>::asum_diff() const
    {
        try
        {
            #ifdef USE_CAFFE
808
                return spImpl->pCaffeBlobT->asum_diff();
G
gineshidalgo99 已提交
809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825
            #else
                return T{0};
            #endif
        }
        catch (const std::exception& e)
        {
            error(e.what(), __LINE__, __FUNCTION__, __FILE__);
            return T{0};
        }
    }

    template<typename T>
    T ArrayCpuGpu<T>::sumsq_data() const
    {
        try
        {
            #ifdef USE_CAFFE
826
                return spImpl->pCaffeBlobT->sumsq_data();
G
gineshidalgo99 已提交
827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843
            #else
                return T{0};
            #endif
        }
        catch (const std::exception& e)
        {
            error(e.what(), __LINE__, __FUNCTION__, __FILE__);
            return T{0};
        }
    }

    template<typename T>
    T ArrayCpuGpu<T>::sumsq_diff() const
    {
        try
        {
            #ifdef USE_CAFFE
844
                return spImpl->pCaffeBlobT->sumsq_diff();
G
gineshidalgo99 已提交
845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889
            #else
                return T{0};
            #endif
        }
        catch (const std::exception& e)
        {
            error(e.what(), __LINE__, __FUNCTION__, __FILE__);
            return T{0};
        }
    }

    template<typename T>
    void ArrayCpuGpu<T>::scale_data(const T scale_factor)
    {
        try
        {
            #ifdef USE_CAFFE
                spImpl->pCaffeBlobT->scale_data(scale_factor);
            #else
                UNUSED(scale_factor);
            #endif
        }
        catch (const std::exception& e)
        {
            error(e.what(), __LINE__, __FUNCTION__, __FILE__);
        }
    }

    template<typename T>
    void ArrayCpuGpu<T>::scale_diff(const T scale_factor)
    {
        try
        {
            #ifdef USE_CAFFE
                spImpl->pCaffeBlobT->scale_diff(scale_factor);
            #else
                UNUSED(scale_factor);
            #endif
        }
        catch (const std::exception& e)
        {
            error(e.what(), __LINE__, __FUNCTION__, __FILE__);
        }
    }

890 891
    COMPILE_TEMPLATE_FLOATING_INT_TYPES_CLASS(ArrayCpuGpu);
}