Back to home page

EIC code displayed by LXR

 
 

    


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

0001 #include <cassert>
0002 #include <csignal>
0003 #include "scuda.h"
0004 #include "QU.hh"
0005 
0006 
0007 void test_not_set_pointer( int* p )
0008 {
0009     p = nullptr ; 
0010 }
0011 void test_set_pointer( int** pp )
0012 {
0013     *pp = nullptr ; 
0014 }
0015 void test_set_pointer()
0016 {
0017     int i = 101 ; 
0018 
0019     int* p0 = &i ; 
0020     int* p = &i ; 
0021 
0022     test_not_set_pointer( p ); 
0023     printf("test_not_set_pointer  p %p \n", p ); 
0024 
0025     bool p_expect = p == p0 ; 
0026     assert( p_expect && "test_not_set_pointer :  expected to NOT set the pointer in the calling scope"); 
0027     if(!p_expect) std::raise(SIGINT); 
0028 
0029     test_set_pointer( &p ); 
0030     printf("test_set_pointer  p %p \n", p ); 
0031     assert( p == nullptr && "test_set_pointer : expected to set the pointer in the calling scope, using pointer-to-pointer argument "); 
0032 }
0033 
0034 
0035 void test_device_free_and_alloc()
0036 {
0037     std::vector<float> v = {1.f, 2.f, 3.f } ;
0038 
0039     float* d_v = nullptr ; 
0040 
0041     QU::device_free_and_alloc<float>(&d_v, v.size() ); 
0042 
0043     printf(" d_v %p \n", d_v ); 
0044     assert( d_v ); 
0045 
0046     QU::copy_host_to_device<float>(d_v, v.data(), v.size() );  
0047 
0048     std::vector<float> v2(v.size(), 0.f) ; 
0049    
0050     QU::copy_device_to_host<float>(v2.data(), d_v, v2.size() );  
0051 
0052     for(unsigned i=0 ; i < v.size() ; i++ ) assert( v2[i] == v[i] ); 
0053 }
0054 
0055 
0056 int main(int argc, char** argv)
0057 {
0058     printf("%s\n",argv[0]); 
0059 
0060     //test_set_pointer(); 
0061     test_device_free_and_alloc(); 
0062 
0063     return 0 ; 
0064 }