Skip to content

Commit

Permalink
Merge pull request #1 from apache/master
Browse files Browse the repository at this point in the history
pull
  • Loading branch information
Xuxue1 authored May 13, 2020
2 parents 7bad56b + 79485fb commit c98c22f
Show file tree
Hide file tree
Showing 103 changed files with 1,660 additions and 1,527 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ __pycache__/
# C extensions
*.so
*.ll

.npm
# Distribution / packaging
.Python
env/
Expand Down Expand Up @@ -225,7 +225,7 @@ Pipfile.lock
# conda package artifacts
conda/Dockerfile.cuda*
conda/pkg

.node_repl_history
# nix files
.envrc
*.nix
Expand Down
2 changes: 0 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ endif()
tvm_option(USE_CUDA "Build with CUDA" OFF)
tvm_option(USE_OPENCL "Build with OpenCL" OFF)
tvm_option(USE_VULKAN "Build with Vulkan" OFF)
tvm_option(USE_OPENGL "Build with OpenGL" OFF)
tvm_option(USE_METAL "Build with Metal" OFF)
tvm_option(USE_ROCM "Build with ROCM" OFF)
tvm_option(ROCM_PATH "The path to rocm" /opt/rocm)
Expand Down Expand Up @@ -308,7 +307,6 @@ include(cmake/modules/VTA.cmake)
include(cmake/modules/CUDA.cmake)
include(cmake/modules/Hexagon.cmake)
include(cmake/modules/OpenCL.cmake)
include(cmake/modules/OpenGL.cmake)
include(cmake/modules/OpenMP.cmake)
include(cmake/modules/Vulkan.cmake)
include(cmake/modules/Metal.cmake)
Expand Down
19 changes: 16 additions & 3 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,10 @@
//
//

ci_lint = "tvmai/ci-lint:v0.60"
ci_gpu = "tvmai/ci-gpu:v0.63"
ci_cpu = "tvmai/ci-cpu:v0.61"
ci_lint = "tvmai/ci-lint:v0.61"
ci_gpu = "tvmai/ci-gpu:v0.64"
ci_cpu = "tvmai/ci-cpu:v0.62"
ci_wasm = "tvmai/ci-wasm:v0.60"
ci_i386 = "tvmai/ci-i386:v0.52"

// tvm libraries
Expand Down Expand Up @@ -169,6 +170,18 @@ stage('Build') {
}
}
}
},
'BUILD: WASM': {
node('CPU') {
ws(per_exec_ws("tvm/build-wasm")) {
init_git()
sh "${docker_run} ${ci_wasm} ./tests/scripts/task_config_build_wasm.sh"
make(ci_wasm, 'build', '-j2')
timeout(time: max_time, unit: 'MINUTES') {
sh "${docker_run} ${ci_wasm} ./tests/scripts/task_web_wasm.sh"
}
}
}
},
'BUILD : i386': {
node('CPU') {
Expand Down
55 changes: 29 additions & 26 deletions apps/bundle_deploy/bundle.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,22 @@
* under the License.
*/

#include <tvm/runtime/c_runtime_api.h>
#include <stdio.h>
#include <stdlib.h>
#include <tvm/runtime/c_runtime_api.h>

/*! \brief macro to do C API call */
#define TVM_CCALL(func) \
do { \
int ret = (func); \
if (ret != 0) { \
#define TVM_CCALL(func) \
do { \
int ret = (func); \
if (ret != 0) { \
fprintf(stderr, "%s: %d: error: %s\n", __FILE__, __LINE__, TVMGetLastError()); \
exit(ret); \
} \
exit(ret); \
} \
} while (0)

TVM_DLL void * tvm_runtime_create(const char * json_data,
const char * params_data,
const uint64_t params_size) {
TVM_DLL void* tvm_runtime_create(const char* json_data, const char* params_data,
const uint64_t params_size) {
int64_t device_type = kDLCPU;
int64_t device_id = 0;

Expand All @@ -47,43 +46,47 @@ TVM_DLL void * tvm_runtime_create(const char * json_data,

// declare pointers
TVMModuleHandle (*SystemLibraryCreate)();
TVMModuleHandle (*TVMGraphRuntimeCreate)(const char *, const TVMModuleHandle, const TVMContext *);
int (*TVMGraphRuntime_LoadParams)(TVMModuleHandle, const char *, const uint32_t);
TVMModuleHandle (*TVMGraphRuntimeCreate)(const char*, const TVMModuleHandle, const TVMContext*);
int (*TVMGraphRuntime_LoadParams)(TVMModuleHandle, const char*, const uint32_t);

// get pointers
TVM_CCALL(TVMFuncGetGlobal("runtime.SystemLib", (TVMFunctionHandle*)&SystemLibraryCreate));
TVM_CCALL(TVMFuncGetGlobal("tvm.graph_runtime.create", (TVMFunctionHandle*)&TVMGraphRuntimeCreate));
TVM_CCALL(
TVMFuncGetGlobal("tvm.graph_runtime.create", (TVMFunctionHandle*)&TVMGraphRuntimeCreate));

// run modules
TVMModuleHandle mod_syslib = SystemLibraryCreate();
TVMModuleHandle mod = TVMGraphRuntimeCreate(json_data, mod_syslib, &ctx);
TVM_CCALL(TVMModGetFunction(mod, "load_params", 0, (TVMFunctionHandle*)&TVMGraphRuntime_LoadParams));
TVM_CCALL(
TVMModGetFunction(mod, "load_params", 0, (TVMFunctionHandle*)&TVMGraphRuntime_LoadParams));
TVMGraphRuntime_LoadParams(mod, params.data, params.size);

return mod;
}

TVM_DLL void tvm_runtime_destroy(void * runtime) {
void (*TVMGraphRuntimeRelease)(TVMModuleHandle *);
TVM_CCALL(TVMFuncGetGlobal("tvm.graph_runtime.release", (TVMFunctionHandle*)&TVMGraphRuntimeRelease));
TVM_DLL void tvm_runtime_destroy(void* runtime) {
void (*TVMGraphRuntimeRelease)(TVMModuleHandle*);
TVM_CCALL(
TVMFuncGetGlobal("tvm.graph_runtime.release", (TVMFunctionHandle*)&TVMGraphRuntimeRelease));
TVMGraphRuntimeRelease(&runtime);
}

TVM_DLL void tvm_runtime_set_input(void * runtime, const char * name, DLTensor * tensor) {
void (*TVMGraphRuntime_SetInput)(TVMModuleHandle, const char *, DLTensor*);
TVM_CCALL(TVMFuncGetGlobal("tvm.graph_runtime.set_input", (TVMFunctionHandle*)&TVMGraphRuntime_SetInput));
TVM_DLL void tvm_runtime_set_input(void* runtime, const char* name, DLTensor* tensor) {
void (*TVMGraphRuntime_SetInput)(TVMModuleHandle, const char*, DLTensor*);
TVM_CCALL(TVMFuncGetGlobal("tvm.graph_runtime.set_input",
(TVMFunctionHandle*)&TVMGraphRuntime_SetInput));
TVMGraphRuntime_SetInput(runtime, name, tensor);
}

TVM_DLL void tvm_runtime_run(void * runtime) {
TVM_DLL void tvm_runtime_run(void* runtime) {
void (*TVMGraphRuntime_Run)(TVMModuleHandle runtime);
TVM_CCALL(TVMFuncGetGlobal("tvm.graph_runtime.run", (TVMFunctionHandle*)&TVMGraphRuntime_Run));
TVMGraphRuntime_Run(runtime);
}

TVM_DLL void tvm_runtime_get_output(void * runtime, int32_t index, DLTensor * tensor) {
int (*TVMGraphRuntime_GetOutput)(TVMModuleHandle, const int32_t, DLTensor *);
TVM_CCALL(TVMFuncGetGlobal("tvm.graph_runtime.get_output", (TVMFunctionHandle*)&TVMGraphRuntime_GetOutput));
TVM_DLL void tvm_runtime_get_output(void* runtime, int32_t index, DLTensor* tensor) {
int (*TVMGraphRuntime_GetOutput)(TVMModuleHandle, const int32_t, DLTensor*);
TVM_CCALL(TVMFuncGetGlobal("tvm.graph_runtime.get_output",
(TVMFunctionHandle*)&TVMGraphRuntime_GetOutput));
TVMGraphRuntime_GetOutput(runtime, index, tensor);
}

27 changes: 13 additions & 14 deletions apps/bundle_deploy/bundle_static.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,8 @@
#include "bundle.h"
#include "runtime.c"

TVM_DLL void * tvm_runtime_create(const char * json_data,
const char * params_data,
const uint64_t params_size) {
TVM_DLL void* tvm_runtime_create(const char* json_data, const char* params_data,
const uint64_t params_size) {
int64_t device_type = kDLCPU;
int64_t device_id = 0;

Expand All @@ -38,9 +37,9 @@ TVM_DLL void * tvm_runtime_create(const char * json_data,
ctx.device_id = device_id;

// declare pointers
void * (*SystemLibraryCreate)();
TVMGraphRuntime * (*TVMGraphRuntimeCreate)(const char *, const TVMModuleHandle, const TVMContext *);
int (*TVMGraphRuntime_LoadParams)(TVMModuleHandle, const char *, const uint32_t);
void* (*SystemLibraryCreate)();
TVMGraphRuntime* (*TVMGraphRuntimeCreate)(const char*, const TVMModuleHandle, const TVMContext*);
int (*TVMGraphRuntime_LoadParams)(TVMModuleHandle, const char*, const uint32_t);

// get pointers
TVMFuncGetGlobal("runtime.SystemLib", (TVMFunctionHandle*)&SystemLibraryCreate);
Expand All @@ -51,30 +50,30 @@ TVM_DLL void * tvm_runtime_create(const char * json_data,
TVMModuleHandle mod = TVMGraphRuntimeCreate(json_data, mod_syslib, &ctx);
TVMModGetFunction(mod, "load_params", 0, (TVMFunctionHandle*)&TVMGraphRuntime_LoadParams);
TVMGraphRuntime_LoadParams(mod, params.data, params.size);

return mod;
}

TVM_DLL void tvm_runtime_destroy(void * runtime) {
void (*TVMGraphRuntimeRelease)(TVMModuleHandle *);
TVM_DLL void tvm_runtime_destroy(void* runtime) {
void (*TVMGraphRuntimeRelease)(TVMModuleHandle*);
TVMFuncGetGlobal("tvm.graph_runtime.release", (TVMFunctionHandle*)&TVMGraphRuntimeRelease);
TVMGraphRuntimeRelease(&runtime);
}

TVM_DLL void tvm_runtime_set_input(void * runtime, const char * name, DLTensor * tensor) {
void (*TVMGraphRuntime_SetInput)(TVMModuleHandle, const char *, DLTensor*);
TVM_DLL void tvm_runtime_set_input(void* runtime, const char* name, DLTensor* tensor) {
void (*TVMGraphRuntime_SetInput)(TVMModuleHandle, const char*, DLTensor*);
TVMFuncGetGlobal("tvm.graph_runtime.set_input", (TVMFunctionHandle*)&TVMGraphRuntime_SetInput);
TVMGraphRuntime_SetInput(runtime, name, tensor);
}

TVM_DLL void tvm_runtime_run(void * runtime) {
TVM_DLL void tvm_runtime_run(void* runtime) {
void (*TVMGraphRuntime_Run)(TVMModuleHandle runtime);
TVMFuncGetGlobal("tvm.graph_runtime.run", (TVMFunctionHandle*)&TVMGraphRuntime_Run);
TVMGraphRuntime_Run(runtime);
}

TVM_DLL void tvm_runtime_get_output(void * runtime, int32_t index, DLTensor * tensor) {
int (*TVMGraphRuntime_GetOutput)(TVMModuleHandle, const int32_t, DLTensor *);
TVM_DLL void tvm_runtime_get_output(void* runtime, int32_t index, DLTensor* tensor) {
int (*TVMGraphRuntime_GetOutput)(TVMModuleHandle, const int32_t, DLTensor*);
TVMFuncGetGlobal("tvm.graph_runtime.get_output", (TVMFunctionHandle*)&TVMGraphRuntime_GetOutput);
TVMGraphRuntime_GetOutput(runtime, index, tensor);
}
41 changes: 20 additions & 21 deletions apps/bundle_deploy/demo_static.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,35 +17,34 @@
* under the License.
*/

#include <tvm/runtime/c_runtime_api.h>

#include <assert.h>
#include <float.h>
#include <stdio.h>
#include <sys/time.h>
#include <stdlib.h>
#include <float.h>
#include <sys/time.h>
#include <tvm/runtime/c_runtime_api.h>

#include "bundle.h"
#include "build/graph.json.c"
#include "build/params.bin.c"
#include "bundle.h"

#define OUTPUT_LEN 1000
#define OUTPUT_LEN 1000

int main(int argc, char **argv) {
int main(int argc, char** argv) {
assert(argc == 2 && "Usage: demo_static <cat.bin>");

char * json_data = (char *)(build_graph_json);
char * params_data = (char *)(build_params_bin);
char* json_data = (char*)(build_graph_json);
char* params_data = (char*)(build_params_bin);
uint64_t params_size = build_params_bin_len;

struct timeval t0, t1, t2, t3, t4, t5;
gettimeofday(&t0, 0);

void *handle = tvm_runtime_create(json_data, params_data, params_size);
void* handle = tvm_runtime_create(json_data, params_data, params_size);
gettimeofday(&t1, 0);

float input_storage[1 * 3 * 224 * 224];
FILE * fp = fopen(argv[1], "rb");
FILE* fp = fopen(argv[1], "rb");
(void)fread(input_storage, 3 * 224 * 224, 4, fp);
fclose(fp);

Expand All @@ -56,7 +55,7 @@ int main(int argc, char **argv) {
input.ndim = 4;
DLDataType dtype = {kDLFloat, 32, 1};
input.dtype = dtype;
int64_t shape [4] = {1, 3, 224, 224};
int64_t shape[4] = {1, 3, 224, 224};
input.shape = shape;
input.strides = NULL;
input.byte_offset = 0;
Expand Down Expand Up @@ -95,15 +94,15 @@ int main(int argc, char **argv) {
tvm_runtime_destroy(handle);
gettimeofday(&t5, 0);

printf("The maximum position in output vector is: %d, with max-value %f.\n",
max_index, max_iter);
printf("timing: %.2f ms (create), %.2f ms (set_input), %.2f ms (run), "
"%.2f ms (get_output), %.2f ms (destroy)\n",
(t1.tv_sec-t0.tv_sec)*1000 + (t1.tv_usec-t0.tv_usec)/1000.f,
(t2.tv_sec-t1.tv_sec)*1000 + (t2.tv_usec-t1.tv_usec)/1000.f,
(t3.tv_sec-t2.tv_sec)*1000 + (t3.tv_usec-t2.tv_usec)/1000.f,
(t4.tv_sec-t3.tv_sec)*1000 + (t4.tv_usec-t3.tv_usec)/1000.f,
(t5.tv_sec-t4.tv_sec)*1000 + (t5.tv_usec-t4.tv_usec)/1000.f);
printf("The maximum position in output vector is: %d, with max-value %f.\n", max_index, max_iter);
printf(
"timing: %.2f ms (create), %.2f ms (set_input), %.2f ms (run), "
"%.2f ms (get_output), %.2f ms (destroy)\n",
(t1.tv_sec - t0.tv_sec) * 1000 + (t1.tv_usec - t0.tv_usec) / 1000.f,
(t2.tv_sec - t1.tv_sec) * 1000 + (t2.tv_usec - t1.tv_usec) / 1000.f,
(t3.tv_sec - t2.tv_sec) * 1000 + (t3.tv_usec - t2.tv_usec) / 1000.f,
(t4.tv_sec - t3.tv_sec) * 1000 + (t4.tv_usec - t3.tv_usec) / 1000.f,
(t5.tv_sec - t4.tv_sec) * 1000 + (t5.tv_usec - t4.tv_usec) / 1000.f);

return 0;
}
4 changes: 2 additions & 2 deletions apps/bundle_deploy/runtime.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@
/*! \brief Page size for virtual memory allocation */
#define TVM_CRT_PAGE_BYTES 4096

#include "../../src/runtime/crt/crt_runtime_api.c"
#include "../../src/runtime/crt/crt_backend_api.c"
#include "../../src/runtime/crt/crt_runtime_api.c"
#include "../../src/runtime/crt/graph_runtime.c"
#include "../../src/runtime/crt/load_json.c"
#include "../../src/runtime/crt/ndarray.c"
#include "../../src/runtime/crt/memory.c"
#include "../../src/runtime/crt/ndarray.c"
33 changes: 16 additions & 17 deletions apps/bundle_deploy/test_static.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,25 @@
* under the License.
*/

#include <tvm/runtime/c_runtime_api.h>

#include <assert.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <sys/time.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <tvm/runtime/c_runtime_api.h>

#include "bundle.h"


int main(int argc, char **argv) {
int main(int argc, char** argv) {
assert(argc == 5 && "Usage: test_static <data.bin> <output.bin> <graph.json> <params.bin>");

struct stat st;
char * json_data;
char * params_data;
char* json_data;
char* params_data;
uint64_t params_size;

FILE * fp = fopen(argv[3], "rb");
FILE* fp = fopen(argv[3], "rb");
stat(argv[3], &st);
json_data = (char*)malloc(st.st_size);
fread(json_data, st.st_size, 1, fp);
Expand All @@ -53,7 +51,7 @@ int main(int argc, char **argv) {
struct timeval t0, t1, t2, t3, t4, t5;
gettimeofday(&t0, 0);

auto *handle = tvm_runtime_create(json_data, params_data, params_size);
auto* handle = tvm_runtime_create(json_data, params_data, params_size);
gettimeofday(&t1, 0);

float input_storage[10 * 5];
Expand Down Expand Up @@ -110,13 +108,14 @@ int main(int argc, char **argv) {
tvm_runtime_destroy(handle);
gettimeofday(&t5, 0);

printf("timing: %.2f ms (create), %.2f ms (set_input), %.2f ms (run), "
"%.2f ms (get_output), %.2f ms (destroy)\n",
(t1.tv_sec-t0.tv_sec)*1000 + (t1.tv_usec-t0.tv_usec)/1000.f,
(t2.tv_sec-t1.tv_sec)*1000 + (t2.tv_usec-t1.tv_usec)/1000.f,
(t3.tv_sec-t2.tv_sec)*1000 + (t3.tv_usec-t2.tv_usec)/1000.f,
(t4.tv_sec-t3.tv_sec)*1000 + (t4.tv_usec-t3.tv_usec)/1000.f,
(t5.tv_sec-t4.tv_sec)*1000 + (t5.tv_usec-t4.tv_usec)/1000.f);
printf(
"timing: %.2f ms (create), %.2f ms (set_input), %.2f ms (run), "
"%.2f ms (get_output), %.2f ms (destroy)\n",
(t1.tv_sec - t0.tv_sec) * 1000 + (t1.tv_usec - t0.tv_usec) / 1000.f,
(t2.tv_sec - t1.tv_sec) * 1000 + (t2.tv_usec - t1.tv_usec) / 1000.f,
(t3.tv_sec - t2.tv_sec) * 1000 + (t3.tv_usec - t2.tv_usec) / 1000.f,
(t4.tv_sec - t3.tv_sec) * 1000 + (t4.tv_usec - t3.tv_usec) / 1000.f,
(t5.tv_sec - t4.tv_sec) * 1000 + (t5.tv_usec - t4.tv_usec) / 1000.f);

free(json_data);
free(params_data);
Expand Down
Loading

0 comments on commit c98c22f

Please sign in to comment.