Ctrl + k

or run

tessl search
Log in

Version

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
pypipkg:pypi/pyopencl@2025.2.x
tile.json

tessl/pypi-pyopencl

tessl install tessl/pypi-pyopencl@2025.2.0

Python wrapper for OpenCL enabling GPU and parallel computing with comprehensive array operations and mathematical functions

Agent Success

Agent success rate when using this tile

86%

Improvement

Agent success rate improvement when using this tile compared to baseline

1.28x

Baseline

Agent success rate without this tile

67%

task.mdevals/scenario-4/

GPU Data Buffer Manager

Build a data buffer management system that efficiently transfers and processes numerical data between host (CPU) and device (GPU) memory using parallel computing capabilities.

Requirements

Create a Python module that provides buffer management functionality with the following capabilities:

Buffer Initialization

Initialize and set up a computing context with the following:

  • Automatic device selection (GPU preferred, fallback to CPU)
  • Command queue creation for operations
  • Context management for resource cleanup

Data Transfer Operations

Implement functions to handle data movement:

  1. Upload data to device: Transfer numpy arrays from host to device memory

    • Support for various numeric data types (int32, float32, float64)
    • Proper memory allocation on device
    • Asynchronous transfer capability
  2. Download data from device: Retrieve data from device back to host

    • Return data as numpy arrays
    • Maintain original data type
    • Support synchronous reads
  3. Device-to-device copy: Copy data between device buffers

    • Efficient internal device memory transfer
    • No intermediate host transfer required

Test Cases

  • Upload a numpy array of 1000 random float32 values to device, download it back, and verify the values match exactly @test
  • Upload two numpy arrays to device, copy the first buffer's data to the second buffer on device, download both, and verify they contain identical data @test

Implementation

@generates

API

import numpy as np

class BufferManager:
    """Manages GPU buffer operations for data transfer and manipulation."""

    def __init__(self):
        """Initialize the buffer manager with appropriate device context and queue."""
        pass

    def upload_to_device(self, data: np.ndarray):
        """
        Transfer numpy array from host to device memory.

        Args:
            data: Numpy array to upload

        Returns:
            Device buffer handle
        """
        pass

    def download_from_device(self, device_buffer, shape, dtype):
        """
        Retrieve data from device buffer to host memory.

        Args:
            device_buffer: Device buffer handle
            shape: Shape of the output array
            dtype: Data type of the array

        Returns:
            Numpy array containing the data
        """
        pass

    def copy_device_buffer(self, source_buffer, dest_buffer, size_bytes: int):
        """
        Copy data from one device buffer to another.

        Args:
            source_buffer: Source device buffer handle
            dest_buffer: Destination device buffer handle
            size_bytes: Number of bytes to copy
        """
        pass

    def cleanup(self):
        """Release resources and cleanup context."""
        pass

Dependencies { .dependencies }

pyopencl { .dependency }

Provides GPU computing and buffer management capabilities.

numpy { .dependency }

Provides array data structures and operations.