Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-09 07:49:09

0001 #pragma once
0002 /**
0003 
0004 Polymorphism on device would be handy for 
0005 treating different genstep types with common 
0006 references.
0007 
0008 Apparently that is possible so long as the objects are created on device.
0009 
0010 https://stackoverflow.com/questions/22988244/polymorphism-and-derived-classes-in-cuda-cuda-thrust/23476510#23476510
0011  
0012 Or perhaps there is a workaround "CUDA polymorphism workaround"
0013 
0014 https://forums.developer.nvidia.com/t/is-there-a-function-polymorphism-trick-in-device-code/22407
0015 
0016 * uses one class, and branches on type   
0017 
0018 **/
0019 
0020 #if defined(__CUDACC__) || defined(__CUDABE__)
0021    #define QPOLY_METHOD __host__ __device__ 
0022 #else
0023    #define QPOLY_METHOD 
0024 #endif 
0025 
0026 
0027 struct Poly
0028 {
0029    float width ; 
0030    float height;
0031 
0032    QPOLY_METHOD void set_param(float width_, float height_ )
0033    { 
0034        width=width_; 
0035        height=height_; 
0036    }
0037    QPOLY_METHOD virtual float area(){ return 0.f; }
0038 };
0039 
0040 
0041 struct RectangleV1 : Poly
0042 {
0043     QPOLY_METHOD float area(){ return width * height + 0.1f ; }
0044 };
0045 
0046 struct RectangleV2 : Poly
0047 {
0048     QPOLY_METHOD float area(){ return width * height + 0.2f ;  }
0049 };
0050 
0051 struct TriangleV1 : Poly 
0052 {
0053     QPOLY_METHOD float area(){ return width*height/2.f + 0.1f ; }
0054 };
0055 
0056 struct TriangleV2 : Poly 
0057 {
0058     QPOLY_METHOD float area(){ return width*height/2.f + 0.2f ; }
0059 };
0060 
0061 
0062 
0063 
0064 
0065 
0066 
0067