Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[REVIEW] Code review for initial check-in #7

Merged
merged 115 commits into from
Sep 4, 2019
Merged
Changes from 3 commits
Commits
Show all changes
115 commits
Select commit Hold shift + click to select a range
1b716b1
init check-in (cpp/python)
zhangjianting Aug 14, 2019
ebe73bc
for code review
zhangjianting Aug 22, 2019
3c3295e
add paths for custring libs
zhangjianting Aug 23, 2019
1b49472
update on documentating python test/demo code
zhangjianting Aug 23, 2019
ae6fe28
Update README.md
zhangjianting Aug 23, 2019
378de35
Update README.md
zhangjianting Aug 23, 2019
675d719
Update README.md
zhangjianting Aug 23, 2019
6563b38
Update README.md
zhangjianting Aug 23, 2019
9d42ab2
Update README.md
zhangjianting Aug 23, 2019
9d5c761
Update cpp/include/cuspatial/hausdorff.hpp
zhangjianting Aug 23, 2019
73a2f05
Update cpp/include/cuspatial/hausdorff.hpp
zhangjianting Aug 23, 2019
5f97192
Update cpp/include/cuspatial/hausdorff.hpp
zhangjianting Aug 23, 2019
0eb5670
Update README.md
zhangjianting Aug 23, 2019
1c187a8
Update cpp/include/cuspatial/hausdorff.hpp
zhangjianting Aug 23, 2019
1022c8d
Update cpp/include/cuspatial/hausdorff.hpp
zhangjianting Aug 23, 2019
f0fc3a8
Update README.md
zhangjianting Aug 23, 2019
d9e7fca
Update README.md
zhangjianting Aug 23, 2019
4a67a78
Update README.md
zhangjianting Aug 23, 2019
1dc84b1
Update README.md
zhangjianting Aug 23, 2019
79b5b1f
Update README.md
zhangjianting Aug 23, 2019
cf6b51a
Update README.md
zhangjianting Aug 23, 2019
db4d6fc
Update README.md
zhangjianting Aug 23, 2019
afac815
Update README.md
zhangjianting Aug 23, 2019
111149c
Update cpp/include/cuspatial/coord_trans.hpp
zhangjianting Aug 23, 2019
0d5fd7d
Update cpp/include/cuspatial/coord_trans.hpp
zhangjianting Aug 23, 2019
6f3b2e2
Update cpp/include/cuspatial/coord_trans.hpp
zhangjianting Aug 23, 2019
67f3356
Update cpp/include/cuspatial/coord_trans.hpp
zhangjianting Aug 23, 2019
227d187
Update cpp/include/cuspatial/coord_trans.hpp
zhangjianting Aug 23, 2019
4d73d59
Update cpp/include/cuspatial/coord_trans.hpp
zhangjianting Aug 23, 2019
8dd7f5f
Update cpp/include/cuspatial/coord_trans.hpp
zhangjianting Aug 23, 2019
4bf2c66
Update cpp/include/cuspatial/coord_trans.hpp
zhangjianting Aug 23, 2019
fed0b48
Update cpp/include/cuspatial/coord_trans.hpp
zhangjianting Aug 23, 2019
f150a05
Update cpp/include/cuspatial/coord_trans.hpp
zhangjianting Aug 23, 2019
81cc626
Update cpp/include/cuspatial/cuspatial.h
zhangjianting Aug 23, 2019
c70cc57
Update cpp/include/cuspatial/cuspatial.h
zhangjianting Aug 23, 2019
05a3f9a
Update cpp/include/cuspatial/cuspatial.h
zhangjianting Aug 23, 2019
fc86a09
Update cpp/include/cuspatial/cuspatial.h
zhangjianting Aug 23, 2019
0e12651
Update cpp/include/cuspatial/cuspatial.h
zhangjianting Aug 23, 2019
0acd63a
Update cpp/include/cuspatial/cuspatial.h
zhangjianting Aug 23, 2019
ca85b2a
formatting
zhangjianting Aug 24, 2019
b3018bd
2nd round revision for code review
zhangjianting Aug 24, 2019
f1e4788
Update cpp/include/cuspatial/haversine.hpp
zhangjianting Aug 28, 2019
645479f
for 3rd round code review
zhangjianting Aug 28, 2019
3b5e989
Merge branch 'fea-initial-code' of github.com:zhangjianting/cuspatial…
zhangjianting Aug 28, 2019
b48b61c
Update cpp/include/cuspatial/trajectory.hpp
zhangjianting Aug 28, 2019
80faf5a
for 3rd round code review
zhangjianting Aug 28, 2019
645e606
Merge branch 'fea-initial-code' of github.com:zhangjianting/cuspatial…
zhangjianting Aug 28, 2019
28ac08a
Update cpp/include/cuspatial/soa_readers.hpp
zhangjianting Aug 28, 2019
1a880f9
for 3rd code review
zhangjianting Aug 28, 2019
0722277
Merge branch 'fea-initial-code' of github.com:zhangjianting/cuspatial…
zhangjianting Aug 28, 2019
b194258
Update cpp/include/cuspatial/soa_readers.hpp
zhangjianting Aug 28, 2019
ff18076
Add .gitignore
harrism Aug 28, 2019
9838cb3
Update version no. and make finding cudf more flexible
harrism Aug 28, 2019
8296a83
Merge branch 'fea-initial-code' of github.com:zhangjianting/cuspatial…
harrism Aug 28, 2019
02551e9
for 3rd round code review: making location3d and coord_2d templated
zhangjianting Aug 28, 2019
34cd979
Merge branch 'fea-initial-code' of github.com:zhangjianting/cuspatial…
zhangjianting Aug 28, 2019
5bd8913
Update cpp/include/cuspatial/soa_readers.hpp
zhangjianting Aug 28, 2019
e2b2de3
Update cpp/include/cuspatial/trajectory.hpp
zhangjianting Aug 28, 2019
ed23bfa
for 3rd round code review
zhangjianting Aug 28, 2019
20cc9b1
Merge branch 'fea-initial-code' of github.com:zhangjianting/cuspatial…
zhangjianting Aug 28, 2019
4b966bd
for 3rd round code review (continued)
zhangjianting Aug 29, 2019
71fcf3e
for 3rd round code review (amendment)
zhangjianting Aug 29, 2019
9809b9c
Update .gitignore cudf->cuspatial
harrism Aug 29, 2019
8646847
Fix URL in setup.py
harrism Aug 29, 2019
f625d93
for 3rd code review (amendment)
zhangjianting Aug 29, 2019
f1b7e2b
Merge branch 'fea-initial-code' of github.com:zhangjianting/cuspatial…
zhangjianting Aug 29, 2019
6da406a
adding typename
zhangjianting Aug 29, 2019
82d4ff4
Clean up and fix Cython bindings and trajectory APIs
harrism Aug 30, 2019
5982544
Merge branch 'fea-initial-code' of github.com:zhangjianting/cuspatial…
harrism Aug 30, 2019
4b729d9
Rename traj.p** to trajectory.p**
harrism Aug 30, 2019
2b7b8ed
Test cleanup and disabling failing tests for now.
harrism Aug 30, 2019
cdc4039
coord_to_traj --> derive_trajectories, plus cleanup
harrism Aug 30, 2019
2bd6371
Clean up README.md
harrism Aug 30, 2019
4f9c9ee
Clean up data README.md
harrism Aug 30, 2019
ce36d37
simplify pip_test for test on GPU only; add pip_compare to compare CP…
zhangjianting Aug 31, 2019
9b256bd
uint-->uint32_t;adding hausdorff_toy test; grouping tests
zhangjianting Aug 31, 2019
7b7bfb6
add hausdorff_compare test
zhangjianting Aug 31, 2019
d1c9db6
pip_test: comparing two rounds GPU results
zhangjianting Aug 31, 2019
a03f82a
Add haversine_toy test; remove uncessary header files
zhangjianting Sep 1, 2019
c71fc5b
remove unused code; remove __host__
zhangjianting Sep 1, 2019
2039056
Fix pip_test crash.
harrism Sep 2, 2019
c1cce54
Readme markdown fixes.
harrism Sep 2, 2019
9c395be
Merge branch 'fea-initial-code' of github.com:zhangjianting/cuspatial…
harrism Sep 2, 2019
a96d5b7
Fix merge error.
harrism Sep 2, 2019
13cbd63
cuspatial.h renamed to cuspatial/types.hpp
harrism Sep 2, 2019
2fc09b3
Header style and documentation cleanup
harrism Sep 2, 2019
02e4e0d
Point in polygon API cleanup
harrism Sep 2, 2019
99d894f
Reorganize / rename utilities
harrism Sep 2, 2019
cbf84fb
pip.hpp --> point_in_polygon.hpp
harrism Sep 2, 2019
fd7740b
Refactor query naming; cleanup
harrism Sep 2, 2019
c71c65c
More pip renaming
harrism Sep 2, 2019
99d5385
add subset_trajectory and its test on toy data
zhangjianting Sep 2, 2019
c489053
add two toy tests for derive_trajectories and trajectory_distance_and…
zhangjianting Sep 2, 2019
6058cbe
Eliminate global `using namespace ...` declarations.
harrism Sep 3, 2019
a8cc7ad
Merge branch 'fea-initial-code' of github.com:zhangjianting/cuspatial…
harrism Sep 3, 2019
e46e4c0
add three test (spaital_window, coordinate_transform, trajectory_spat…
zhangjianting Sep 3, 2019
dad03ce
trajectory cleanup
harrism Sep 3, 2019
c5724bf
Merge branch 'fea-initial-code' of github.com:zhangjianting/cuspatial…
harrism Sep 3, 2019
0a8c1f0
Fix forward declarations.
harrism Sep 3, 2019
63165f3
Remove more global using namespace decls
harrism Sep 3, 2019
3f5a931
Clean up polygon_soa_reader
harrism Sep 3, 2019
a137faf
clean-up: indentation, simplification
zhangjianting Sep 3, 2019
69cf890
code clean-up: indentation, using T* instead of thrust::device_ptr an…
zhangjianting Sep 3, 2019
7a3c36f
code clean-up: indentation, using T* instead of thrust::device_ptr an…
zhangjianting Sep 3, 2019
afc19b0
code clean-up: use anonymous namespace, remove output and timing code
zhangjianting Sep 3, 2019
d52a80b
code clean-up: use anonymous namespace, remove output and timing code
zhangjianting Sep 3, 2019
2e155bd
code clean-up: remove output, using anonymous namespace etc.
zhangjianting Sep 3, 2019
d20d7df
Remove C-style casts.
harrism Sep 3, 2019
452c56f
Merge branch 'fea-initial-code' of github.com:zhangjianting/cuspatial…
harrism Sep 3, 2019
ed953e9
code clean-up: remove debug output and timing code, using anonymous n…
zhangjianting Sep 3, 2019
c6608a1
Merge branch 'fea-initial-code' of https://github.com/zhangjianting/c…
zhangjianting Sep 3, 2019
60999ce
replace count_if with count
harrism Sep 4, 2019
7b472a0
Safely copy gdf_scalar values.
harrism Sep 4, 2019
4624e57
Changelog for PR #7
harrism Sep 4, 2019
07e68b9
Clearer window parameters for spatial_window_points
harrism Sep 4, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -270,6 +270,7 @@ add_library(cuspatial SHARED
src/trajectory/trajectory_spatial_bound.cu
src/trajectory/trajectory_distance_speed.cu
src/trajectory/derive_trajectories.cu
src/trajectory/subset_trajectories.cu
src/utility/utility.cpp)

#Override RPATH for cuspatial
31 changes: 27 additions & 4 deletions cpp/include/cuspatial/trajectory.hpp
Original file line number Diff line number Diff line change
@@ -22,20 +22,20 @@ namespace cuspatial {

/**
* @brief derive trajectories from points, timestamps and object ids
*
*
* Points are x/y coordinates relative to an origin. First sorts by object id
* and timestamp and then groups by id.
*
*
* @param[in/out] x: x coordinates relative to a camera origin
* (before/after sorting)
* @param[in/out] y: y coordinates relative to a camera origin
* (before/after sorting)
* @param[in/out] object_id: object (e.g., vehicle) id column (before/after
* @param[in/out] object_id: object (e.g., vehicle) id column (before/after
* sorting); upon completion, unique ids become trajectory ids
* @param[in/out] timestamp: timestamp column (before/after sorting)
* @param[out] trajectory_id: trajectory id column (see comments on oid)
* @param[out] length: #of points in the derived trajectories
* @param[out] offset: position offsets of trajectories used to index x, y,
* @param[out] offset: position offsets of trajectories used to index x, y,
* object_id and timestamp
* @return number of derived trajectories
*/
@@ -86,4 +86,27 @@ void trajectory_spatial_bounds(const gdf_column& x, const gdf_column& y,
gdf_column& bbox_x1, gdf_column& bbox_y1,
gdf_column& bbox_x2, gdf_column& bbox_y2);

/**
* @brief subset a set of trajectories based on provided trajectory IDs

* @param[in] ids: ids of trajectories whose x/y/len/pos data will be kept
* @param[in] in_x: input x coordinates
* @param[in] in_y: input y coordinates
* @param[in] in_id: input ids of points
* @param[in] in_ts: input timestamps of points
* @param[out] out_x: output x coordinates ordered by (in_id,in_ts)
* @param[out] out_y: output y coordinates ordered by (in_id,in_ts)
* @param[out] out_id: output ids ordered by (in_id,in_ts)
* @param[out] out_ts: output timestamp ordered by (in_id,in_ts)

* Note: the API is useful for integraitng with cudf and serial python APIs,
* e.g., query based on trajectory level informaiton using serial python APIs or cudf APIs
* and identify a subset of trajectory IDs.
* These IDs can then be used to reterive x/y/len/pos data for futher processing.
*/

uint32_t subset_trajectory_id(const gdf_column& ids,
const gdf_column& in_x, const gdf_column& in_y, const gdf_column& in_id, const gdf_column& in_ts,
gdf_column& out_x, gdf_column& out_y,gdf_column& out_id, gdf_column& out_ts);

} // namespace cuspatial
57 changes: 33 additions & 24 deletions cpp/src/trajectory/derive_trajectories.cu
Original file line number Diff line number Diff line change
@@ -17,8 +17,6 @@
#include <cudf/utilities/legacy/type_dispatcher.hpp>
#include <utilities/cuda_utils.hpp>
#include <type_traits>
#include <thrust/device_vector.h>
#include <thrust/iterator/discard_iterator.h>
#include <sys/time.h>
#include <time.h>

@@ -38,22 +36,30 @@ struct derive_trajectories_functor {
gdf_column& timestamp, gdf_column& trajectory_id,
gdf_column& length, gdf_column& offset)
{
T* x_ptr = static_cast<T*>(x.data);
T* y_ptr = static_cast<T*>(y.data);
uint32_t* id_ptr = static_cast<uint32_t*>(object_id.data);
cuspatial::its_timestamp * time_ptr =
static_cast<cuspatial::its_timestamp*>(timestamp.data);

//T* x_ptr = static_cast<T*>(x.data);
thrust::device_ptr<T> x_ptr =
thrust::device_pointer_cast(static_cast<T*>(x.data));
//T* y_ptr = static_cast<T*>(y.data);
thrust::device_ptr<T> y_ptr =
thrust::device_pointer_cast(static_cast<T*>(y.data));
//uint32_t* id_ptr = static_cast<uint32_t*>(object_id.data);
thrust::device_ptr<uint32_t> id_ptr =
thrust::device_pointer_cast(static_cast<uint32_t*>(object_id.data));
//its_timestamp * time_ptr = static_cast<its_timestamp*>(timestamp.data);
thrust::device_ptr<cuspatial::its_timestamp> time_ptr =
thrust::device_pointer_cast(
static_cast<cuspatial::its_timestamp *>(timestamp.data));

#ifdef DEBUG
int num_print = (object_id.size < 10) ? object_id.size : 10;
std::cout<<"showing the first "<< num_print<<" input records before sort"<<std::endl;

std::cout<<"x"<<std::endl;
thrust::copy(x_ptr,x_ptr+num_print,std::ostream_iterator<col_type>(std::cout, " "));std::cout<<std::endl;
thrust::copy(x_ptr,x_ptr+num_print,std::ostream_iterator<T>(std::cout, " "));std::cout<<std::endl;
std::cout<<"y"<<std::endl;
thrust::copy(y_ptr,y_ptr+num_print,std::ostream_iterator<col_type>(std::cout, " "));std::cout<<std::endl;
thrust::copy(y_ptr,y_ptr+num_print,std::ostream_iterator<T>(std::cout, " "));std::cout<<std::endl;

std::cout<<"oid"<<std::endl;
std::cout<<"object id"<<std::endl;
thrust::copy(id_ptr,id_ptr+num_print,std::ostream_iterator<uint32_t>(std::cout, " "));std::cout<<std::endl;
std::cout<<"timestamp"<<std::endl;
thrust::copy(time_ptr,time_ptr+num_print,std::ostream_iterator<its_timestamp>(std::cout, " "));std::cout<<std::endl;
@@ -69,37 +75,41 @@ struct derive_trajectories_functor {
thrust::make_zip_iterator(thrust::make_tuple(time_ptr, x_ptr, y_ptr)));

//allocate sufficient memory to hold id,cnt and pos before reduce_by_key
uint32_t *objcnt = nullptr, *objpos = nullptr, *objid = nullptr;
uint32_t *objcnt{nullptr};
uint32_t *objid{nullptr};
RMM_TRY( RMM_ALLOC((void**)&objcnt,num_rec* sizeof(uint32_t),0) ) ;
RMM_TRY( RMM_ALLOC((void**)&objpos,num_rec* sizeof(uint32_t),0) ) ;
RMM_TRY( RMM_ALLOC((void**)&objid,num_rec* sizeof(uint32_t),0) ) ;
thrust::device_ptr<uint32_t> objcnt_ptr=thrust::device_pointer_cast(objcnt);
thrust::device_ptr<uint32_t> objid_ptr=thrust::device_pointer_cast(objid);

int num_traj =
thrust::reduce_by_key(thrust::device, id_ptr, id_ptr+num_rec,
thrust::constant_iterator<int>(1),
objid, objcnt).second - objcnt;
objid_ptr, objcnt_ptr).second - objcnt_ptr;


//allocate just enough memory (num_traj), copy over and then free large (num_rec) arrays
uint32_t *trajid=nullptr,*trajcnt=nullptr,*trajpos=nullptr;
uint32_t *trajid{nullptr};
uint32_t *trajcnt{nullptr};
uint32_t *trajpos{nullptr};
RMM_TRY( RMM_ALLOC((void**)&trajid, num_traj * sizeof(uint32_t),0) ) ;
RMM_TRY( RMM_ALLOC((void**)&trajcnt, num_traj * sizeof(uint32_t),0) ) ;
RMM_TRY( RMM_ALLOC((void**)&trajpos, num_traj * sizeof(uint32_t),0) ) ;

thrust::device_ptr<uint32_t> trajid_ptr=thrust::device_pointer_cast(trajid);
thrust::device_ptr<uint32_t> trajcnt_ptr=thrust::device_pointer_cast(trajcnt);
thrust::device_ptr<uint32_t> trajpos_ptr=thrust::device_pointer_cast(trajpos);

thrust::copy(objid, objid + num_traj, trajid);
thrust::copy(objcnt, objcnt + num_traj, trajcnt);
thrust::copy(objpos, objpos + num_traj, trajpos);
thrust::copy(objid_ptr, objid_ptr + num_traj, trajid_ptr);
thrust::copy(objcnt_ptr, objcnt_ptr + num_traj, trajcnt_ptr);
thrust::inclusive_scan(trajcnt_ptr, trajcnt_ptr + num_traj, trajpos_ptr);

RMM_TRY( RMM_FREE(objid, 0) );
RMM_TRY( RMM_FREE(objcnt, 0) );
RMM_TRY( RMM_FREE(objpos, 0) );


//to avoid lost memory problem when tid/cnt/pos gdf columns are associated with dvice memory
gdf_column_view(&trajectory_id, trajid, nullptr, num_traj, GDF_INT32);
gdf_column_view(&length, trajcnt, nullptr, num_traj, GDF_INT32);
thrust::inclusive_scan(thrust::device, trajcnt_ptr, trajcnt_ptr+num_traj, trajpos_ptr);
gdf_column_view(&offset, trajpos, nullptr, num_traj, GDF_INT32);

gettimeofday(&t1, nullptr);
@@ -110,9 +120,9 @@ struct derive_trajectories_functor {
std::cout<<"#traj="<<num_traj<<std::endl;
std::cout<<"showing the first "<< num_print<<" records aftr sort"<<std::endl;
std::cout<<"x"<<std::endl;
thrust::copy(x_ptr,x_ptr+num_print,std::ostream_iterator<col_type>(std::cout, " "));std::cout<<std::endl;
thrust::copy(x_ptr,x_ptr+num_print,std::ostream_iterator<T>(std::cout, " "));std::cout<<std::endl;
std::cout<<"y"<<std::endl;
thrust::copy(y_ptr,y_ptr+num_print,std::ostream_iterator<col_type>(std::cout, " "));std::cout<<std::endl;
thrust::copy(y_ptr,y_ptr+num_print,std::ostream_iterator<T>(std::cout, " "));std::cout<<std::endl;

std::cout<<"oid"<<std::endl;
thrust::copy(id_ptr,id_ptr+num_print,std::ostream_iterator<uint32_t>(std::cout, " "));std::cout<<std::endl;
@@ -122,7 +132,6 @@ struct derive_trajectories_functor {
num_print=(num_traj<10)?num_traj:10;
std::cout<<"showing the first "<< num_print<<" trajectory records"<<std::endl;
std::cout<<"trajectory id"<<std::endl;
thrust::device_ptr<uint32_t> trajid_ptr=thrust::device_pointer_cast(trajid);
thrust::copy(trajid_ptr,trajid_ptr+num_print,std::ostream_iterator<uint32_t>(std::cout, " "));std::cout<<std::endl;
std::cout<<"trajectory #of points"<<std::endl;
thrust::copy(trajcnt_ptr,trajcnt_ptr+num_print,std::ostream_iterator<uint32_t>(std::cout, " "));std::cout<<std::endl;
164 changes: 164 additions & 0 deletions cpp/src/trajectory/subset_trajectories.cu
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
/*
* Copyright (c) 2019, NVIDIA CORPORATION.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include <cudf/utilities/legacy/type_dispatcher.hpp>
#include <utilities/cuda_utils.hpp>
#include <type_traits>
#include <thrust/device_vector.h>
#include <thrust/binary_search.h>
#include <thrust/iterator/discard_iterator.h>
#include <sys/time.h>
#include <time.h>

#include <utility/utility.hpp>
#include <utility/trajectory_thrust.cuh>
#include <cuspatial/trajectory.hpp>

using namespace std;
using namespace cudf;
using namespace cuspatial;

struct is_true
{
__device__
bool operator()(const bool t)
{
return(t);
}
};

struct subset_functor {
template <typename T>
static constexpr bool is_supported()
{
return std::is_floating_point<T>::value;
}

template <typename T, std::enable_if_t< is_supported<T>() >* = nullptr>
uint32_t operator()(const gdf_column& ids,
const gdf_column& in_x,const gdf_column& in_y, const gdf_column& in_id,const gdf_column& in_ts,
gdf_column& out_x, gdf_column& out_y, gdf_column& out_id,gdf_column& out_ts)
{

//struct timeval t0,t1;
//gettimeofday(&t0, nullptr);

thrust::device_ptr<T> in_x_ptr = thrust::device_pointer_cast(static_cast<T*>(in_x.data));
thrust::device_ptr<T> in_y_ptr = thrust::device_pointer_cast(static_cast<T*>(in_y.data));
thrust::device_ptr<uint32_t> in_id_ptr =thrust::device_pointer_cast(static_cast<uint32_t*>(in_id.data));
thrust::device_ptr<its_timestamp> in_ts_ptr = thrust::device_pointer_cast(static_cast<its_timestamp*>(in_ts.data));

#ifdef DEBUG
int num_print = (in_id.size < 10) ? in_id.size : 10;
std::cout<<"showing the first "<< num_print<<" input records before sort"<<std::endl;

std::cout<<"input x"<<std::endl;
thrust::copy(in_x_ptr,in_x_ptr+num_print,std::ostream_iterator<T>(std::cout, " "));std::cout<<std::endl;
std::cout<<"input y"<<std::endl;
thrust::copy(in_y_ptr,in_y_ptr+num_print,std::ostream_iterator<T>(std::cout, " "));std::cout<<std::endl;

std::cout<<"input id"<<std::endl;
thrust::copy(in_id_ptr,in_id_ptr+num_print,std::ostream_iterator<uint32_t>(std::cout, " "));std::cout<<std::endl;
std::cout<<"input timestamp"<<std::endl;
thrust::copy(in_ts_ptr,in_ts_ptr+num_print,std::ostream_iterator<its_timestamp>(std::cout, " "));std::cout<<std::endl;
#endif

uint32_t num_id=ids.size;
uint32_t num_rec=in_id.size;

uint32_t *temp_id{nullptr};
RMM_TRY( RMM_ALLOC((void**)&temp_id,num_id* sizeof(uint32_t),0) ) ;
thrust::device_ptr<uint32_t> temp_id_ptr=thrust::device_pointer_cast(temp_id);

thrust::device_ptr<uint32_t> ids_ptr=thrust::device_pointer_cast(static_cast<uint32_t*>(ids.data));
thrust::copy(ids_ptr, ids_ptr+num_id,temp_id_ptr);
thrust::sort(temp_id_ptr,temp_id_ptr+num_id);
thrust::copy(temp_id_ptr,temp_id_ptr+num_id,std::ostream_iterator<uint32_t>(std::cout, " "));std::cout<<std::endl;

thrust::device_vector<bool> hit_vec(num_rec);
std::cout<<"beginning binary_search .............."<<std::endl;
thrust::binary_search(temp_id_ptr, temp_id_ptr+num_id,in_id_ptr,in_id_ptr+num_rec,hit_vec.begin());
std::cout<<"binary_search results.............."<<std::endl;
thrust::copy(hit_vec.begin(),hit_vec.end(),std::ostream_iterator<uint32_t>(std::cout, " "));std::cout<<std::endl;
thrust::device_vector<bool> temp_vec=hit_vec;
thrust::copy(temp_vec.begin(),temp_vec.end(),std::ostream_iterator<uint32_t>(std::cout, " "));std::cout<<std::endl;

uint32_t num_hit=thrust::count_if(temp_vec.begin(),temp_vec.end(),is_true());
std::cout<<"num_hit="<<num_hit<<std::endl;

RMM_TRY( RMM_ALLOC((void**)(&(out_x.data)),num_hit* sizeof(double),0) ) ;
RMM_TRY( RMM_ALLOC((void**)(&(out_y.data)),num_hit* sizeof(double),0) ) ;
RMM_TRY( RMM_ALLOC((void**)(&(out_id.data)),num_hit* sizeof(uint32_t),0) ) ;
RMM_TRY( RMM_ALLOC((void**)(&(out_ts.data)),num_hit* sizeof(its_timestamp),0) ) ;

thrust::device_ptr<T> out_x_ptr = thrust::device_pointer_cast(static_cast<T*>(out_x.data));
thrust::device_ptr<T> out_y_ptr = thrust::device_pointer_cast(static_cast<T*>(out_y.data));
thrust::device_ptr<uint32_t> out_id_ptr =thrust::device_pointer_cast(static_cast<uint32_t*>(out_id.data));
thrust::device_ptr<its_timestamp> out_ts_ptr = thrust::device_pointer_cast(static_cast<its_timestamp*>(out_ts.data));

auto in_itr=thrust::make_zip_iterator(thrust::make_tuple(in_x_ptr, in_y_ptr, in_id_ptr,in_ts_ptr));
auto out_itr=thrust::make_zip_iterator(thrust::make_tuple(out_x_ptr, out_y_ptr, out_id_ptr,out_ts_ptr));
uint32_t num_keep=thrust::copy_if(in_itr,in_itr+num_rec,hit_vec.begin(),out_itr,is_true())-out_itr;
CUDF_EXPECTS(num_hit==num_keep,"expecting count_if and copy_if return the same size");

return(num_hit);
}

template <typename col_type, std::enable_if_t< !is_supported<col_type>() >* = nullptr>
uint32_t operator()(const gdf_column& ids,
const gdf_column& in_x,const gdf_column& in_y, const gdf_column& in_id,const gdf_column& in_ts,
gdf_column& out_x,gdf_column& out_y, gdf_column& out_id,gdf_column& out_ts)
{
CUDF_FAIL("Non-floating point operation is not supported");
}
};


namespace cuspatial {

/*

*/
uint32_t subset_trajectory_id(const gdf_column& ids,
const gdf_column& in_x, const gdf_column& in_y, const gdf_column& in_id, const gdf_column& in_ts,
gdf_column& out_x, gdf_column& out_y,gdf_column& out_id, gdf_column& out_ts)
{
struct timeval t0,t1;
gettimeofday(&t0, nullptr);

CUDF_EXPECTS(in_x.data != nullptr && in_x.data != nullptr &&
in_id.data != nullptr && in_ts.data != nullptr,
"x/y/in_id/in_ts data cannot be null");
CUDF_EXPECTS(in_x.size == in_y.size && in_x.size == in_id.size &&
in_x.size == in_ts.size ,
"x/y/in_id/timestamp must have equal size");

// future versions might allow x/y/in_id/timestamp to have null_count > 0,
// which might be useful for taking query results as inputs
CUDF_EXPECTS(in_x.null_count == 0 && in_y.null_count == 0 &&
in_id.null_count==0 && in_ts.null_count==0,
"NULL support unimplemented");

uint32_t num_hit=cudf::type_dispatcher(in_x.dtype, subset_functor(),ids,
in_x, in_y, in_id, in_ts,
out_x, out_y,out_id,out_ts);
std::cout<<"number of resulting points:"<<num_hit<<std::endl;
gettimeofday(&t1, nullptr);
float subset_end2end_time=calc_time("trajectory subset end-to-end time in ms=",t0,t1);
return num_hit;
}

}// namespace cuspatial
Loading
Oops, something went wrong.