|
26 | 26 | WF_TYPE_SAND = 0 |
27 | 27 | WF_TYPE_ASL = 1 |
28 | 28 |
|
| 29 | +def get_kv_pairs(testdict, keys, dicts=None): |
| 30 | + # find and return kv pairs with particular keys in testdict |
| 31 | + if not dicts: |
| 32 | + dicts = [testdict] |
| 33 | + testdict = [testdict] |
| 34 | + data = testdict.pop(0) |
| 35 | + if isinstance(data, dict): |
| 36 | + data = data.values() |
| 37 | + for d in data: |
| 38 | + if isinstance(d, dict) or isinstance(d, list): # check d for type |
| 39 | + testdict.append(d) |
| 40 | + if isinstance(d, dict): |
| 41 | + dicts.append(d) |
| 42 | + if testdict: # no more data to search |
| 43 | + return get_kv_pairs(testdict, keys, dicts) |
| 44 | + return [(k, v) for d in dicts for k, v in d.items() if k in keys] |
| 45 | + |
29 | 46 | def is_asl_workflow(wfobj): |
30 | 47 | return 'StartAt' in wfobj and 'States' in wfobj and isinstance(wfobj['States'], dict) |
31 | 48 |
|
@@ -132,7 +149,6 @@ def compile_resource_info_map(resource_names, uploaded_resources, email, sapi, d |
132 | 149 | resource_metadata = json.loads(resource_metadata) |
133 | 150 | if "runtime" in resource_metadata: |
134 | 151 | resource_info["runtime"] = resource_metadata["runtime"] |
135 | | - print("RESOURCE_INFO_ALL: " +str(resource_info)) |
136 | 152 | #if "num_gpu" in resource_metadata: |
137 | 153 | # print("RESOURCE_INFO: " + str(resource_info["num_gpu"])) |
138 | 154 |
|
@@ -245,7 +261,7 @@ def get_workflow_host_port(host_to_deploy, sid): |
245 | 261 |
|
246 | 262 | return success, host_port |
247 | 263 |
|
248 | | -def create_k8s_deployment(email, workflow_info, runtime, management=False): |
| 264 | +def create_k8s_deployment(email, workflow_info, runtime, management=False, use_gpus=0): |
249 | 265 | # KUBERNETES MODE |
250 | 266 | new_workflow_conf = {} |
251 | 267 | conf_file = '/opt/mfn/SandboxAgent/conf/new_workflow.conf' |
@@ -297,17 +313,15 @@ def create_k8s_deployment(email, workflow_info, runtime, management=False): |
297 | 313 | env.append({'name': 'WORKFLOWID', 'value': workflow_info["workflowId"]}) |
298 | 314 | env.append({'name': 'WORKFLOWNAME', 'value': workflow_info["workflowName"]}) |
299 | 315 |
|
300 | | - """ |
301 | | - if "num_gpu" in workflow_info.keys(): |
302 | | - print("INSIDE K8S Deploy, num_gpu: " + str(workflow_info['num_gpu'])) |
303 | | - num_gpu = int(workflow_info['num_gpu']) |
| 316 | + if use_gpus >= 0: |
| 317 | + #print("INSIDE K8S Deploy, num_gpu: " + str(workflow_info['num_gpu'])) |
| 318 | + #num_gpu = int(workflow_info['num_gpu']) |
304 | 319 | # overwrite values from values.yaml for new workflows |
305 | | - kservice['spec']['template']['spec']['containers'][0]['resources']['limits']['nvidia.com/gpu'] = str(num_gpu) |
306 | | - kservice['spec']['template']['spec']['containers'][0]['resources']['requests']['nvidia.com/gpu'] = str(num_gpu) |
307 | | - kservice['spec']['template']['spec']['containers'][0]['image'] = "localhost:5000/microfn/sandbox" |
308 | | - if num_gpu > 0: |
309 | | - kservice['spec']['template']['spec']['containers'][0]['image'] = "localhost:5000/microfn/sandbox" |
310 | | - """ |
| 320 | + kservice['spec']['template']['spec']['containers'][0]['resources']['limits']['nvidia.com/gpu'] = str(use_gpus) |
| 321 | + kservice['spec']['template']['spec']['containers'][0]['resources']['requests']['nvidia.com/gpu'] = str(use_gpus) |
| 322 | + #kservice['spec']['template']['spec']['containers'][0]['image'] = "localhost:5000/microfn/sandbox" |
| 323 | + kservice['spec']['template']['spec']['containers'][0]['image'] = "localhost:5000/microfn/sandbox_gpu" |
| 324 | + |
311 | 325 | # Special handling for the management container |
312 | 326 | if management: |
313 | 327 | kservice['spec']['template']['spec']['volumes'] = [{ 'name': 'new-workflow-conf', 'configMap': {'name': new_workflow_conf['configmap']}}] |
@@ -407,6 +421,11 @@ def handle(value, sapi): |
407 | 421 | workflow = data["workflow"] |
408 | 422 | if "id" not in workflow: |
409 | 423 | raise Exception("malformed input") |
| 424 | + """ |
| 425 | + if "gpu_usage" not in workflow: |
| 426 | + raise Exception("malformed input: no gpu_usage") |
| 427 | + use_gpus = int(data['gpu_usage']) |
| 428 | + """ |
410 | 429 | sapi.log(json.dumps(workflow)) |
411 | 430 | wfmeta = sapi.get(email + "_workflow_" + workflow["id"], True) |
412 | 431 | if wfmeta is None or wfmeta == "": |
@@ -437,6 +456,8 @@ def handle(value, sapi): |
437 | 456 | if is_asl_workflow(wfobj): |
438 | 457 | wf_type = WF_TYPE_ASL |
439 | 458 |
|
| 459 | + #use_gpus = int(wfmeta._gpu_usage) |
| 460 | + |
440 | 461 | success, errmsg, resource_names, uploaded_resources = check_workflow_functions(wf_type, wfobj, email, sapi) |
441 | 462 | if not success: |
442 | 463 | raise Exception("Couldn't deploy workflow; " + errmsg) |
@@ -477,13 +498,16 @@ def handle(value, sapi): |
477 | 498 | else: |
478 | 499 | runtime = "Python" |
479 | 500 |
|
| 501 | + """ |
480 | 502 | if "num_gpu" in resource_info_map.keys(): |
481 | 503 | print ("RESOURCE_INFO_MAP: " + str(resource_info_map)) |
482 | 504 | workflow_info['num_gpu'] = resource_info_map['num_gpu'] |
483 | 505 | else: |
484 | 506 | workflow_info['num_gpu'] = 0 |
| 507 | + """ |
| 508 | + use_gpus = 0 |
485 | 509 |
|
486 | | - url, endpoint_key = create_k8s_deployment(email, workflow_info, runtime) |
| 510 | + url, endpoint_key = create_k8s_deployment(email, workflow_info, runtime, use_gpus) |
487 | 511 | if url is not None and len(url) > 0: |
488 | 512 | status = "deploying" |
489 | 513 | sapi.addSetEntry(workflow_info["workflowId"] + "_workflow_endpoints", str(url), is_private=True) |
|
0 commit comments