CtrlK
CommunityDocumentationLog inGet started
Tessl Logo

tessl/pypi-pycuda

Python wrapper for Nvidia CUDA parallel computation API with object cleanup, automatic error checking, and convenient abstractions.

62%

Overall

Evaluation62%

0.94x

Agent success when using this tile

Overview
Eval results
Files

task.mdevals/scenario-6/

GPU Context Manager with Synchronization

Build a context manager utility for GPU computation that handles device context setup, operations, and proper synchronization.

Requirements

Create a GPUContextManager class that:

  1. Context Setup: Initializes a CUDA context for a specified GPU device (by device ID)
  2. Context Lifecycle: Properly manages context creation and cleanup
  3. Synchronization Operations: Provides methods to synchronize the GPU context before and after operations
  4. Multi-operation Support: Can execute multiple GPU operations within the same context while ensuring proper synchronization between operations

The context manager should:

  • Accept a device ID during initialization (default to device 0)
  • Automatically set up the context when entering
  • Support explicit synchronization calls
  • Clean up the context when exiting
  • Provide a method to get the current device properties (name and total memory)

Test Cases

  • Initializing the context manager with device 0 successfully creates a context and returns device properties @test
  • Calling synchronize on an active context completes without error @test
  • The context manager properly cleans up resources when exiting @test
  • Multiple synchronization calls within the same context work correctly @test

Implementation

@generates

API

class GPUContextManager:
    """
    Context manager for GPU operations with synchronization support.
    """

    def __init__(self, device_id=0):
        """
        Initialize the GPU context manager.

        Args:
            device_id: The GPU device ID to use (default: 0)
        """
        pass

    def __enter__(self):
        """
        Enter the context and set up the GPU context.

        Returns:
            self
        """
        pass

    def __exit__(self, exc_type, exc_val, exc_tb):
        """
        Exit the context and clean up GPU resources.
        """
        pass

    def synchronize(self):
        """
        Synchronize the current context to ensure all GPU operations complete.
        """
        pass

    def get_device_info(self):
        """
        Get information about the current device.

        Returns:
            dict: Dictionary with 'name' and 'total_memory' keys
        """
        pass

Dependencies { .dependencies }

pycuda { .dependency }

Provides GPU computing capabilities with context management and synchronization.

@satisfied-by

tessl i tessl/pypi-pycuda@2025.1.0

tile.json