Repository: LMCache/LMCache
File: lmcache/v1/storage_backend/connector/eic_connector.py (Python)

Code before:
            self.connection.free_managed_buffer(ptr, size)
            del self.used_mem[ptr]


def _make_dir(path: str):
    try:
        if not os.path.exists(path):
            os.makedirs(path)
        logger.info(f"create dir '{path}' success")
    except OSError as e:
        logger.error(f"create dir '{path}' error {e}")


class EICConnector(RemoteConnector):
    """
    The remote url should start with "eic://" and only have one host-port pair
    """

    def __init__(
        self,
        endpoint: str,
        loop: asyncio.AbstractEventLoop,
        memory_allocator: LocalCPUBackend,
    ):
        super().__init__(memory_allocator.config, memory_allocator.metadata)

        logger.info("init EICConnector")
        logger.info(f"try connect to eic: {endpoint}")

        self.loop = loop
        self.memory_allocator = memory_allocator

        # Initialize pq_executor early to avoid AttributeError
        try:
            self.pq_executor = AsyncPQExecutor(loop)
            logger.info("AsyncPQExecutor initialized successfully")
        except Exception as e:
            logger.error(f"Failed to initialize AsyncPQExecutor: {e}")
            raise

        self.cudaError_t = ctypes.c_int
        self.cudaMemcpyDeviceToHost = 2
        self.cudaMemcpyHostToDevice = 1
        self.cuda_lib = ctypes.CDLL("libcudart.so")
        self.cuda_lib.cudaMemcpy.argtypes = [
            ctypes.c_void_p,
            ctypes.c_void_p,
            ctypes.c_size_t,
            ctypes.c_int,
        ]
        self.cuda_lib.cudaMemcpy.restype = self.cudaError_t

Review comment (refactor):
can we add a comment in each connector on what this super init is doing? like variables / data will be accessible in the child connector. I remember this was a little confusing during refactoring the S3 connector

Code after:
            self.connection.free_managed_buffer(ptr, size)
            del self.used_mem[ptr]


def _make_dir(path: str):
    try:
        if not os.path.exists(path):
            os.makedirs(path)
        logger.info(f"create dir '{path}' success")
    except OSError as e:
        logger.error(f"create dir '{path}' error {e}")


class EICConnector(RemoteConnector):
    """
    The remote url should start with "eic://" and only have one host-port pair
    """

    def __init__(
        self,
        endpoint: str,
        loop: asyncio.AbstractEventLoop,
        memory_allocator: LocalCPUBackend,
    ):
        # initialize base class, which includes some common attributes
        super().__init__(memory_allocator.config, memory_allocator.metadata)

        logger.info("init EICConnector")
        logger.info(f"try connect to eic: {endpoint}")

        self.loop = loop
        self.memory_allocator = memory_allocator

        # Initialize pq_executor early to avoid AttributeError
        try:
            self.pq_executor = AsyncPQExecutor(loop)
            logger.info("AsyncPQExecutor initialized successfully")
        except Exception as e:
            logger.error(f"Failed to initialize AsyncPQExecutor: {e}")
            raise

        self.cudaError_t = ctypes.c_int
        self.cudaMemcpyDeviceToHost = 2
        self.cudaMemcpyHostToDevice = 1
        self.cuda_lib = ctypes.CDLL("libcudart.so")
        self.cuda_lib.cudaMemcpy.argtypes = [
            ctypes.c_void_p,
            ctypes.c_void_p,
            ctypes.c_size_t,
            ctypes.c_int,
        ]