Skip to main content

User code executors for Backend.AI kernels

Project description

A common base runner for various programming languages.

It manages an internal task queue so that multiple command/code execution requests are processed in the FIFO order, without garbling the console output.

How to write a new computation kernel

Inherit ai.backend.kernel.BaseRunner and implement the following methods:

  • async def init_with_loop(self)

    • Called after the asyncio event loop becomes available.

    • Mostly just pass.

    • If your kernel supports interactive user input, then put set self.user_input_queue as an asyncio.Queue object. It’s your job to utilize the queue object for waiting for the user input. (See handle_input() method in ai/backend/kernel/python/inproc.py for reference) If it’s not set, then any attempts for getting interactive user input will simply return "<user-input is unsupported>".

  • async def build_heuristic(self)

    • (Batch mode) Write a heuristic code to find some build script or run a good-enough build command for your language/runtime.

    • (Blocking) You don’t have to worry about overlapped execution since the base runner will take care of it.

  • async def execute_heuristic(self)

    • (Batch mode) Write a heuristic code to find the main program.

    • (Blocking) You don’t have to worry about overlapped execution since the base runner will take care of it.

  • async def query(self, code_text)

    • (Query mode) Directly run the given code snippet. Depending on the language/runtime, you may need to create a temporary file and execute an external program.

    • (Blocking) You don’t have to worry about overlapped execution since the base runner will take care of it.

  • async def complete(self, data)

    • (Query mode) Take a dict data that includes the current line of code where the user is typing and return a list of strings that can auto-complete it.

    • (Non-blocking) You should implement this method to run asynchronously with ongoing code execution.

  • async def interrupt(self)

    • (Query mode) Send an interruption signal to the running program. The implementation is up to you. The Python runner currently spawns a thread for in-process query-mode execution and use a ctypes hack to throw KeyboardInterrupt exception into it.

    • (Non-blocking) You should implement this method to run asynchronously with ongoing code execution.

NOTE: Existing codes are good referecnes!

How to use in your Backend.AI computation kernels

Install this package using pip via a RUN instruction in Dockerfile. Then, set the CMD instruction like below:

CMD ["/home/sorna/jail", "-policy", "/home/sorna/policy.yml", \
     "/usr/local/bin/python", "-m", "ai.backend.kernel", "<language>"]

where <language> should be one of the supported language names defined in lang_map variable in ai/backend/kernel/__main__.py file.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

backend.ai-kernel-runner-1.0.5.tar.gz (18.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

backend.ai_kernel_runner-1.0.5-py3-none-any.whl (34.5 kB view details)

Uploaded Python 3

File details

Details for the file backend.ai-kernel-runner-1.0.5.tar.gz.

File metadata

File hashes

Hashes for backend.ai-kernel-runner-1.0.5.tar.gz
Algorithm Hash digest
SHA256 b888fbf8b351cc9a50c24b4ecc6d2efcdb015868f6a9cbe2d0bddca6db20a651
MD5 c5bdced86d85a07de156f10e583341b2
BLAKE2b-256 2c90c76e65b3efdbaf8d753ceb4b38e824a4d4403f89e5763b6bb5b380d13706

See more details on using hashes here.

File details

Details for the file backend.ai_kernel_runner-1.0.5-py3-none-any.whl.

File metadata

File hashes

Hashes for backend.ai_kernel_runner-1.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 22dad68af0f1f5d2acbc2e81cfad294ae63b6b0b25c40179ed8b2d1fadf0ffc5
MD5 a63384245436aab7b7295855c290154c
BLAKE2b-256 6619df648f59b4ea48f3a8c200c6991951fa33dc3323ddaf09f4f3eb9f2abe57

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page