GPU代碼編寫筆記

1. 內存拷貝

//重新排序points
    thrust::device_ptr<unsigned int> rank_ptr_points;//新建一個指針
    allocThrustDevicePtr(&rank_ptr_points, state.numPoints);//給指針申請空間,大小爲state.numPoints
    thrust::copy(state.pointsRankList, state.pointsRankList+state.numPoints, rank_ptr_points);//將state.pointsRankList中前state.numPoints個項複製到rank_ptr_points中

    thrust::device_ptr<float3> d_points_ptr = thrust::device_pointer_cast(state.params.points);//新建一個指向state.params.points的指針,這裏應該是指向的一個GPU內存
    sortByKey( rank_ptr_points, d_points_ptr, state.numPoints);//用rank_ptr_points作爲key,對d_points_ptr進行排序,元素數量爲state.numPoints,排完序後rank_ptr_points和d_points_ptr都會變的有序
    thrust::copy(d_points_ptr, d_points_ptr+state.numPoints, state.h_points);//將d_points_ptr拷貝回state.h_points,相當於將device拷貝回host

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章