Skip to content
This repository has been archived by the owner on Sep 22, 2023. It is now read-only.

Commit

Permalink
Add cli command to set required resources (lablup/backend.ai-manager#50)
Browse files Browse the repository at this point in the history
* TODO: spawn resourced-limited container.
  • Loading branch information
adrysn committed Jun 26, 2018
1 parent 6112856 commit 2892183
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
13 changes: 11 additions & 2 deletions ai/backend/client/cli/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,16 @@ def run(args):
envs = {k: v for k, v in map(lambda s: s.split('=', 1), args.env)}
else:
envs = {}
if args.resources is not None:
resources = {k: v for k, v in map(lambda s: s.split('=', 1), args.resources)}
else:
resources = {}
try:
kernel = Kernel.get_or_create(
args.lang, args.client_token,
mounts=args.mount,
envs=envs)
envs=envs,
resources=resources)
except BackendError as e:
print_fail(str(e))
return
Expand Down Expand Up @@ -185,8 +190,12 @@ def run(args):
run.add_argument('-s', '--stats', action='store_true', default=False,
help='Show resource usage statistics after termination '
'(only works if "--rm" is given)')
run.add_argument('-r', '--resources', metavar='KEY=VAL', type=str, action='append',
help='Set computation resources (e.g: -r cpu=2 -r ram=512 -r gpu=1)'
'The maximum values may be limited by system setting '
'(default: cpu=1 ram=1024 gpu=0)')
run.add_argument('-q', '--quiet', action='store_true', default=False,
help='Hide execution details but show only the kernel'
help='Hide execution details but show only the kernel '
'outputs')


Expand Down
4 changes: 4 additions & 0 deletions ai/backend/client/kernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ def _get_or_create(cls, lang: str,
client_token: str=None,
mounts: Iterable[str]=None,
envs: Mapping[str, str]=None,
resources: Mapping[str, int]=None,
max_mem: int=0, exec_timeout: int=0,
config: APIConfig=None) -> str:
if client_token:
Expand All @@ -51,6 +52,9 @@ def _get_or_create(cls, lang: str,
'config': {
'mounts': mounts,
'environ': envs,
'instanceMemory': resources.get('ram'),
'instanceCores': resources.get('cpu'),
'instanceGPUs': resources.get('gpu'),
},
}, config=config)
data = resp.json()
Expand Down

0 comments on commit 2892183

Please sign in to comment.