Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Runtime] Add config file for Device Config used in Runtime. #2978

Closed
wants to merge 1 commit into from

Conversation

beicy
Copy link
Contributor

@beicy beicy commented May 24, 2019

Summary:
Enable Loader to get device configs from a config yaml file.
Now there are 2 ways in Loader to get the DeviceConfigs:

  1. If the config file is provided, use the file;
  2. otherwise, use the "num-devices" which is 1 by default.

Documentation:

Test Plan:
The config file example is :

---
- name:     Device1
  kindName: CPU
  parameters: |
    "platformID":"1"
    "deviceID" : "0"
- name:     Device2
  kindName: CPU
  parameters: |
    "platformID":"1"
...

The command line:
./bin/text-translator -m "en2gr" -cpu -cpu-memory=500000 -load-device-configs="configs.yaml" <<< "I love music ."

[Optional Fixes #issue]

Please see a detailed explanation of how to fill out the fields in the relevant sections in PULL_REQUEST.md.

@@ -35,11 +35,33 @@ template <> struct MappingTraits<glow::NodeQuantizationInfo> {
}
};

template <> struct BlockScalarTraits<glow::MultiLineStr> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that does not belong to quantization/serialization. Could you move that to a separate configs, lib/configs

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also add a test for this.

Copy link
Contributor

@opti-mix opti-mix left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a very useful functionality! Thanks for working on this.

Questions:

  • Do we really need this multi-line syntax? Or may be YAML has a nicer syntactic alternative for this?
  • It could be that you do more work than needed and YAML parser can do more for you. @rdzhabarov had some experience with it for quantization. May be he can suggest a better way to use the YAML parser?
  • Could you add a test with an example YAML file?

/// Helper to get the BackendKind type from a backend's \p name. Need to be
/// updated if a new backend comes.
static BackendKind getBackendKindFromName(std::string &name) {
if (name == "CPU")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LLVM has llvm::StringMap for it.

}

/// Helper to get the parameters in DeviceConfig from \p str. The \p str has
/// multiply lines, and each line with this format : "str1" : "str2".
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mutiply->multiple.

@beicy
Copy link
Contributor Author

beicy commented May 24, 2019

  • Do we really need this multi-line syntax? Or may be YAML has a nicer syntactic alternative for this?
  • It could be that you do more work than needed and YAML parser can do more for you. @rdzhabarov had some experience with it for quantization. May be he can suggest a better way to use the YAML parser?

Discussed with @rdzhabarov about the yaml file. So far, we haven't found a better way...

@beicy beicy changed the title [WIP][Runtime] Add config file for Device Config used in Runtime. [Runtime] Add config file for Device Config used in Runtime. May 24, 2019
Copy link
Contributor

@gcatron gcatron left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great! Thanks for doing it. Could you add a test to the expensive tests? It might require checking in an example config file but I think that would be useful to have anyway.

@beicy beicy force-pushed the temp1 branch 2 times, most recently from 2a7eb21 to 2b39787 Compare May 28, 2019 18:21
@beicy
Copy link
Contributor Author

beicy commented May 28, 2019

Added an unit test for checking yaml file format, and an expensive test for the whole flow.

@@ -0,0 +1,12 @@
---
- name: Device1
kindName: CPU
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor nit, if we are going to use a CPU maybe rename the parameters so it's clear they are test parameters, or put a comment that these parameters don't mean anything to the CPU backend.

std::string str;
};

struct DeviceConfigHelper {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be in "Support.h" or some other header file that is related to device and device configurations?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is only used in Support.cpp for reading yaml file.

@@ -119,6 +119,26 @@ inline void report(llvm::StringRef str) { report(str.data()); }
/// can be inspected under debugger.
std::string legalizeName(llvm::StringRef name);

struct MultiLineStr {

This comment was marked as resolved.

@@ -271,6 +280,43 @@ static Kinded::Kind getKindFromNodeName(llvm::StringRef nodeName) {
GLOW_UNREACHABLE("Unknown node name.");
}

/// Helper to get the BackendKind type from a backend's \p name. Need to be
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like details of the hardware leak into the loader. This means that every time we add a new hardware backend we would need to update this file. Is there a way to avoid it?

@gcatron was working on something simiar.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had a chat with @rdzhabarov last week related to this. When we move to dynamic backend registration there will be a string:backendKind map that can be used. I think this solution is a temporary one until we have that map.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already essentially have this map via llvm::cl::opt<BackendKind> ExecutionBackend here in the Loader. If we must have a map like this too, I think we should unify them somehow.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can have a follow up PR for this, since some tests command line maybe changed as well.

for (unsigned int i = 0; i < numDevices; ++i) {
auto config = llvm::make_unique<runtime::DeviceConfig>(ExecutionBackend);
configs.push_back(std::move(config));

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This adds a lot of logic to a function that is already long. Is there a way to refactor things and make the code more readable?

Copy link
Contributor Author

@beicy beicy May 29, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got this piece of code into a function.

@@ -18,6 +18,10 @@
#include "glow/Testing/StrCheck.h"
#include "gtest/gtest.h"

#ifndef GLOW_DATA_PATH
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is required for the fbcode setup.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok. Got it. Thank you.

std::istringstream f(str.c_str());
while (getline(f, s, '\n')) {
size_t pos1, pos2, pos3, pos4;

This comment was marked as resolved.

@beicy beicy force-pushed the temp1 branch 3 times, most recently from 7bb76de to b8ce02e Compare May 29, 2019 17:09
Copy link

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@beicy has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

/// configs from the file. Otherwise, create \p numDevices number of devices
/// based on \p backendKind.
static void generateDeviceConfigs(
std::vector<std::unique_ptr<runtime::DeviceConfig>> &configs,
Copy link
Contributor

@gcatron gcatron May 29, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: can generateDeviceConfigs return the vector of configs? That way we don't have to pass in a reference.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done! Thanks!

Copy link
Contributor

@gcatron gcatron left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, once we have dynamic backend discovery we should be able to remove hw specific info from the loader.

Copy link

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@beicy has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@facebook-github-bot
Copy link

@beicy merged this pull request in 65df406.

1 similar comment
@facebook-github-bot
Copy link

@beicy merged this pull request in 65df406.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants