Skip to content

Commit

Permalink
raw pointer cast
Browse files Browse the repository at this point in the history
  • Loading branch information
neka-nat committed Aug 17, 2023
1 parent 122b69b commit c3466b0
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 35 deletions.
2 changes: 1 addition & 1 deletion src/cupoch/geometry/occupancygrid.cu
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,7 @@ OccupancyGrid& OccupancyGrid::Insert(
float max_range) {
utility::device_vector<Eigen::Vector3f> dev_points(points.size());
cudaSafeCall(cudaMemcpy(
thrust::raw_pointer_cast(dev_points.data()), points.data(),
thrust::raw_pointer_cast(dev_points.data()), thrust::raw_pointer_cast(points.data()),
points.size() * sizeof(Eigen::Vector3f), cudaMemcpyHostToDevice));
return Insert(dev_points, viewpoint, max_range);
}
Expand Down
4 changes: 2 additions & 2 deletions src/cupoch/io/class_io/image_io.cu
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ void HostImage::FromDevice(const geometry::Image& image) {
data_.resize(image.data_.size());
Prepare(image.width_, image.height_, image.num_of_channels_,
image.bytes_per_channel_);
cudaSafeCall(cudaMemcpy(data_.data(), thrust::raw_pointer_cast(image.data_.data()), image.data_.size(), cudaMemcpyDeviceToHost));
cudaSafeCall(cudaMemcpy(thrust::raw_pointer_cast(data_.data()), thrust::raw_pointer_cast(image.data_.data()), image.data_.size(), cudaMemcpyDeviceToHost));
}

void HostImage::ToDevice(geometry::Image& image) const {
image.Prepare(width_, height_, num_of_channels_, bytes_per_channel_);
image.data_.resize(data_.size());
cudaSafeCall(cudaMemcpy(thrust::raw_pointer_cast(image.data_.data()), data_.data(), image.data_.size(), cudaMemcpyHostToDevice));
cudaSafeCall(cudaMemcpy(thrust::raw_pointer_cast(image.data_.data()), thrust::raw_pointer_cast(data_.data()), image.data_.size(), cudaMemcpyHostToDevice));
}

void HostImage::Clear() {
Expand Down
12 changes: 6 additions & 6 deletions src/cupoch/io/class_io/pointcloud_io.cu
Original file line number Diff line number Diff line change
Expand Up @@ -30,23 +30,23 @@ void HostPointCloud::FromDevice(const geometry::PointCloud& pointcloud) {
points_.resize(pointcloud.points_.size());
normals_.resize(pointcloud.normals_.size());
colors_.resize(pointcloud.colors_.size());
cudaSafeCall(cudaMemcpy(points_.data(), thrust::raw_pointer_cast(pointcloud.points_.data()),
cudaSafeCall(cudaMemcpy(thrust::raw_pointer_cast(points_.data()), thrust::raw_pointer_cast(pointcloud.points_.data()),
points_.size() * sizeof(Eigen::Vector3f), cudaMemcpyDeviceToHost));
cudaSafeCall(cudaMemcpy(normals_.data(), thrust::raw_pointer_cast(pointcloud.normals_.data()),
cudaSafeCall(cudaMemcpy(thrust::raw_pointer_cast(normals_.data()), thrust::raw_pointer_cast(pointcloud.normals_.data()),
normals_.size() * sizeof(Eigen::Vector3f), cudaMemcpyDeviceToHost));
cudaSafeCall(cudaMemcpy(colors_.data(), thrust::raw_pointer_cast(pointcloud.colors_.data()),
cudaSafeCall(cudaMemcpy(thrust::raw_pointer_cast(colors_.data()), thrust::raw_pointer_cast(pointcloud.colors_.data()),
colors_.size() * sizeof(Eigen::Vector3f), cudaMemcpyDeviceToHost));
}

void HostPointCloud::ToDevice(geometry::PointCloud& pointcloud) const {
pointcloud.points_.resize(points_.size());
pointcloud.normals_.resize(normals_.size());
pointcloud.colors_.resize(colors_.size());
cudaSafeCall(cudaMemcpy(thrust::raw_pointer_cast(pointcloud.points_.data()), points_.data(),
cudaSafeCall(cudaMemcpy(thrust::raw_pointer_cast(pointcloud.points_.data()), thrust::raw_pointer_cast(points_.data()),
points_.size() * sizeof(Eigen::Vector3f), cudaMemcpyHostToDevice));
cudaSafeCall(cudaMemcpy(thrust::raw_pointer_cast(pointcloud.normals_.data()), normals_.data(),
cudaSafeCall(cudaMemcpy(thrust::raw_pointer_cast(pointcloud.normals_.data()), thrust::raw_pointer_cast(normals_.data()),
normals_.size() * sizeof(Eigen::Vector3f), cudaMemcpyHostToDevice));
cudaSafeCall(cudaMemcpy(thrust::raw_pointer_cast(pointcloud.colors_.data()), colors_.data(),
cudaSafeCall(cudaMemcpy(thrust::raw_pointer_cast(pointcloud.colors_.data()), thrust::raw_pointer_cast(colors_.data()),
colors_.size() * sizeof(Eigen::Vector3f), cudaMemcpyHostToDevice));
}

Expand Down
24 changes: 12 additions & 12 deletions src/cupoch/io/class_io/trianglemesh_io.cu
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,17 @@ void HostTriangleMesh::FromDevice(const geometry::TriangleMesh& trianglemesh) {
triangles_.resize(trianglemesh.triangles_.size());
triangle_normals_.resize(trianglemesh.triangle_normals_.size());
triangle_uvs_.resize(trianglemesh.triangle_uvs_.size());
cudaSafeCall(cudaMemcpy(vertices_.data(), thrust::raw_pointer_cast(trianglemesh.vertices_.data()),
cudaSafeCall(cudaMemcpy(thrust::raw_pointer_cast(vertices_.data()), thrust::raw_pointer_cast(trianglemesh.vertices_.data()),
vertices_.size() * sizeof(Eigen::Vector3f), cudaMemcpyDeviceToHost));
cudaSafeCall(cudaMemcpy(vertex_normals_.data(), thrust::raw_pointer_cast(trianglemesh.vertex_normals_.data()),
cudaSafeCall(cudaMemcpy(thrust::raw_pointer_cast(vertex_normals_.data()), thrust::raw_pointer_cast(trianglemesh.vertex_normals_.data()),
vertex_normals_.size() * sizeof(Eigen::Vector3f), cudaMemcpyDeviceToHost));
cudaSafeCall(cudaMemcpy(vertex_colors_.data(), thrust::raw_pointer_cast(trianglemesh.vertex_colors_.data()),
cudaSafeCall(cudaMemcpy(thrust::raw_pointer_cast(vertex_colors_.data()), thrust::raw_pointer_cast(trianglemesh.vertex_colors_.data()),
vertex_colors_.size() * sizeof(Eigen::Vector3f), cudaMemcpyDeviceToHost));
cudaSafeCall(cudaMemcpy(triangles_.data(), thrust::raw_pointer_cast(trianglemesh.triangles_.data()),
cudaSafeCall(cudaMemcpy(thrust::raw_pointer_cast(triangles_.data()), thrust::raw_pointer_cast(trianglemesh.triangles_.data()),
triangles_.size() * sizeof(Eigen::Vector3i), cudaMemcpyDeviceToHost));
cudaSafeCall(cudaMemcpy(triangle_normals_.data(), thrust::raw_pointer_cast(trianglemesh.triangle_normals_.data()),
cudaSafeCall(cudaMemcpy(thrust::raw_pointer_cast(triangle_normals_.data()), thrust::raw_pointer_cast(trianglemesh.triangle_normals_.data()),
triangle_normals_.size() * sizeof(Eigen::Vector3f), cudaMemcpyDeviceToHost));
cudaSafeCall(cudaMemcpy(triangle_uvs_.data(), thrust::raw_pointer_cast(trianglemesh.triangle_uvs_.data()),
cudaSafeCall(cudaMemcpy(thrust::raw_pointer_cast(triangle_uvs_.data()), thrust::raw_pointer_cast(trianglemesh.triangle_uvs_.data()),
triangle_uvs_.size() * sizeof(Eigen::Vector2f), cudaMemcpyDeviceToHost));
texture_.FromDevice(trianglemesh.texture_);
}
Expand All @@ -54,17 +54,17 @@ void HostTriangleMesh::ToDevice(geometry::TriangleMesh& trianglemesh) const {
trianglemesh.triangles_.resize(triangles_.size());
trianglemesh.triangle_normals_.resize(triangle_normals_.size());
trianglemesh.triangle_uvs_.resize(triangle_uvs_.size());
cudaSafeCall(cudaMemcpy(thrust::raw_pointer_cast(trianglemesh.vertices_.data()), vertices_.data(),
cudaSafeCall(cudaMemcpy(thrust::raw_pointer_cast(trianglemesh.vertices_.data()), thrust::raw_pointer_cast(vertices_.data()),
vertices_.size() * sizeof(Eigen::Vector3f), cudaMemcpyHostToDevice));
cudaSafeCall(cudaMemcpy(thrust::raw_pointer_cast(trianglemesh.vertex_normals_.data()), vertex_normals_.data(),
cudaSafeCall(cudaMemcpy(thrust::raw_pointer_cast(trianglemesh.vertex_normals_.data()), thrust::raw_pointer_cast(vertex_normals_.data()),
vertex_normals_.size() * sizeof(Eigen::Vector3f), cudaMemcpyHostToDevice));
cudaSafeCall(cudaMemcpy(thrust::raw_pointer_cast(trianglemesh.vertex_colors_.data()), vertex_colors_.data(),
cudaSafeCall(cudaMemcpy(thrust::raw_pointer_cast(trianglemesh.vertex_colors_.data()), thrust::raw_pointer_cast(vertex_colors_.data()),
vertex_colors_.size() * sizeof(Eigen::Vector3f), cudaMemcpyHostToDevice));
cudaSafeCall(cudaMemcpy(thrust::raw_pointer_cast(trianglemesh.triangles_.data()), triangles_.data(),
cudaSafeCall(cudaMemcpy(thrust::raw_pointer_cast(trianglemesh.triangles_.data()), thrust::raw_pointer_cast(triangles_.data()),
triangles_.size() * sizeof(Eigen::Vector3i), cudaMemcpyHostToDevice));
cudaSafeCall(cudaMemcpy(thrust::raw_pointer_cast(trianglemesh.triangle_normals_.data()), triangle_normals_.data(),
cudaSafeCall(cudaMemcpy(thrust::raw_pointer_cast(trianglemesh.triangle_normals_.data()), thrust::raw_pointer_cast(triangle_normals_.data()),
triangle_normals_.size() * sizeof(Eigen::Vector3f), cudaMemcpyHostToDevice));
cudaSafeCall(cudaMemcpy(thrust::raw_pointer_cast(trianglemesh.triangle_uvs_.data()), triangle_uvs_.data(),
cudaSafeCall(cudaMemcpy(thrust::raw_pointer_cast(trianglemesh.triangle_uvs_.data()), thrust::raw_pointer_cast(triangle_uvs_.data()),
triangle_uvs_.size() * sizeof(Eigen::Vector2f), cudaMemcpyHostToDevice));
texture_.ToDevice(trianglemesh.texture_);
}
Expand Down
8 changes: 4 additions & 4 deletions src/cupoch/io/class_io/voxelgrid_io.cu
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,18 @@ using namespace cupoch::io;
void HostVoxelGrid::FromDevice(const geometry::VoxelGrid& voxelgrid) {
voxels_keys_.resize(voxelgrid.voxels_keys_.size());
voxels_values_.resize(voxelgrid.voxels_values_.size());
cudaSafeCall(cudaMemcpy(voxels_keys_.data(), thrust::raw_pointer_cast(voxelgrid.voxels_keys_.data()),
cudaSafeCall(cudaMemcpy(thrust::raw_pointer_cast(voxels_keys_.data()), thrust::raw_pointer_cast(voxelgrid.voxels_keys_.data()),
voxels_keys_.size() * sizeof(Eigen::Vector3i), cudaMemcpyDeviceToHost));
cudaSafeCall(cudaMemcpy(voxels_values_.data(), thrust::raw_pointer_cast(voxelgrid.voxels_values_.data()),
cudaSafeCall(cudaMemcpy(thrust::raw_pointer_cast(voxels_values_.data()), thrust::raw_pointer_cast(voxelgrid.voxels_values_.data()),
voxels_values_.size() * sizeof(geometry::Voxel), cudaMemcpyDeviceToHost));
}

void HostVoxelGrid::ToDevice(geometry::VoxelGrid& voxelgrid) const {
voxelgrid.voxels_keys_.resize(voxels_keys_.size());
voxelgrid.voxels_values_.resize(voxels_values_.size());
cudaSafeCall(cudaMemcpy(thrust::raw_pointer_cast(voxelgrid.voxels_keys_.data()), voxels_keys_.data(),
cudaSafeCall(cudaMemcpy(thrust::raw_pointer_cast(voxelgrid.voxels_keys_.data()), thrust::raw_pointer_cast(voxels_keys_.data()),
voxels_keys_.size() * sizeof(Eigen::Vector3i), cudaMemcpyHostToDevice));
cudaSafeCall(cudaMemcpy(thrust::raw_pointer_cast(voxelgrid.voxels_values_.data()), voxels_values_.data(),
cudaSafeCall(cudaMemcpy(thrust::raw_pointer_cast(voxelgrid.voxels_values_.data()), thrust::raw_pointer_cast(voxels_values_.data()),
voxels_values_.size() * sizeof(geometry::Voxel), cudaMemcpyHostToDevice));
}

Expand Down
4 changes: 2 additions & 2 deletions src/cupoch/io/file_format/file_jpg.cu
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ bool ReadImageFromJPG(const std::string &filename, geometry::Image &image) {
int row_stride = cinfo.output_width * cinfo.output_components;
buffer = (*cinfo.mem->alloc_sarray)((j_common_ptr)&cinfo, JPOOL_IMAGE,
row_stride, 1);
uint8_t *pdata = host_img.data_.data();
uint8_t *pdata = thrust::raw_pointer_cast(host_img.data_.data());
while (cinfo.output_scanline < cinfo.output_height) {
jpeg_read_scanlines(&cinfo, buffer, 1);
memcpy(pdata, buffer[0], row_stride);
Expand Down Expand Up @@ -128,7 +128,7 @@ bool WriteImageToJPG(const std::string &filename,
int row_stride = image.width_ * image.num_of_channels_;
HostImage host_img;
host_img.FromDevice(image);
const uint8_t *pdata = host_img.data_.data();
const uint8_t *pdata = thrust::raw_pointer_cast(host_img.data_.data());
std::vector<uint8_t> buffer(row_stride);
while (cinfo.next_scanline < cinfo.image_height) {
memcpy(buffer.data(), pdata, row_stride);
Expand Down
6 changes: 3 additions & 3 deletions src/cupoch/io/file_format/file_png.cu
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ bool ReadImageFromPNG(const std::string &filename, geometry::Image &image) {
PNG_IMAGE_SAMPLE_CHANNELS(pngimage.format),
PNG_IMAGE_SAMPLE_COMPONENT_SIZE(pngimage.format));
SetPNGImageFromImage(host_img, pngimage);
if (png_image_finish_read(&pngimage, NULL, host_img.data_.data(), 0,
if (png_image_finish_read(&pngimage, NULL, thrust::raw_pointer_cast(host_img.data_.data()), 0,
NULL) == 0) {
utility::LogWarning("Read PNG failed: unable to read file: {}",
filename);
Expand All @@ -107,7 +107,7 @@ bool WriteImageToPNG(const std::string &filename,
HostImage host_img;
host_img.FromDevice(image);
if (png_image_write_to_file(&pngimage, filename.c_str(), 0,
host_img.data_.data(), 0, NULL) == 0) {
thrust::raw_pointer_cast(host_img.data_.data()), 0, NULL) == 0) {
utility::LogWarning("Write PNG failed: unable to write file: {}",
filename);
return false;
Expand All @@ -127,7 +127,7 @@ bool WriteHostImageToPNG(const std::string &filename,
pngimage.version = PNG_IMAGE_VERSION;
SetPNGImageFromImage(image, pngimage);
if (png_image_write_to_file(&pngimage, filename.c_str(), 0,
image.data_.data(), 0, NULL) == 0) {
thrust::raw_pointer_cast(image.data_.data()), 0, NULL) == 0) {
utility::LogWarning("Write PNG failed: unable to write file: {}",
filename);
return false;
Expand Down
8 changes: 4 additions & 4 deletions src/python/cupoch_pybind/device_map_wrapper.cu
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ device_map_wrapper<KeyType, ValueType, Hash>::device_map_wrapper(
keys[cnt] = it.first;
values[cnt] = it.second;
}
cudaSafeCall(cudaMemcpy(thrust::raw_pointer_cast(keys_.data()), keys.data(),
cudaSafeCall(cudaMemcpy(thrust::raw_pointer_cast(keys_.data()), thrust::raw_pointer_cast(keys.data()),
other.size() * sizeof(KeyType), cudaMemcpyHostToDevice));
cudaSafeCall(cudaMemcpy(thrust::raw_pointer_cast(values_.data()), values.data(),
cudaSafeCall(cudaMemcpy(thrust::raw_pointer_cast(values_.data()), thrust::raw_pointer_cast(values.data()),
other.size() * sizeof(ValueType), cudaMemcpyHostToDevice));
}

Expand Down Expand Up @@ -82,9 +82,9 @@ std::unordered_map<KeyType, ValueType, Hash>
device_map_wrapper<KeyType, ValueType, Hash>::cpu() const {
utility::pinned_host_vector<KeyType> keys(keys_.size());
utility::pinned_host_vector<ValueType> values(values_.size());
cudaSafeCall(cudaMemcpy(keys.data(), thrust::raw_pointer_cast(keys_.data()),
cudaSafeCall(cudaMemcpy(thrust::raw_pointer_cast(keys.data()), thrust::raw_pointer_cast(keys_.data()),
keys.size() * sizeof(KeyType), cudaMemcpyDeviceToHost));
cudaSafeCall(cudaMemcpy(values.data(), thrust::raw_pointer_cast(values_.data()),
cudaSafeCall(cudaMemcpy(thrust::raw_pointer_cast(values.data()), thrust::raw_pointer_cast(values_.data()),
values.size() * sizeof(ValueType), cudaMemcpyDeviceToHost));
std::unordered_map<KeyType, ValueType, Hash> ans;
for (int i = 0; i < keys.size(); i++) {
Expand Down
2 changes: 1 addition & 1 deletion src/python/cupoch_pybind/device_vector_wrapper.cu
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ void device_vector_wrapper<Type>::push_back(const Type& x) {
template <typename Type>
utility::pinned_host_vector<Type> device_vector_wrapper<Type>::cpu() const {
utility::pinned_host_vector<Type> ans(data_.size());
cudaSafeCall(cudaMemcpy(ans.data(), thrust::raw_pointer_cast(data_.data()),
cudaSafeCall(cudaMemcpy(thrust::raw_pointer_cast(ans.data()), thrust::raw_pointer_cast(data_.data()),
sizeof(Type) * data_.size(), cudaMemcpyDeviceToHost));
return ans;
}
Expand Down

0 comments on commit c3466b0

Please sign in to comment.