Marko Grdinić
Marko Grdinić

Reputation: 4062

How do I redirect the Cuda kernel IO in Cupy?

import sys

class Logger:
    def __init__(self, filename):
        self.console = sys.stdout
        self.file = open(filename, 'w')

    def write(self, message):
        self.console.write(message)
        self.file.write(message)

    def flush(self):
        self.console.flush()
        self.file.flush()

# Usage:
path = 'path/to/output.txt'
sys.stdout = Logger(path)
print('Hello from CuPy!')

# Reset stdout to its original value when done:
sys.stdout = sys.__stdout__

The advice I am getting from BingGPT for only works for redirecting regular host output to a file. How do I make it work for printf statements called inside the kernel?

Edit: Here is the longer example that I am using for testing purposes.

Upvotes: 0

Views: 15

Answers (0)

Related Questions