예제 #1
0
def invoke(ctx, func, native=False, iface=None, np=8):
    """
    Invoke one of the ParRes Kernels functions
    """
    if func not in PRK_CMDLINE:
        print("Invalid PRK function {}".format(func))
        return 1

    cmdline = PRK_CMDLINE[func]

    if func == "random" and not is_power_of_two(np):
        print("Must have a power of two number of processes for random")
        exit(1)
    elif func == "sparse" and not (SPARSE_GRID_SIZE % np == 0):
        print(
            "To run sparse, grid size must be a multiple of --np (currently grid_size={} and np={})"
            .format(SPARSE_GRID_SIZE, np))
        exit(1)

    if native:
        executable = PRK_NATIVE_EXECUTABLES[func]
        cmd_out = mpi_run(executable, iface=iface, cmdline=cmdline, np=np)
        cmd_out = cmd_out.decode()
        print(cmd_out)
    else:
        host, port = get_invoke_host_port()
        cmd_out = invoke_impl(FAASM_USER,
                              func,
                              cmdline=cmdline,
                              host=host,
                              port=port,
                              mpi_world_size=np)

    _parse_prk_out(func, cmd_out)
예제 #2
0
def mapping(ctx):
    """
    Run genomics mapping
    """
    read_idxs, _ = get_reads_from_dir()

    # Iterate through and make the calls to the worker
    call_ids = list()
    for read_idx in read_idxs:
        print("Invoking worker for read chunk {}".format(read_idx))
        call_id = invoke_impl("gene",
                              "mapper",
                              input="{}".format(read_idx),
                              async=True,
                              poll=False)
        call_ids.append(call_id)

    # Poll for completion of each read
    completed_read_idxs = list()
    host, port = get_invoke_host_port()
    print("Polling workers...")

    while len(completed_read_idxs) < len(read_idxs):
        for i, read_idx in enumerate(read_idxs):
            sleep(0.5)

            # See whether this call is still running
            call_id = call_ids[i]
            result, output = status_call_impl(call_id, host, port)
            if result == STATUS_RUNNING:
                continue

            # Check for success or failure
            if result == STATUS_SUCCESS:
                # Download the results of this read
                print("Read chunk {} completed. Downloading output".format(
                    read_idx))
                state_key = "output_read_{}".format(read_idx)

                output_dir = join(FAASM_DATA_DIR, "genomics_output")
                if not exists(output_dir):
                    makedirs(output_dir)

                output_file = join(output_dir, state_key)
                host, port = get_upload_host_port(None, None)
                download_binary_state("gene",
                                      state_key,
                                      output_file,
                                      host=host,
                                      port=port)

            elif result == STATUS_FAILED:
                print("Read chunk {} failed: {}", read_idx, output)

            # Check if we're done
            completed_read_idxs.append(read_idx)

    print("All read chunks finished")
예제 #3
0
    def _do_run(self, native):
        if not self.no_billing:
            # Start the billing scripts
            start_billing()

        # Start the timer
        run_start = time()

        # Run the request
        success, output = invoke_impl(
            self.user,
            self.func,
            poll=True,
            poll_interval_ms=self.poll_interval,
            knative=True,
            input=self.input_data,
            native=native,
            py=self.is_python,
        )

        # Finish the timer
        run_time_ms = (time() - run_start) * 1000.0

        if not self.no_billing:
            # Pull the billing info
            pull_billing()

        if not success:
            print("FAILED on {}".format(self.input_data))

        output_dir = join(FAASM_HOME, "{}_{}".format(self.user, self.func))
        if not exists(output_dir):
            mkdir(output_dir)

        system = "NATIVE" if native else "FAASM"
        folder_name = self.get_result_dir_name(system)
        result_dir = join(output_dir, folder_name)
        if exists(result_dir):
            rmtree(result_dir)
        mkdir(result_dir)

        # Write the running time
        output_file = join(result_dir, "RUN_TIME.log")
        with open(output_file, "w") as fh:
            fh.write("{}ms".format(run_time_ms))

        # Write the output from the function
        output_file = join(result_dir, self.result_file_name)
        with open(output_file, "w") as fh:
            fh.write(output)

        # Copy billing directory into place
        if not self.no_billing:
            res = call("cp -r /tmp/billing {}/".format(result_dir), shell=True)
            if res != 0:
                raise RuntimeError("Failed to put billing files in place")
예제 #4
0
    def execute_benchmark(self, native):
        success, output = invoke_impl(
            self.user,
            self.func,
            poll=True,
            poll_interval_ms=self.poll_interval,
            knative=True,
            input=self.input_data,
            native=native,
            py=self.is_python,
        )

        return success, output
예제 #5
0
    port=None,
    input=None,
    py=False,
    async=False,
    knative=True,
    native=False,
    ibm=False,
    poll=False,
    cmdline=None,
):
    """
    Invoke a function
    """
    invoke_impl(user,
                func,
                host=host,
                port=port,
                input=input,
                py=py,
                async=async,
                knative=knative,
                native=native,
                ibm=ibm,
                poll=poll,
                cmdline=cmdline)


@task
def status(ctx, call_id, host=None, port=None):
    """
    Get the status of an async function call
    """