Skip to content

Commit

Permalink
Clone printf and fprintf calls (#1147)
Browse files Browse the repository at this point in the history
* Clone printf and fprintf calls

* Add FIXME and print loop index
  • Loading branch information
kchristin22 authored Nov 22, 2024
1 parent 284c33e commit b5e0d12
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/Differentiator/ReverseModeVisitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1459,6 +1459,10 @@ Expr* getArraySizeExpr(const ArrayType* AT, ASTContext& context,
return StmtDiff(Clone(CE));
}

// FIXME: Revisit this when variadic functions are supported.
if (FD->getNameAsString() == "printf" || FD->getNameAsString() == "fprintf")
return StmtDiff(Clone(CE));

Expr* CUDAExecConfig = nullptr;
if (const auto* KCE = dyn_cast<CUDAKernelCallExpr>(CE))
CUDAExecConfig = Clone(KCE->getConfig());
Expand Down
2 changes: 2 additions & 0 deletions test/CUDA/GradientKernels.cu
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,7 @@ double fn_memory(double *out, double *in) {
cudaMemcpy(out_host, out, 10 * sizeof(double), cudaMemcpyDeviceToHost);
double res = 0;
for (int i=0; i < 10; ++i) {
printf("Writing result of out[%d]\n", i);
res += out_host[i];
}
free(out_host);
Expand Down Expand Up @@ -469,6 +470,7 @@ double fn_memory(double *out, double *in) {
//CHECK-NEXT: break;
//CHECK-NEXT: }
//CHECK-NEXT: _t0++;
//CHECK-NEXT: printf("Writing result of out[%d]\n", i);
//CHECK-NEXT: clad::push(_t1, res);
//CHECK-NEXT: res += out_host[i];
//CHECK-NEXT: }
Expand Down

0 comments on commit b5e0d12

Please sign in to comment.