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

Move computeAt logic to separate file/class. #128

Closed
wants to merge 5 commits into from
Closed
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
1 change: 1 addition & 0 deletions caffe2/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,7 @@ if(NOT INTERN_BUILD_MOBILE OR NOT BUILD_CAFFE2_MOBILE)
${TORCH_SRC_DIR}/csrc/autograd/functions/comm.cpp
${TORCH_SRC_DIR}/csrc/cuda/comm.cpp
${TORCH_SRC_DIR}/csrc/jit/codegen/cuda/arith.cpp
${TORCH_SRC_DIR}/csrc/jit/codegen/cuda/compute_at.cpp
${TORCH_SRC_DIR}/csrc/jit/codegen/cuda/dispatch.cpp
${TORCH_SRC_DIR}/csrc/jit/codegen/cuda/expr_evaluator.cpp
${TORCH_SRC_DIR}/csrc/jit/codegen/cuda/fusion.cpp
Expand Down
28 changes: 25 additions & 3 deletions test/cpp/jit/test_gpu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1125,7 +1125,7 @@ void testGPU_FusionAdvancedComputeAt() {
TORCH_CHECK(tv0->getComputeAtView() == tv3);
TORCH_CHECK(tv1->getComputeAtView() == tv4);
TORCH_CHECK(tv2->getComputeAtView() == tv4);
TORCH_CHECK(tv3->getComputeAtView() == tv5);
TORCH_CHECK(tv3->getComputeAtView() == tv6);
TORCH_CHECK(tv4->getComputeAtView() == tv5);
TORCH_CHECK(tv5->getComputeAtView() == tv6);
TORCH_CHECK(!tv6->hasComputeAt());
Expand Down Expand Up @@ -2131,7 +2131,8 @@ void testGPU_FusionRFactorReplay() {

// Replay casp, replay new_domain2 as new_domain
// reordered_new_domain[I0oi{16}, I0oo*I0i{32}, ir1oi{4}rf, R(R1oo*R1i{8})rf]
TensorDomain* casp = TransformReplay::replayCasP(new_domain2, new_domain, 2);
auto replay_casp = TransformReplay::replayCasP(new_domain2, new_domain, 2);
TensorDomain* casp = replay_casp.first;
// new_domain[I0oi{16}, I0oo*I0i{32}, ir1oi{4}rf, R(R1oo*R1i{8})rf]
// casp[I0oi{16}, I0oo*I0i{32}, R1oi{4}]

Expand All @@ -2140,7 +2141,8 @@ void testGPU_FusionRFactorReplay() {
// new_domain[I0oi{16}, I0oo*I0i{32} , ir1oi{4}rf,
// R(R1oo*R1i{8})rf]

TensorDomain* pasc = TransformReplay::replayPasC(new_domain, casp, 2);
auto replay_pasc = TransformReplay::replayPasC(new_domain, casp, 2);
TensorDomain* pasc = replay_pasc.first;
// pasc [I0oi{16}, (I0oo*I0i{32})o, I(Ioo*I0i)i{2}, ir1oi{4}rf,
// R(R1oo*R1i{8})rf]

Expand Down Expand Up @@ -3448,6 +3450,26 @@ void testGPU_FusionBCastReduce() {
!tv2->axis(2)->isBroadcast() && !tv2->axis(2)->isReduction());
}

// Multiple consumer reduction with computeAt
// https://github.com/csarofeen/pytorch/issues/110
void testGPU_FusionReductionMultiConsumer() {
torch::jit::fuser::cuda::CudaKernel prog;
Fusion& fusion = *prog.fusion_;
FusionGuard fg(&fusion);
TensorView* tv0 = makeDummyTensor(2);
fusion.addInput(tv0);
auto tv1 = unaryOp(UnaryOpType::Exp, tv0);
auto tv2 = reductionOp(BinaryOpType::Max, {-1}, new Float(0), tv1);
auto tv3 = reductionOp(BinaryOpType::Min, {-1}, new Float(0), tv1);
auto tv4 = add(tv2, tv3);
fusion.addOutput(tv4);
tv1->computeAt(tv2, -1);

TORCH_CHECK(
(tv1->getComputeAtView() == tv2 || tv1->getComputeAtView() == tv3) &&
tv1->getThisComputeAtAxis() == 2 && tv1->getRelativeComputeAtAxis() == 2);
}

} // namespace jit
} // namespace torch
#endif // #if defined(USE_CUDA)
3 changes: 2 additions & 1 deletion test/cpp/jit/tests.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,8 @@ namespace jit {
_(GPU_FusionNonRedAxisBind) \
_(GPU_FusionBCastInnerDim) \
_(GPU_FusionBCastReduce) \
_(GPU_FusionSplitBCast)
_(GPU_FusionSplitBCast) \
_(GPU_FusionReductionMultiConsumer)
#else
#define TH_FORALL_TESTS_CUDA(_) \
_(ArgumentSpec) \
Expand Down
1 change: 1 addition & 0 deletions tools/build_variables.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,7 @@ libtorch_cuda_sources = [
"torch/csrc/autograd/profiler_cuda.cpp",
"torch/csrc/autograd/functions/comm.cpp",
"torch/csrc/jit/codegen/cuda/arith.cpp",
"torch/csrc/jit/codegen/cuda/compute_at.cpp",
"torch/csrc/jit/codegen/cuda/dispatch.cpp",
"torch/csrc/jit/codegen/cuda/expr_evaluator.cpp",
"torch/csrc/jit/codegen/cuda/fusion.cpp",
Expand Down
Loading