diff --git a/src/codegen/codegen_cuda.cpp b/src/codegen/codegen_cuda.cpp index 971410b98..77cf0cd88 100644 --- a/src/codegen/codegen_cuda.cpp +++ b/src/codegen/codegen_cuda.cpp @@ -1096,6 +1096,20 @@ void CodeGen_CUDA::visit(const Allocate* op) { op->num_elements.accept(this); parentPrecedence = TOP; stream << "));" << endl; + // If the operation wants the input cleared, then memset it to zero. + if (op->clear) { + doIndent(); + stream << "gpuErrchk(cudaMemset("; + op->var.accept(this); + stream << variable_name; + stream << ", 0, "; + stream << "sizeof(" << elementType << ")"; + stream << " * "; + parentPrecedence = MUL; + op->num_elements.accept(this); + parentPrecedence = TOP; + stream << "));" << endl; + } if(op->is_realloc) { doIndent();