none
AMP bug? static cast failed with a runtime error in a parallel_for RRS feed

  • Question

  • #include <amp.h>
    #include <iostream>
    
    using namespace concurrency;
    
    int main() {
      int a[] = {1, 2, 3, 4};
      int n = sizeof(a)/sizeof(a[0]);
      array_view<int, 1> A(n, a);
    
      parallel_for_each(
        A.grid,
        [=](index<1> idx) restrict(direct3d) {
          int x = idx.get_x();
    #if 0
          A[x] = static_cast<int>(2.0f * x); // OK
    #else 
          A[x] = static_cast<int>(2.0 * x);  // !OK
    #endif
        });
      A.synchronize();
    
      std::for_each(a, a + n, [](int x) { std::cout << x << " "; });
      std::cout << std::endl;
    
      return 0;
    }

    The above simple code compiles but failed at runtime, (Win7 64, VC11 preview, NVIDIA GTS450).

    It turns out float-to-int ok but double-to-int not. BUG?

    Thanks

    Wei Pan

     

     

    Thursday, December 22, 2011 9:21 PM

Answers

  • Yes, you are using it correctly (and the way we offer this will change in the Beta, as part of the "shape" changes I mentioned).

    I hinted at this with "extended" double support: Some parts of double precision support are under what we call "extended support" in DirectX, which is what your scenario falls under. In the Developer Preview, we do not report the extended double support for the accelerator, and this is what will come by the time we ship. At that point, you would also need an update on the driver form the hardware vendor and you can ask them when they'll have extended double support in their DirectX driver.

    Apologies for the confusion, there are non-obvious moving parts in this area and we are preparing a blog post to shed some light on double precision with DX GPUs in general.

    Cheers

    Daniel


    http://www.danielmoth.com/Blog/
    • Marked as answer by wwwwpan Friday, December 23, 2011 2:00 AM
    Thursday, December 22, 2011 11:53 PM

All replies

  • Hi Wei Pan

    That level of double-precision requires not only hardware that supports double precision, but also a DirectX driver from the vendor that supports that level of extended double precision. It sounds like you do not have an extended double precision supporting driver from the hardware vendor. Please contact the vendor to check if the card you are using has (or will have in the future) a driver that supports extended double precision.

    FYI, the C++ AMP API offers a way to query the accelerator for double precision capability, but we are making some (robustness and shape) changes in that area for the Beta, so for now I suggest you stick with floats for your C++ AMP evaluation.

    Cheers

    Daniel


    http://www.danielmoth.com/Blog/
    Thursday, December 22, 2011 10:23 PM
  • Thanks Daniel for your answer!
    The output of the following query  
     
    accelerator acc = accelerator();
    std::wcout << acc.get_description() << std::endl;
    std::cout << acc.supports(accelerator_restriction::double_precision) << std::endl;

    is
    NVIDIA  GeForce GTS 450
    1
    GTS 450 does support double floats in CUDA.
    Not sure how to read the output of API function supports() now.
     
     
     
    Thursday, December 22, 2011 10:57 PM
  • Yes, you are using it correctly (and the way we offer this will change in the Beta, as part of the "shape" changes I mentioned).

    I hinted at this with "extended" double support: Some parts of double precision support are under what we call "extended support" in DirectX, which is what your scenario falls under. In the Developer Preview, we do not report the extended double support for the accelerator, and this is what will come by the time we ship. At that point, you would also need an update on the driver form the hardware vendor and you can ask them when they'll have extended double support in their DirectX driver.

    Apologies for the confusion, there are non-obvious moving parts in this area and we are preparing a blog post to shed some light on double precision with DX GPUs in general.

    Cheers

    Daniel


    http://www.danielmoth.com/Blog/
    • Marked as answer by wwwwpan Friday, December 23, 2011 2:00 AM
    Thursday, December 22, 2011 11:53 PM