Skip to content

Commit

Permalink
Get rid of printf in cuda fuser debugPrint() (pytorch#46994)
Browse files Browse the repository at this point in the history
Summary: Pull Request resolved: pytorch#46994

Reviewed By: raghuramank100, mruberry

Differential Revision: D25342954

Pulled By: malfet

fbshipit-source-id: 549b5b072f7f70877261a155e989a21072ec49d8
  • Loading branch information
malfet authored and facebook-github-bot committed Dec 4, 2020
1 parent ca3ae7d commit b9cd774
Showing 1 changed file with 27 additions and 30 deletions.
57 changes: 27 additions & 30 deletions torch/csrc/jit/codegen/cuda/kernel_cache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,52 +40,49 @@ std::vector<size_t> toVector(const at::DimVector& small_vec) {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunused-function"
void debugPrint(const TensorTypePtr& type) {
printf("\nsizes:");
std::stringstream sizes_s;
if (auto sizes = type->symbolic_sizes().sizes()) {
// for (const auto& shape_symbol : sizes.value()) {
int rank = static_cast<int>(sizes->size());
for (int i = 0; i < rank; i++) {
const auto& shape_symbol = sizes.value()[i];
for (const auto& shape_symbol : *sizes) {
if (shape_symbol.is_static()) {
printf("%ld, ", shape_symbol.static_size());
sizes_s << shape_symbol.static_size() << ", ";
} else {
printf("s(%ld), ", *reinterpret_cast<const int64_t*>(&shape_symbol));
sizes_s << "s(" << *reinterpret_cast<const int64_t*>(&shape_symbol)
<< "), ";
}
}
} else {
printf("no size available\n");
sizes_s << "no size available";
}
std::cout << "sizes:" << sizes_s.str() << std::endl;
if (const auto& stride_properties = type->stride_properties().sizes()) {
int rank = static_cast<int>(stride_properties->size());
printf("\nstride: ");
for (int i = 0; i < rank; i++) {
if ((*stride_properties)[i].has_value() &&
(*stride_properties)[i]->stride_.has_value()) {
printf("%ld, ", (*stride_properties)[i]->stride_.value());
std::stringstream stride_s;
std::stringstream index_s;
std::stringstream contig_s;

for (const auto& stride_property : *stride_properties) {
if (stride_property.has_value() && stride_property->stride_.has_value()) {
stride_s << *stride_property->stride_ << ", ";
} else {
printf("?, ");
stride_s << "?, ";
}
}
printf("\nstride index: ");
for (int i = 0; i < rank; i++) {
if ((*stride_properties)[i].has_value() &&
(*stride_properties)[i]->stride_index_.has_value()) {
printf("%ld, ", (*stride_properties)[i]->stride_index_.value());
if (stride_property.has_value() &&
stride_property->stride_index_.has_value()) {
index_s << *stride_property->stride_index_ << ", ";
} else {
printf("?, ");
index_s << "?, ";
}
}
printf("\ncontiguous: ");
for (int i = 0; i < rank; i++) {
if ((*stride_properties)[i].has_value() &&
(*stride_properties)[i]->contiguous_.has_value()) {
printf("%d, ", (*stride_properties)[i]->contiguous_.value());
if (stride_property.has_value() &&
stride_property->contiguous_.has_value()) {
contig_s << *stride_property->contiguous_ << ", ";
} else {
printf("?, ");
contig_s << "?, ";
}
}
std::cout << "stride: " << stride_s.str() << std::endl;
std::cout << "stride index: " << index_s.str() << std::endl;
std::cout << "contiguous: " << contig_s.str() << std::endl;
} else {
printf("no stride properties available\n");
std::cout << "no stride properties available" << std::endl;
}
}
#pragma clang diagnostic pop
Expand Down

0 comments on commit b9cd774

Please sign in to comment.