File indexing completed on 2026-04-09 07:49:16
0001
0002
0003
0004
0005
0006
0007
0008 #include "ssys.h"
0009 #include "scuda.h"
0010
0011 struct scuda_test
0012 {
0013 static const char* TEST ;
0014 static int cross();
0015 static int indexed();
0016 static int efloat();
0017 static int serial();
0018 static int uint4_increment();
0019 static int uint4_skipahead();
0020
0021 static int main();
0022 };
0023
0024 const char* scuda_test::TEST = ssys::getenvvar("TEST","ALL");
0025
0026
0027
0028 int scuda_test::cross()
0029 {
0030 float3 mom = make_float3( -0.2166f,-0.9745f, 0.0578f );
0031 float3 oriented_normal = make_float3( 0.2166f,0.9745f, -0.0578f );
0032 float3 trans = ::cross( mom, oriented_normal );
0033 printf("// trans (%10.7f, %10.7f, %10.7f) \n", trans.x, trans.y, trans.z );
0034
0035 float trans_mag2 = dot(trans, trans) ;
0036 bool trans_mag2_is_zero = trans_mag2 == 0.f ;
0037 printf("// trans_mag2 %10.9f trans_mag2_is_zero %d \n", trans_mag2, trans_mag2_is_zero );
0038
0039 float3 A_trans = normalize(trans) ;
0040 printf("// A_trans (%10.7f, %10.7f, %10.7f) \n", A_trans.x, A_trans.y, A_trans.z );
0041 return 0 ;
0042 }
0043
0044
0045 int scuda_test::indexed()
0046 {
0047 float4 v = make_float4( 0.f , 1.f, 2.f, 3.f );
0048 const float* vv = (const float*)&v ;
0049 printf("//test_indexed vv[0] %10.4f vv[1] %10.4f vv[2] %10.4f vv[3] %10.4f \n",vv[0], vv[1], vv[2], vv[3] );
0050 return 0 ;
0051 }
0052
0053
0054 int scuda_test::efloat()
0055 {
0056 float f = scuda::efloat("f",101.102f);
0057 printf("//test_efloat f (%10.4f) \n", f );
0058
0059 float3 v3 = scuda::efloat3("v3","3,33,333");
0060 printf("//test_efloat3 v3 (%10.4f %10.4f %10.4f) \n", v3.x, v3.y, v3.z );
0061
0062 float4 v4 = scuda::efloat4("v4","4,44,444,4444");
0063 printf("//test_efloat4 v4 (%10.4f %10.4f %10.4f %10.4f) \n", v4.x, v4.y, v4.z, v4.w );
0064
0065 float3 v3n = scuda::efloat3n("v3n","1,1,1");
0066 printf("//test_efloat3n v3n (%10.4f %10.4f %10.4f) \n", v3n.x, v3n.y, v3n.z );
0067 return 0 ;
0068 }
0069
0070
0071 int scuda_test::serial()
0072 {
0073 float4 v = make_float4( 0.001f , 1.004f, 2.00008f, 3.0006f );
0074 std::cout << " v " << v << std::endl ;
0075
0076 std::cout << " scuda::serialize(v) " << scuda::serialize(v) << std::endl ;
0077 return 0 ;
0078 }
0079
0080
0081
0082
0083
0084 void increment(uint4& ctr )
0085 {
0086 if(++ctr.x==0)
0087 if(++ctr.y==0)
0088 if(++ctr.z==0)
0089 ++ctr.w ;
0090
0091 }
0092
0093 void increment_n(uint4& ctr, unsigned long long n, bool dump)
0094 {
0095 for(unsigned long long i=0ull ; i < n ; i++) increment(ctr);
0096 if(dump) std::cout << "increment_n " << std::setw(16) << n << " : " << ctr << "\n" ;
0097 }
0098
0099
0100
0101
0102 void skipahead(uint4& ctr, unsigned long long n)
0103 {
0104 unsigned int nlo = (unsigned int)(n);
0105 unsigned int nhi = (unsigned int)(n>>32);
0106
0107 ctr.x += nlo;
0108 if( ctr.x < nlo ) nhi++;
0109
0110 ctr.y += nhi;
0111 if(nhi <= ctr.y) return;
0112 if(ctr.z) return;
0113 ++ctr.w;
0114
0115 }
0116 void _skipahead(uint4& ctr, unsigned long long n)
0117 {
0118 skipahead(ctr, n);
0119 std::cout << "_skipahead " << std::hex << std::setw(16) << n << " : " << ctr << "\n" ;
0120 }
0121
0122
0123 int scuda_test::uint4_increment()
0124 {
0125 std::cout << "[scuda_test::uint4_increment\n" ;
0126 uint4 ctr = {};
0127 increment_n(ctr, 1000, true );
0128 std::cout << "]scuda_test::uint4_increment\n" ;
0129 return 0 ;
0130 }
0131
0132 int scuda_test::uint4_skipahead()
0133 {
0134 typedef unsigned long long ULL ;
0135 std::cout << "[scuda_test::uint4_skipahead \n" ;
0136 std::array<ULL,3> skip = { 1000ull, 0xffffffffull, 0xffffffffffffffffull };
0137 for(int i=0 ; i < int(skip.size()) ; i++ )
0138 {
0139 ULL n = skip[i];
0140
0141 uint4 ctr0 = {};
0142 uint4 ctr1 = {};
0143
0144 _skipahead(ctr0, n );
0145 _skipahead(ctr0, n );
0146 _skipahead(ctr0, n );
0147
0148 increment_n(ctr1, n, true );
0149 increment_n(ctr1, n, true );
0150 increment_n(ctr1, n, true );
0151
0152 }
0153 std::cout << "]scuda_test::uint4_skipahead \n" ;
0154 return 0 ;
0155 }
0156
0157
0158 int scuda_test::main()
0159 {
0160 bool ALL = strcmp(TEST, "ALL")==0 ;
0161 int rc = 0 ;
0162 if(ALL||0==strcmp(TEST,"cross")) rc += cross();
0163 if(ALL||0==strcmp(TEST,"indexed")) rc += indexed();
0164 if(ALL||0==strcmp(TEST,"efloat")) rc += efloat();
0165 if(ALL||0==strcmp(TEST,"serial")) rc += serial();
0166 if(ALL||0!=strstr(TEST,"uint4_increment")) rc += uint4_increment();
0167 if(ALL||0!=strstr(TEST,"uint4_skipahead")) rc += uint4_skipahead();
0168
0169 return rc ;
0170 }
0171
0172 int main(){ return scuda_test::main() ; }
0173
0174