[Linux][2012-08-28] c/cpp # 井号 双井号 的使用

本文详细介绍了C/C++宏定义中单井号(#)与双井号(##)的作用及使用方法。单井号(#)可以将参数转换为字符串,而双井号(##)则用于连接两个子串形成新的标识符。
在宏定义中经常会用到#和##
单井号(#)
把传递过来的参数当成字符串进行替代
如下示例:
#define display(name) printf(""#name"")
int main() {
  display(name);
}


输出:
name

说明:# 不可以 是第一个和最后一个, 所以 前后使用“”。



双井号(##)
称为连接符
在带参数的宏定义中将两个子串(token)联接起来,从而形成一个新的子串(变量或类型)。但它不可以是第一个或者最后一个子串。所谓的子串(token)就是指编译器能够识别的最小语法单元。具体的定义在参考编译原理。

下面是MSDN上的一个例子。
假设程序中已经定义了这样一个带参数的宏:

#define paster( n ) printf( "token" #n " = %d", token##n )
//同时又定义了一个整形变量:
int token9 = 9;


现在在主程序中以下面的方式调用这个宏:
paster( 9 );

那么在编译时,上面的这句话被扩展为:
printf( "token" "9" " = %d", token9 );

注意到在这个例子中,paster(9);中的这个”9”被原封不动的当成了一个字符串,与”token”连接在了一起,从而成为了token9。而#n也被”9”所替代。

可想而知,上面程序运行的结果就是在屏幕上打印出token9=9

原文转自:http://www.delnabla.cn/article.asp?id=205

参考:http://thatax.blog.163.com/blog/static/20892680200882391827116/

copying mmcv/ops/csrc/parrots/min_area_polygons_pytorch.h -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/parrots copying mmcv/ops/csrc/parrots/modulated_deform_conv.cpp -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/parrots copying mmcv/ops/csrc/parrots/modulated_deform_conv_parrots.cpp -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/parrots copying mmcv/ops/csrc/parrots/modulated_deform_conv_pytorch.h -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/parrots copying mmcv/ops/csrc/parrots/ms_deform_attn.cpp -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/parrots copying mmcv/ops/csrc/parrots/ms_deform_attn_parrots.cpp -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/parrots copying mmcv/ops/csrc/parrots/nms.cpp -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/parrots copying mmcv/ops/csrc/parrots/nms_parrots.cpp -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/parrots copying mmcv/ops/csrc/parrots/nms_pytorch.h -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/parrots copying mmcv/ops/csrc/parrots/nms_rotated.cpp -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/parrots copying mmcv/ops/csrc/parrots/pixel_group.cpp -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/parrots copying mmcv/ops/csrc/parrots/pixel_group_parrots.cpp -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/parrots copying mmcv/ops/csrc/parrots/pixel_group_pytorch.h -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/parrots copying mmcv/ops/csrc/parrots/points_in_boxes.cpp -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/parrots copying mmcv/ops/csrc/parrots/points_in_boxes_parrots.cpp -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/parrots copying mmcv/ops/csrc/parrots/points_in_boxes_pytorch.h -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/parrots copying mmcv/ops/csrc/parrots/points_in_polygons.cpp -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/parrots copying mmcv/ops/csrc/parrots/points_in_polygons_parrots.cpp -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/parrots copying mmcv/ops/csrc/parrots/points_in_polygons_pytorch.h -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/parrots copying mmcv/ops/csrc/parrots/psamask.cpp -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/parrots copying mmcv/ops/csrc/parrots/psamask_parrots.cpp -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/parrots copying mmcv/ops/csrc/parrots/psamask_pytorch.h -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/parrots copying mmcv/ops/csrc/parrots/riroi_align_rotated.cpp -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/parrots copying mmcv/ops/csrc/parrots/riroi_align_rotated_parrots.cpp -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/parrots copying mmcv/ops/csrc/parrots/riroi_align_rotated_pytorch.h -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/parrots copying mmcv/ops/csrc/parrots/roi_align.cpp -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/parrots copying mmcv/ops/csrc/parrots/roi_align_parrots.cpp -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/parrots copying mmcv/ops/csrc/parrots/roi_align_pytorch.h -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/parrots copying mmcv/ops/csrc/parrots/roi_align_rotated.cpp -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/parrots copying mmcv/ops/csrc/parrots/roi_align_rotated_parrots.cpp -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/parrots copying mmcv/ops/csrc/parrots/roi_align_rotated_pytorch.h -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/parrots copying mmcv/ops/csrc/parrots/roi_pool.cpp -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/parrots copying mmcv/ops/csrc/parrots/roi_pool_parrots.cpp -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/parrots copying mmcv/ops/csrc/parrots/roi_pool_pytorch.h -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/parrots copying mmcv/ops/csrc/parrots/roiaware_pool3d.cpp -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/parrots copying mmcv/ops/csrc/parrots/roiaware_pool3d_parrots.cpp -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/parrots copying mmcv/ops/csrc/parrots/roiaware_pool3d_pytorch.h -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/parrots copying mmcv/ops/csrc/parrots/roipoint_pool3d.cpp -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/parrots copying mmcv/ops/csrc/parrots/roipoint_pool3d_parrots.cpp -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/parrots copying mmcv/ops/csrc/parrots/roipoint_pool3d_pytorch.h -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/parrots copying mmcv/ops/csrc/parrots/rotated_feature_align.cpp -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/parrots copying mmcv/ops/csrc/parrots/rotated_feature_align_parrots.cpp -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/parrots copying mmcv/ops/csrc/parrots/rotated_feature_align_pytorch.h -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/parrots copying mmcv/ops/csrc/parrots/sync_bn.cpp -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/parrots copying mmcv/ops/csrc/parrots/sync_bn_parrots.cpp -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/parrots copying mmcv/ops/csrc/parrots/sync_bn_pytorch.h -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/parrots copying mmcv/ops/csrc/parrots/three_interpolate.cpp -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/parrots copying mmcv/ops/csrc/parrots/three_interpolate_parrots.cpp -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/parrots copying mmcv/ops/csrc/parrots/three_interpolate_pytorch.h -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/parrots copying mmcv/ops/csrc/parrots/three_nn.cpp -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/parrots copying mmcv/ops/csrc/parrots/three_nn_parrots.cpp -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/parrots copying mmcv/ops/csrc/parrots/three_nn_pytorch.h -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/parrots copying mmcv/ops/csrc/parrots/tin_shift.cpp -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/parrots copying mmcv/ops/csrc/parrots/tin_shift_parrots.cpp -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/parrots copying mmcv/ops/csrc/parrots/tin_shift_pytorch.h -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/parrots copying mmcv/ops/csrc/parrots/upfirdn2d.cpp -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/parrots copying mmcv/ops/csrc/parrots/upfirdn2d_parrots.cpp -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/parrots copying mmcv/ops/csrc/parrots/voxelization.cpp -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/parrots copying mmcv/ops/csrc/parrots/voxelization_parrots.cpp -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/parrots copying mmcv/ops/csrc/parrots/voxelization_pytorch.h -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/parrots creating build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/pytorch copying mmcv/ops/csrc/pytorch/active_rotated_filter.cpp -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/pytorch copying mmcv/ops/csrc/pytorch/assign_score_withk.cpp -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/pytorch copying mmcv/ops/csrc/pytorch/ball_query.cpp -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/pytorch copying mmcv/ops/csrc/pytorch/bbox_overlaps.cpp -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/pytorch copying mmcv/ops/csrc/pytorch/border_align.cpp -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/pytorch copying mmcv/ops/csrc/pytorch/box_iou_rotated.cpp -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/pytorch copying mmcv/ops/csrc/pytorch/carafe.cpp -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/pytorch copying mmcv/ops/csrc/pytorch/carafe_naive.cpp -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/pytorch copying mmcv/ops/csrc/pytorch/contour_expand.cpp -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/pytorch copying mmcv/ops/csrc/pytorch/convex_iou.cpp -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/pytorch copying mmcv/ops/csrc/pytorch/correlation.cpp -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/pytorch copying mmcv/ops/csrc/pytorch/deform_conv.cpp -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/pytorch copying mmcv/ops/csrc/pytorch/deform_roi_pool.cpp -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/pytorch copying mmcv/ops/csrc/pytorch/diff_iou_rotated.cpp -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/pytorch copying mmcv/ops/csrc/pytorch/focal_loss.cpp -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/pytorch copying mmcv/ops/csrc/pytorch/furthest_point_sample.cpp -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/pytorch copying mmcv/ops/csrc/pytorch/fused_bias_leakyrelu.cpp -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/pytorch copying mmcv/ops/csrc/pytorch/fused_spconv_ops.cpp -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/pytorch copying mmcv/ops/csrc/pytorch/gather_points.cpp -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/pytorch copying mmcv/ops/csrc/pytorch/group_points.cpp -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/pytorch copying mmcv/ops/csrc/pytorch/info.cpp -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/pytorch copying mmcv/ops/csrc/pytorch/iou3d.cpp -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/pytorch copying mmcv/ops/csrc/pytorch/knn.cpp -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/pytorch copying mmcv/ops/csrc/pytorch/masked_conv2d.cpp -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/pytorch copying mmcv/ops/csrc/pytorch/min_area_polygons.cpp -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/pytorch copying mmcv/ops/csrc/pytorch/modulated_deform_conv.cpp -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/pytorch copying mmcv/ops/csrc/pytorch/ms_deform_attn.cpp -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/pytorch copying mmcv/ops/csrc/pytorch/nms.cpp -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/pytorch copying mmcv/ops/csrc/pytorch/nms_rotated.cpp -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/pytorch copying mmcv/ops/csrc/pytorch/pixel_group.cpp -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/pytorch copying mmcv/ops/csrc/pytorch/points_in_boxes.cpp -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/pytorch copying mmcv/ops/csrc/pytorch/points_in_polygons.cpp -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/pytorch copying mmcv/ops/csrc/pytorch/psamask.cpp -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/pytorch copying mmcv/ops/csrc/pytorch/pybind.cpp -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/pytorch copying mmcv/ops/csrc/pytorch/riroi_align_rotated.cpp -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/pytorch copying mmcv/ops/csrc/pytorch/roi_align.cpp -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/pytorch copying mmcv/ops/csrc/pytorch/roi_align_rotated.cpp -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/pytorch copying mmcv/ops/csrc/pytorch/roi_pool.cpp -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/pytorch copying mmcv/ops/csrc/pytorch/roiaware_pool3d.cpp -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/pytorch copying mmcv/ops/csrc/pytorch/roipoint_pool3d.cpp -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/pytorch copying mmcv/ops/csrc/pytorch/rotated_feature_align.cpp -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/pytorch copying mmcv/ops/csrc/pytorch/scatter_points.cpp -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/pytorch copying mmcv/ops/csrc/pytorch/sparse_pool_ops.cpp -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/pytorch copying mmcv/ops/csrc/pytorch/spconv_ops.cpp -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/pytorch copying mmcv/ops/csrc/pytorch/spconv_utils.h -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/pytorch copying mmcv/ops/csrc/pytorch/sync_bn.cpp -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/pytorch copying mmcv/ops/csrc/pytorch/three_interpolate.cpp -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/pytorch copying mmcv/ops/csrc/pytorch/three_nn.cpp -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/pytorch copying mmcv/ops/csrc/pytorch/tin_shift.cpp -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/pytorch copying mmcv/ops/csrc/pytorch/upfirdn2d.cpp -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/pytorch copying mmcv/ops/csrc/pytorch/voxelization.cpp -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/pytorch creating build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/pytorch/cpu copying mmcv/ops/csrc/pytorch/cpu/active_rotated_filter.cpp -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/pytorch/cpu copying mmcv/ops/csrc/pytorch/cpu/box_iou_rotated.cpp -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/pytorch/cpu copying mmcv/ops/csrc/pytorch/cpu/deform_conv.cpp -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/pytorch/cpu copying mmcv/ops/csrc/pytorch/cpu/modulated_deform_conv.cpp -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/pytorch/cpu copying mmcv/ops/csrc/pytorch/cpu/nms.cpp -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/pytorch/cpu copying mmcv/ops/csrc/pytorch/cpu/nms_rotated.cpp -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/pytorch/cpu copying mmcv/ops/csrc/pytorch/cpu/pixel_group.cpp -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/pytorch/cpu copying mmcv/ops/csrc/pytorch/cpu/points_in_boxes.cpp -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/pytorch/cpu copying mmcv/ops/csrc/pytorch/cpu/psamask.cpp -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/pytorch/cpu copying mmcv/ops/csrc/pytorch/cpu/roi_align.cpp -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/pytorch/cpu copying mmcv/ops/csrc/pytorch/cpu/roi_align_rotated.cpp -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/pytorch/cpu copying mmcv/ops/csrc/pytorch/cpu/sparse_indice.cpp -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/pytorch/cpu copying mmcv/ops/csrc/pytorch/cpu/sparse_maxpool.cpp -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/pytorch/cpu copying mmcv/ops/csrc/pytorch/cpu/sparse_reordering.cpp -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/pytorch/cpu copying mmcv/ops/csrc/pytorch/cpu/voxelization.cpp -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/pytorch/cpu creating build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/pytorch/cuda copying mmcv/ops/csrc/pytorch/cuda/active_rotated_filter_cuda.cu -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/pytorch/cuda copying mmcv/ops/csrc/pytorch/cuda/assign_score_withk_cuda.cu -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/pytorch/cuda copying mmcv/ops/csrc/pytorch/cuda/ball_query_cuda.cu -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/pytorch/cuda copying mmcv/ops/csrc/pytorch/cuda/bbox_overlaps_cuda.cu -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/pytorch/cuda copying mmcv/ops/csrc/pytorch/cuda/border_align_cuda.cu -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/pytorch/cuda copying mmcv/ops/csrc/pytorch/cuda/box_iou_rotated_cuda.cu -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/pytorch/cuda copying mmcv/ops/csrc/pytorch/cuda/carafe_cuda.cu -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/pytorch/cuda copying mmcv/ops/csrc/pytorch/cuda/carafe_naive_cuda.cu -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/pytorch/cuda copying mmcv/ops/csrc/pytorch/cuda/convex_iou.cu -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/pytorch/cuda copying mmcv/ops/csrc/pytorch/cuda/correlation_cuda.cu -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/pytorch/cuda copying mmcv/ops/csrc/pytorch/cuda/cudabind.cpp -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/pytorch/cuda copying mmcv/ops/csrc/pytorch/cuda/deform_conv_cuda.cu -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/pytorch/cuda copying mmcv/ops/csrc/pytorch/cuda/deform_roi_pool_cuda.cu -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/pytorch/cuda copying mmcv/ops/csrc/pytorch/cuda/diff_iou_rotated_cuda.cu -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/pytorch/cuda copying mmcv/ops/csrc/pytorch/cuda/focal_loss_cuda.cu -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/pytorch/cuda copying mmcv/ops/csrc/pytorch/cuda/furthest_point_sample_cuda.cu -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/pytorch/cuda copying mmcv/ops/csrc/pytorch/cuda/fused_bias_leakyrelu_cuda.cu -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/pytorch/cuda copying mmcv/ops/csrc/pytorch/cuda/fused_spconv_ops_cuda.cu -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/pytorch/cuda copying mmcv/ops/csrc/pytorch/cuda/gather_points_cuda.cu -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/pytorch/cuda copying mmcv/ops/csrc/pytorch/cuda/group_points_cuda.cu -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/pytorch/cuda copying mmcv/ops/csrc/pytorch/cuda/iou3d_cuda.cu -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/pytorch/cuda copying mmcv/ops/csrc/pytorch/cuda/knn_cuda.cu -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/pytorch/cuda copying mmcv/ops/csrc/pytorch/cuda/masked_conv2d_cuda.cu -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/pytorch/cuda copying mmcv/ops/csrc/pytorch/cuda/min_area_polygons.cu -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/pytorch/cuda copying mmcv/ops/csrc/pytorch/cuda/modulated_deform_conv_cuda.cu -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/pytorch/cuda copying mmcv/ops/csrc/pytorch/cuda/ms_deform_attn_cuda.cu -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/pytorch/cuda copying mmcv/ops/csrc/pytorch/cuda/nms_cuda.cu -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/pytorch/cuda copying mmcv/ops/csrc/pytorch/cuda/nms_rotated_cuda.cu -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/pytorch/cuda copying mmcv/ops/csrc/pytorch/cuda/points_in_boxes_cuda.cu -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/pytorch/cuda copying mmcv/ops/csrc/pytorch/cuda/points_in_polygons_cuda.cu -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/pytorch/cuda copying mmcv/ops/csrc/pytorch/cuda/psamask_cuda.cu -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/pytorch/cuda copying mmcv/ops/csrc/pytorch/cuda/riroi_align_rotated_cuda.cu -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/pytorch/cuda copying mmcv/ops/csrc/pytorch/cuda/roi_align_cuda.cu -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/pytorch/cuda copying mmcv/ops/csrc/pytorch/cuda/roi_align_rotated_cuda.cu -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/pytorch/cuda copying mmcv/ops/csrc/pytorch/cuda/roi_pool_cuda.cu -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/pytorch/cuda copying mmcv/ops/csrc/pytorch/cuda/roiaware_pool3d_cuda.cu -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/pytorch/cuda copying mmcv/ops/csrc/pytorch/cuda/roipoint_pool3d_cuda.cu -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/pytorch/cuda copying mmcv/ops/csrc/pytorch/cuda/rotated_feature_align_cuda.cu -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/pytorch/cuda copying mmcv/ops/csrc/pytorch/cuda/scatter_points_cuda.cu -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/pytorch/cuda copying mmcv/ops/csrc/pytorch/cuda/sparse_indice.cu -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/pytorch/cuda copying mmcv/ops/csrc/pytorch/cuda/sparse_maxpool.cu -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/pytorch/cuda copying mmcv/ops/csrc/pytorch/cuda/sparse_pool_ops_cuda.cu -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/pytorch/cuda copying mmcv/ops/csrc/pytorch/cuda/sparse_reordering.cu -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/pytorch/cuda copying mmcv/ops/csrc/pytorch/cuda/spconv_ops_cuda.cu -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/pytorch/cuda copying mmcv/ops/csrc/pytorch/cuda/sync_bn_cuda.cu -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/pytorch/cuda copying mmcv/ops/csrc/pytorch/cuda/three_interpolate_cuda.cu -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/pytorch/cuda copying mmcv/ops/csrc/pytorch/cuda/three_nn_cuda.cu -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/pytorch/cuda copying mmcv/ops/csrc/pytorch/cuda/tin_shift_cuda.cu -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/pytorch/cuda copying mmcv/ops/csrc/pytorch/cuda/upfirdn2d_kernel.cu -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/pytorch/cuda copying mmcv/ops/csrc/pytorch/cuda/voxelization_cuda.cu -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/pytorch/cuda creating build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/pytorch/mlu copying mmcv/ops/csrc/pytorch/mlu/bbox_overlaps_mlu.cpp -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/pytorch/mlu copying mmcv/ops/csrc/pytorch/mlu/focal_loss_sigmoid_mlu.cpp -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/pytorch/mlu copying mmcv/ops/csrc/pytorch/mlu/nms_mlu.cpp -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/pytorch/mlu copying mmcv/ops/csrc/pytorch/mlu/roi_align_mlu.cpp -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/pytorch/mlu copying mmcv/ops/csrc/pytorch/mlu/tin_shift_mlu.cpp -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/pytorch/mlu creating build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/tensorrt copying mmcv/ops/csrc/tensorrt/trt_corner_pool.hpp -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/tensorrt copying mmcv/ops/csrc/tensorrt/trt_cuda_helper.cuh -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/tensorrt copying mmcv/ops/csrc/tensorrt/trt_cummaxmin.hpp -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/tensorrt copying mmcv/ops/csrc/tensorrt/trt_deform_conv.hpp -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/tensorrt copying mmcv/ops/csrc/tensorrt/trt_grid_sampler.hpp -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/tensorrt copying mmcv/ops/csrc/tensorrt/trt_instance_norm.hpp -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/tensorrt copying mmcv/ops/csrc/tensorrt/trt_modulated_deform_conv.hpp -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/tensorrt copying mmcv/ops/csrc/tensorrt/trt_nms.hpp -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/tensorrt copying mmcv/ops/csrc/tensorrt/trt_plugin.hpp -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/tensorrt copying mmcv/ops/csrc/tensorrt/trt_plugin_helper.hpp -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/tensorrt copying mmcv/ops/csrc/tensorrt/trt_roi_align.hpp -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/tensorrt copying mmcv/ops/csrc/tensorrt/trt_scatternd.hpp -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/tensorrt copying mmcv/ops/csrc/tensorrt/trt_serialize.hpp -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/tensorrt creating build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/tensorrt/plugins copying mmcv/ops/csrc/tensorrt/plugins/trt_corner_pool.cpp -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/tensorrt/plugins copying mmcv/ops/csrc/tensorrt/plugins/trt_corner_pool_kernel.cu -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/tensorrt/plugins copying mmcv/ops/csrc/tensorrt/plugins/trt_cuda_helper.cu -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/tensorrt/plugins copying mmcv/ops/csrc/tensorrt/plugins/trt_cummaxmin.cpp -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/tensorrt/plugins copying mmcv/ops/csrc/tensorrt/plugins/trt_cummaxmin_kernel.cu -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/tensorrt/plugins copying mmcv/ops/csrc/tensorrt/plugins/trt_deform_conv.cpp -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/tensorrt/plugins copying mmcv/ops/csrc/tensorrt/plugins/trt_deform_conv_kernel.cu -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/tensorrt/plugins copying mmcv/ops/csrc/tensorrt/plugins/trt_grid_sampler.cpp -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/tensorrt/plugins copying mmcv/ops/csrc/tensorrt/plugins/trt_grid_sampler_kernel.cu -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/tensorrt/plugins copying mmcv/ops/csrc/tensorrt/plugins/trt_instance_norm.cpp -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/tensorrt/plugins copying mmcv/ops/csrc/tensorrt/plugins/trt_modulated_deform_conv.cpp -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/tensorrt/plugins copying mmcv/ops/csrc/tensorrt/plugins/trt_modulated_deform_conv_kernel.cu -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/tensorrt/plugins copying mmcv/ops/csrc/tensorrt/plugins/trt_nms.cpp -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/tensorrt/plugins copying mmcv/ops/csrc/tensorrt/plugins/trt_nms_kernel.cu -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/tensorrt/plugins copying mmcv/ops/csrc/tensorrt/plugins/trt_plugin.cpp -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/tensorrt/plugins copying mmcv/ops/csrc/tensorrt/plugins/trt_roi_align.cpp -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/tensorrt/plugins copying mmcv/ops/csrc/tensorrt/plugins/trt_roi_align_kernel.cu -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/tensorrt/plugins copying mmcv/ops/csrc/tensorrt/plugins/trt_scatternd.cpp -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/tensorrt/plugins copying mmcv/ops/csrc/tensorrt/plugins/trt_scatternd_kernel.cu -> build/lib.linux-x86_64-cpython-310/mmcv/ops/csrc/tensorrt/plugins running build_ext Traceback (most recent call last): File "<string>", line 2, in <module> File "<pip-setuptools-caller>", line 35, in <module> File "/tmp/pip-install-llwa_afu/mmcv-full_ee0517bc5c5749f89f22f446bfc7022a/setup.py", line 393, in <module> setup( File "/home/tj/miniconda3/envs/hamer/lib/python3.10/site-packages/setuptools/__init__.py", line 117, in setup return distutils.core.setup(**attrs) File "/home/tj/miniconda3/envs/hamer/lib/python3.10/site-packages/setuptools/_distutils/core.py", line 186, in setup return run_commands(dist) File "/home/tj/miniconda3/envs/hamer/lib/python3.10/site-packages/setuptools/_distutils/core.py", line 202, in run_commands dist.run_commands() File "/home/tj/miniconda3/envs/hamer/lib/python3.10/site-packages/setuptools/_distutils/dist.py", line 1002, in run_commands self.run_command(cmd) File "/home/tj/miniconda3/envs/hamer/lib/python3.10/site-packages/setuptools/dist.py", line 1104, in run_command super().run_command(command) File "/home/tj/miniconda3/envs/hamer/lib/python3.10/site-packages/setuptools/_distutils/dist.py", line 1021, in run_command cmd_obj.run() File "/home/tj/miniconda3/envs/hamer/lib/python3.10/site-packages/setuptools/command/bdist_wheel.py", line 370, in run self.run_command("build") File "/home/tj/miniconda3/envs/hamer/lib/python3.10/site-packages/setuptools/_distutils/cmd.py", line 357, in run_command self.distribution.run_command(command) File "/home/tj/miniconda3/envs/hamer/lib/python3.10/site-packages/setuptools/dist.py", line 1104, in run_command super().run_command(command) File "/home/tj/miniconda3/envs/hamer/lib/python3.10/site-packages/setuptools/_distutils/dist.py", line 1021, in run_command cmd_obj.run() File "/home/tj/miniconda3/envs/hamer/lib/python3.10/site-packages/setuptools/_distutils/command/build.py", line 135, in run self.run_command(cmd_name) File "/home/tj/miniconda3/envs/hamer/lib/python3.10/site-packages/setuptools/_distutils/cmd.py", line 357, in run_command self.distribution.run_command(command) File "/home/tj/miniconda3/envs/hamer/lib/python3.10/site-packages/setuptools/dist.py", line 1104, in run_command super().run_command(command) File "/home/tj/miniconda3/envs/hamer/lib/python3.10/site-packages/setuptools/_distutils/dist.py", line 1021, in run_command cmd_obj.run() File "/home/tj/miniconda3/envs/hamer/lib/python3.10/site-packages/setuptools/command/build_ext.py", line 99, in run _build_ext.run(self) File "/home/tj/miniconda3/envs/hamer/lib/python3.10/site-packages/setuptools/_distutils/command/build_ext.py", line 368, in run self.build_extensions() File "/home/tj/miniconda3/envs/hamer/lib/python3.10/site-packages/torch/utils/cpp_extension.py", line 650, in build_extensions _check_cuda_version(compiler_name, compiler_version) File "/home/tj/miniconda3/envs/hamer/lib/python3.10/site-packages/torch/utils/cpp_extension.py", line 506, in _check_cuda_version raise RuntimeError(CUDA_MISMATCH_MESSAGE, cuda_str_version, torch.version.cuda) RuntimeError: (&#39;The detected CUDA version (%s) mismatches the version that was used to compilePyTorch (%s). Please make sure to use the same CUDA versions.&#39;, &#39;11.7&#39;, &#39;12.8&#39;) [end of output] note: This error originates from a subprocess, and is likely not a problem with pip. ERROR: Failed building wheel for mmcv-full Running setup.py clean for mmcv-full Failed to build mmcv-full error: failed-wheel-build-for-install × Failed to build installable wheels for some pyproject.toml based projects ╰─> mmcv-full
10-06
<think>根据用户描述,在运行`camera_demo_light.py`脚本时遇到mmcv-full库构建失败的问题,具体错误是CUDA版本(11.7)与编译PyTorch时使用的CUDA版本(12.8)不匹配。这是一个常见的环境配置问题,我们需要确保CUDA、PyTorch和mmcv-full的版本兼容。 ### 问题分析 1. **版本不匹配**:PyTorch可能是使用CUDA 12.1编译的,而当前系统中安装的CUDA版本是11.7。mmcv-full在安装时会根据系统中CUDA的版本和PyTorch的版本来编译,如果版本不一致,就会导致编译失败。 2. **解决方案**:需要确保PyTorch、CUDA和mmcv-full三者的版本兼容。 ### 解决步骤 #### 步骤1:确认当前环境中的CUDA版本和PyTorch编译使用的CUDA版本 - 在终端中运行以下命令检查CUDA版本: ```bash nvcc --version ``` 或者 ```bash cat /usr/local/cuda/version.txt ``` - 在Python中检查PyTorch使用的CUDA版本: ```python import torch print(torch.__version__) print(torch.version.cuda) ``` #### 步骤2:调整环境以统一版本 有两种解决方案: ##### 方案A:升级系统CUDA到12.1(推荐但操作复杂) 1. 卸载当前CUDA 11.7,安装CUDA 12.1。 2. 重新安装与CUDA 12.1匹配的PyTorch版本。 3. 安装与PyTorch和CUDA 12.1兼容的mmcv-full。 ##### 方案B:安装与CUDA 11.7匹配的PyTorch版本(更简单) 1. 卸载当前PyTorch(使用CUDA 12.1编译的版本)。 2. 安装使用CUDA 11.7编译的PyTorch版本。 3. 安装与CUDA 11.7和PyTorch版本匹配的mmcv-full。 由于升级系统CUDA可能影响其他程序,推荐方案B。 #### 步骤3:具体操作(方案B) 1. **卸载当前PyTorch**: ```bash pip uninstall torch torchvision torchaudio ``` 2. **安装CUDA 11.7版本的PyTorch**: 访问[PyTorch官网](https://pytorch.org/get-started/previous-versions/),查找与CUDA 11.7兼容的版本。例如,对于PyTorch 2.0.1,安装命令为: ```bash pip install torch==2.0.1+cu117 torchvision==0.15.2+cu117 torchaudio==2.0.2 --index-url https://download.pytorch.org/whl/cu117 ``` 3. **安装匹配的mmcv-full**: 根据PyTorch和CUDA版本,选择合适的mmcv-full版本。可以查看[mmcv官方文档](https://mmcv.readthedocs.io/en/latest/get_started/installation.html)获取版本匹配信息。 例如,对于PyTorch 2.0.1和CUDA 11.7,可以安装: ```bash pip install mmcv-full==1.7.1 -f https://download.openmmlab.com/mmcv/dist/cu117/torch2.0.1/index.html ``` #### 步骤4:验证安装 运行以下Python代码检查版本: ```python import torch import mmcv print(f"PyTorch版本: {torch.__version__}") print(f"PyTorch使用的CUDA版本: {torch.version.cuda}") print(f"mmcv-full版本: {mmcv.__version__}") ``` 确保输出中PyTorch的CUDA版本为11.7,且mmcv-full版本与安装一致。 ### 注意事项 - 如果使用conda环境,请确保在正确的环境中操作。 - 安装过程中可能会遇到依赖冲突,建议使用干净的虚拟环境。 - 如果安装mmcv-full时仍然遇到问题,可以尝试从源码编译,但过程较为复杂。详情参考[官方编译指南](https://mmcv.readthedocs.io/en/latest/get_started/build.html)。 ### 替代解决方案 如果上述步骤仍然无法解决问题,可以考虑使用预编译的Docker镜像,其中已经配置好兼容的环境。例如,使用OpenMMLab提供的Docker镜像: ```bash docker pull openmmlab/mmdetection:3.0.0 ``` ### 相关问题 1. 如何检查系统中安装的CUDA版本? 2. PyTorch版本与CUDA版本不兼容会出现哪些问题? 3. 卸载CUDA的正确步骤是什么? 通过以上步骤,应该能够解决mmcv-full安装时的版本不匹配问题[^1]。 </think>### 解决mmcv-full构建失败:CUDA版本不匹配问题 #### 问题诊断 CUDA版本与PyTorch编译版本不匹配的根本原因是: $$ \text{系统CUDA版本}(11.7) \neq \text{PyTorch编译时CUDA版本}(12.8) $$ 这种不兼容会导致mmcv-full编译时出现底层库链接错误[^1]。 --- ### 解决方案步骤 #### 步骤1:验证实际环境版本 ```bash # 检查系统CUDA版本 nvcc --version # 检查PyTorch使用的CUDA版本 python -c "import torch; print(f&#39;PyTorch CUDA: {torch.version.cuda}&#39;)" # 检查已安装mmcv版本 pip list | grep mmcv ``` #### 步骤2:重新安装匹配的PyTorch ```bash # 卸载当前PyTorch pip uninstall -y torch torchvision torchaudio # 安装CUDA 11.7兼容的PyTorch (2023年10月最新版本) pip install torch==2.0.1+cu117 torchvision==0.15.2+cu117 torchaudio==2.0.2 \ --index-url https://download.pytorch.org/whl/cu117 ``` #### 步骤3:安装兼容的mmcv-full ```bash # 安装匹配CUDA 11.7的mmcv-full pip install mmcv-full==1.7.1 -f https://download.openmmlab.com/mmcv/dist/cu117/torch2.0.0/index.html ``` #### 步骤4:环境验证脚本 创建`verify_env.py`: ```python import torch import mmcv def check_versions(): print(f"[✓] PyTorch版本: {torch.__version__}") print(f"[✓] PyTorch CUDA: {torch.version.cuda}") print(f"[✓] mmcv-full版本: {mmcv.__version__}") # 验证CUDA兼容性 if "cu117" in torch.__version__ and "cu117" in mmcv.__version__: print("[✓] CUDA 11.7环境验证通过") else: print("[×] 版本不匹配!请检查安装") # 测试基本功能 if torch.cuda.is_available(): print(f"[✓] CUDA设备可用: {torch.cuda.get_device_name(0)}") else: print("[×] CUDA不可用!") if __name__ == "__main__": check_versions() ``` #### 步骤5:清理缓存并重试 ```bash # 强制清除构建缓存 rm -rf ~/.cache/pip rm -rf ~/.cache/torch_extensions # 重新运行您的脚本 python camera_demo_light.py ``` --- ### 版本兼容矩阵(关键) | 组件 | 推荐版本 | 验证组合 | |-------------|-------------|------------------| | PyTorch | 2.0.1+cu117 | ✅ 稳定运行 | | torchvision | 0.15.2+cu117| ✅ 兼容性好 | | mmcv-full | 1.7.1 | ✅ 完美兼容cu117 | | CUDA | 11.7 | ✅ 官方支持版本 | > **注意**:避免使用`conda`安装PyTorch,因其CUDA版本管理不如pip直接[^1]。 --- ### 高级解决方案(适用于持续集成) 创建`install_deps.sh`自动化脚本: ```bash #!/bin/bash # 强制设置CUDA版本 export FORCE_CUDA="1" export CUDA_HOME="/usr/local/cuda-11.7" # 安装PyTorch pip install torch==2.0.1+cu117 torchvision==0.15.2+cu117 --extra-index-url https://download.pytorch.org/whl/cu117 # 从源码编译mmcv-full (确保最佳兼容性) git clone https://github.com/open-mmlab/mmcv.git cd mmcv MMCV_WITH_OPS=1 pip install -e . -v ``` --- ### 常见错误处理 1. **`nvcc not found`错误**: ```bash # 确保CUDA路径正确 export PATH="/usr/local/cuda-11.7/bin:$PATH" export LD_LIBRARY_PATH="/usr/local/cuda-11.7/lib64:$LD_LIBRARY_PATH" ``` 2. **`undefined symbol`运行时错误**: ```bash # 完全重装所有依赖 pip uninstall -y mmcv-full rm -rf build/ pip install -v -e . ``` --- ### 性能优化建议 启用JIT编译加速: ```python # 在camera_demo_light.py中添加 torch.set_flush_denormal(True) torch.backends.cudnn.benchmark = True # 启用cuDNN自动优化 ``` > 注:Jetson设备需额外执行 `sudo nvpmodel -m 0` 启用最大性能模式[^1]。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值