This repository has been archived by the owner on Dec 22, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #56 from gunrock/master
Merging changes to `dev` branch.
- Loading branch information
Showing
12 changed files
with
313 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
#pragma once | ||
|
||
#include <chrono> | ||
#include <vector> | ||
#include <queue> | ||
|
||
namespace bfs_cpu { | ||
|
||
using namespace std; | ||
using namespace std::chrono; | ||
|
||
template <typename vertex_t> | ||
class prioritize { | ||
public: | ||
bool operator()(pair<vertex_t, vertex_t>& p1, pair<vertex_t, vertex_t>& p2) { | ||
return p1.second > p2.second; | ||
} | ||
}; | ||
|
||
template <typename csr_t, typename vertex_t, typename edge_t> | ||
float run(csr_t& csr, | ||
vertex_t& single_source, | ||
vertex_t* distances, | ||
vertex_t* predecessors) { | ||
thrust::host_vector<edge_t> row_offsets(csr.row_offsets); // Copy data to CPU | ||
thrust::host_vector<vertex_t> column_indices(csr.column_indices); | ||
|
||
for (vertex_t i = 0; i < csr.number_of_rows; i++) | ||
distances[i] = std::numeric_limits<vertex_t>::max(); | ||
|
||
auto t_start = high_resolution_clock::now(); | ||
|
||
distances[single_source] = 0; | ||
|
||
priority_queue<pair<vertex_t, vertex_t>, | ||
std::vector<pair<vertex_t, vertex_t>>, | ||
prioritize<vertex_t>> pq; | ||
|
||
pq.push(make_pair(single_source, 0.0)); | ||
|
||
while (!pq.empty()) { | ||
pair<vertex_t, vertex_t> curr = pq.top(); | ||
pq.pop(); | ||
|
||
vertex_t curr_node = curr.first; | ||
vertex_t curr_dist = curr.second; | ||
|
||
vertex_t start = row_offsets[curr_node]; | ||
vertex_t end = row_offsets[curr_node + 1]; | ||
|
||
for (vertex_t offset = start; offset < end; offset++) { | ||
vertex_t neib = column_indices[offset]; | ||
vertex_t new_dist = curr_dist + 1; | ||
if (new_dist < distances[neib]) { | ||
distances[neib] = new_dist; | ||
pq.push(make_pair(neib, new_dist)); | ||
} | ||
} | ||
} | ||
|
||
auto t_stop = high_resolution_clock::now(); | ||
auto elapsed = duration_cast<microseconds>(t_stop - t_start).count(); | ||
return (float)elapsed / 1000; | ||
} | ||
|
||
template <typename val_t> | ||
int compute_error(thrust::device_vector<val_t> _gpu_result, | ||
thrust::host_vector<val_t> cpu_result) { | ||
thrust::host_vector<val_t> gpu_result(_gpu_result); | ||
|
||
int n_errors = 0; | ||
for (int i = 0; i < cpu_result.size(); i++) { | ||
if (gpu_result[i] != cpu_result[i]) { | ||
n_errors++; | ||
} | ||
} | ||
return n_errors; | ||
} | ||
|
||
} // namespace bfs_cpu |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# begin /* Set the application name. */ | ||
set(APPLICATION_NAME mtx2bin) | ||
# end /* Set the application name. */ | ||
|
||
# begin /* Add CUDA executables */ | ||
add_executable(${APPLICATION_NAME}) | ||
|
||
set(SOURCE_LIST | ||
${APPLICATION_NAME}.cu | ||
) | ||
|
||
target_sources(${APPLICATION_NAME} PRIVATE ${SOURCE_LIST}) | ||
target_link_libraries(${APPLICATION_NAME} PRIVATE essentials) | ||
get_target_property(ESSENTIALS_ARCHITECTURES essentials CUDA_ARCHITECTURES) | ||
set_target_properties(${APPLICATION_NAME} | ||
PROPERTIES | ||
CUDA_ARCHITECTURES ${ESSENTIALS_ARCHITECTURES} | ||
) # XXX: Find a better way to inherit essentials properties. | ||
|
||
message("-- Example Added: ${APPLICATION_NAME}") | ||
# end /* Add CUDA executables */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#include <cstdlib> // EXIT_SUCCESS | ||
|
||
#include <gunrock/applications/application.hxx> | ||
|
||
using namespace gunrock; | ||
using namespace memory; | ||
|
||
void test_mtx2bin(int num_arguments, char** argument_array) { | ||
if (num_arguments != 2) { | ||
std::cerr << "usage: ./bin/mtx2bin <inpath>" << std::endl; | ||
exit(1); | ||
} | ||
|
||
// -- | ||
// Define types | ||
|
||
using vertex_t = int; | ||
using edge_t = int; | ||
using weight_t = float; | ||
|
||
// -- | ||
// IO | ||
|
||
std::string inpath = argument_array[1]; | ||
std::string outpath = inpath + ".csr"; | ||
|
||
io::matrix_market_t<vertex_t, edge_t, weight_t> mm; | ||
|
||
using csr_t = format::csr_t<memory::memory_space_t::device, vertex_t, edge_t, weight_t>; | ||
csr_t csr; | ||
csr.from_coo(mm.load(inpath)); | ||
|
||
std::cout << "csr.number_of_rows = " << csr.number_of_rows << std::endl; | ||
std::cout << "csr.number_of_columns = " << csr.number_of_columns << std::endl; | ||
std::cout << "csr.number_of_nonzeros = " << csr.number_of_nonzeros << std::endl; | ||
std::cout << "writing to = " << outpath << std::endl; | ||
|
||
csr.write_binary(outpath); | ||
} | ||
|
||
int main(int argc, char** argv) { | ||
test_mtx2bin(argc, argv); | ||
return EXIT_SUCCESS; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.