Unverified Commit 87978f03 authored by Umang Yadav's avatar Umang Yadav Committed by GitHub
Browse files

change examples to use new C++ api (#967)

Change examples to use newer c++ api for compile_options and file_options

C++ API changed for calling migraphx.  Fixed examples for compatibility 
parent 0b7672d7
...@@ -25,8 +25,8 @@ migraphx::save(p, output_file); ...@@ -25,8 +25,8 @@ migraphx::save(p, output_file);
``` ```
migraphx::program p = ... <migraphx::program>; migraphx::program p = ... <migraphx::program>;
migraphx_file_options options; migraphx::file_options options;
options.format = "msgpack"; options.set_file_format("msgpack");
migraphx::save(p, output_file, options); migraphx::save(p, output_file, options);
``` ```
...@@ -41,15 +41,15 @@ p = migraphx::load(input_file); ...@@ -41,15 +41,15 @@ p = migraphx::load(input_file);
``` ```
migraphx::program p; migraphx::program p;
migraphx_file_options options; migraphx::file_options options;
options.format = "msgpack"; options.set_file_format("msgpack");
p = migraphx::load(input_file, options); p = migraphx::load(input_file, options);
``` ```
To load a program that has been saved in JSON format: To load a program that has been saved in JSON format:
``` ```
migraphx::program p; migraphx::program p;
migraphx_file_options options; migraphx::file_options options;
options.format = "json"; options.set_file_format("json");
p = migraphx::load(input_file, options); p = migraphx::load(input_file, options);
``` ```
......
...@@ -44,15 +44,15 @@ int main(int argc, char** argv) ...@@ -44,15 +44,15 @@ int main(int argc, char** argv)
std::string format = load_arg; std::string format = load_arg;
if(format == "json") if(format == "json")
{ {
migraphx_file_options options; migraphx::file_options options;
options.format = "json"; options.set_file_format("json");
p = migraphx::load(input_file, options); p = migraphx::load(input_file, options);
} }
else if(format == "msgpack") else if(format == "msgpack")
{ {
migraphx_file_options options; migraphx::file_options options;
options.format = "msgpack"; options.set_file_format("msgpack");
p = migraphx::load(input_file, options); p = migraphx::load(input_file, options);
} }
else else
p = migraphx::load(input_file); p = migraphx::load(input_file);
...@@ -80,8 +80,8 @@ int main(int argc, char** argv) ...@@ -80,8 +80,8 @@ int main(int argc, char** argv)
output_file = save_arg == nullptr ? "out" : save_arg; output_file = save_arg == nullptr ? "out" : save_arg;
output_file.append(".msgpack"); output_file.append(".msgpack");
migraphx_file_options options; migraphx::file_options options;
options.format = "msgpack"; options.set_file_format("msgpack");
migraphx::save(p, output_file.c_str(), options); migraphx::save(p, output_file.c_str(), options);
std::cout << "Program has been saved as ./" << output_file << std::endl; std::cout << "Program has been saved as ./" << output_file << std::endl;
} }
......
...@@ -60,14 +60,14 @@ migraphx::quantize_int8(prog, targ, quant_opts); ...@@ -60,14 +60,14 @@ migraphx::quantize_int8(prog, targ, quant_opts);
## Compilation ## Compilation
Network graphs saved in e.g. ONNX or protobuf format are not target-specific. In order to run inference, we must compile the graph into a target-specific program. Network graphs saved in e.g. ONNX or protobuf format are not target-specific. In order to run inference, we must compile the graph into a target-specific program.
Two options may be turned on (default for both is `false`) when compiling: Two options may be turned on when compiling:
- `bool offload_copy`: For targets with offloaded memory (such as the gpu), this will insert instructions during compilation to copy the input parameters to the offloaded memory and to copy the final result from the offloaded memory back to main memory. - `set_offload_copy(bool value)`: For targets with offloaded memory (such as the gpu), this will insert instructions during compilation to copy the input parameters to the offloaded memory and to copy the final result from the offloaded memory back to main memory. Default value is `false` for offload_copy.
- `bool fast_math`: Optimize math functions to use faster approximate versions. There may be slight accuracy degredation when enabled. - `set_fast_math(bool value)`: Optimize math functions to use faster approximate versions. There may be slight accuracy degredation when enabled. Default value is `true` for fast_math.
The following snippet assumes `targ` has been set as "gpu", and will compile the program without the fast_math optimization. The following snippet assumes `targ` has been set as "gpu", and will compile the program without the fast_math optimization.
``` ```
migraphx_compile_options comp_opts; migraphx::compile_options comp_opts;
comp_opts.offload_copy = true; comp_opts.set_offload_copy();
prog.compile(targ, comp_opts); prog.compile(targ, comp_opts);
``` ```
......
...@@ -99,8 +99,8 @@ int main(int argc, char** argv) ...@@ -99,8 +99,8 @@ int main(int argc, char** argv)
if(GPU) if(GPU)
{ {
migraphx_compile_options comp_opts; migraphx::compile_options comp_opts;
comp_opts.offload_copy = true; comp_opts.set_offload_copy();
prog.compile(targ, comp_opts); prog.compile(targ, comp_opts);
} }
else else
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment