@@ -33,32 +33,32 @@ using namespace std;
3333static void test_tensor2 (){
3434
3535 // /////////////////////////////////////////////////////////////////
36- // 内存的自动复制,依靠head属性标记数据最新的位置
37- // 若访问的数据不是最新的,则会自动发生复制操作
36+ /* 内存的自动复制,依靠head属性标记数据最新的位置
37+ 若访问的数据不是最新的,则会自动发生复制操作 */
3838 TRT::Tensor tensor ({1 , 3 , 5 , 5 }, TRT::DataType::Float);
39- INFO (" tensor.head = %s" , TRT::data_head_string (tensor.head ())); // 输出 Init,内存没有分配
39+ INFO (" tensor.head = %s" , TRT::data_head_string (tensor.head ())); /* 输出 Init,内存没有分配 */
4040
41- tensor.cpu <float >()[0 ] = 512 ; // 访问cpu时,分配cpu内存
42- INFO (" tensor.head = %s" , TRT::data_head_string (tensor.head ())); // 输出 Host
41+ tensor.cpu <float >()[0 ] = 512 ; /* 访问cpu时,分配cpu内存 */
42+ INFO (" tensor.head = %s" , TRT::data_head_string (tensor.head ())); /* 输出 Host */
4343
44- float * device_ptr = tensor.gpu <float >(); // 访问gpu时,最新数据在Host,发生复制动作并标记最新数据在Device
45- INFO (" tensor.head = %s" , TRT::data_head_string (tensor.head ())); // 输出 Device
46- INFO (" device_ptr[0] = %f" , device_ptr[0 ]); // 输出 512.00000
44+ float * device_ptr = tensor.gpu <float >(); /* 访问gpu时,最新数据在Host,发生复制动作并标记最新数据在Device */
45+ INFO (" tensor.head = %s" , TRT::data_head_string (tensor.head ())); /* 输出 Device */
46+ INFO (" device_ptr[0] = %f" , device_ptr[0 ]); /* 输出 512.00000 */
4747}
4848
4949static void test_tensor3 (){
5050
5151 // /////////////////////////////////////////////////////////////////
52- // 计算维度的偏移量
52+ /* 计算维度的偏移量 */
5353 TRT::Tensor tensor ({1 , 3 , 5 , 5 , 2 , 5 }, TRT::DataType::Float);
5454 auto ptr_origin = tensor.cpu <float >();
5555 auto ptr_channel2 = tensor.cpu <float >(0 , 2 , 3 , 2 , 1 , 3 );
5656
57- INFO (" Offset = %d" , ptr_channel2 - ptr_origin); // 输出678
58- INFO (" Offset = %d" , tensor.offset (0 , 2 , 3 , 2 , 1 , 3 )); // 输出678
57+ INFO (" Offset = %d" , ptr_channel2 - ptr_origin); /* 输出678 */
58+ INFO (" Offset = %d" , tensor.offset (0 , 2 , 3 , 2 , 1 , 3 )); /* 输出678 */
5959
6060 int offset_compute = ((((0 * 3 + 2 ) * 5 + 3 ) * 5 + 2 ) * 2 + 1 ) * 5 + 3 ;
61- INFO (" Compute = %d" , offset_compute); // 输出678
61+ INFO (" Compute = %d" , offset_compute); /* 输出678 */
6262}
6363
6464static void lesson1 (){
0 commit comments