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

[GraphBolt][CUDA] Compute capability check refactor. #7485

Merged
merged 2 commits into from
Jun 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
17 changes: 1 addition & 16 deletions graphbolt/src/cuda/unique_and_compact_impl.cu
Original file line number Diff line number Diff line change
Expand Up @@ -277,22 +277,7 @@ UniqueAndCompactBatched(
const std::vector<torch::Tensor>& src_ids,
const std::vector<torch::Tensor>& dst_ids,
const std::vector<torch::Tensor>& unique_dst_ids, int num_bits) {
auto dev_id = cuda::GetCurrentStream().device_index();
static std::mutex mtx;
static std::unordered_map<decltype(dev_id), int> compute_capability_cache;
const auto compute_capability_major = [&] {
std::lock_guard lock(mtx);
auto it = compute_capability_cache.find(dev_id);
if (it != compute_capability_cache.end()) {
return it->second;
} else {
int major;
CUDA_RUNTIME_CHECK(cudaDeviceGetAttribute(
&major, cudaDevAttrComputeCapabilityMajor, dev_id));
return compute_capability_cache[dev_id] = major;
}
}();
if (compute_capability_major >= 7) {
if (cuda::compute_capability() >= 70) {
// Utilizes a hash table based implementation, the mapped id of a vertex
// will be monotonically increasing as the first occurrence index of it in
// torch.cat([unique_dst_ids, src_ids]). Thus, it is deterministic.
Expand Down
10 changes: 10 additions & 0 deletions graphbolt/src/cuda/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,16 @@ constexpr int CUDA_MAX_NUM_THREADS = 1024;
namespace graphbolt {
namespace cuda {

/**
* @brief Returns the compute capability of the cuda device, e.g. 70 for Volta.
*/
inline int compute_capability(
int device = cuda::GetCurrentStream().device_index()) {
int sm_version;
CUDA_RUNTIME_CHECK(cub::SmVersion(sm_version, device));
return sm_version / 10;
};

/**
* @brief Calculate the number of threads needed given the size of the dimension
* to be processed.
Expand Down
Loading