# Profile mlc\_chat\_cli on android phone

**URL:** <https://discuss.tvm.apache.org/t/profile-mlc-chat-cli-on-android-phone/16506>\
**Category:** Uncategorized\
**Created:** [March 13, 2024, 6:44am UTC](https://discuss.tvm.apache.org/t/profile-mlc-chat-cli-on-android-phone/16506 "2024-03-13T06:44:50Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![yige0617](https://discuss.tvm.apache.org/letter_avatar_proxy/v4/letter/y/b782af/32.png) [@yige0617](https://discuss.tvm.apache.org/u/yige0617)\
**Post date:** [March 13, 2024, 6:44am UTC](https://discuss.tvm.apache.org/t/profile-mlc-chat-cli-on-android-phone/16506/1 "2024-03-13T06:44:50Z")

</div>

I tried to do per op profiling on android phone for mlc-chat. I add following code tvm::Device gpu; gpu.device\_type = kDLOpenCL; int device\_type = gpu.device\_type; gpu.device\_id = device\_id; std::ifstream loaded\_json(model.config); std::string json\_data((std::istreambuf\_iterator(loaded\_json)), std::istreambuf\_iterator()); loaded\_json.close(); std::string lib\_path\_string = model.lib.parent\_path().string(); std::string model\_path\_string = model.config.string(); std::cout \<\<"model\_path\_string "\<\<model\_path\_string\<\<std::endl; tvm::runtime::Module loaded\_lib = tvm::runtime::Module::LoadFromFile(lib\_path); tvm::runtime::Module executor = (\*tvm::runtime::Registry::Get(“tvm.graph\_executor\_debug.create”))(json\_data, loaded\_lib, device\_type, gpu.device\_id); tvm::runtime::PackedFunc profile = executor.GetFunction(“profile”);

But I don’t know where I should **get model json file** , initially, I thought it is mlc-chat-config.json, I realized it means network json. Could you tell me how to dump the json file? This my first time on TVM, it might be very trivial questions. Thanks.

---

<div class="post-metadata">

**Author:** ![srkreddy1238](https://discuss.tvm.apache.org/user_avatar/discuss.tvm.apache.org/srkreddy1238/32/3518_2.png) [@srkreddy1238](https://discuss.tvm.apache.org/u/srkreddy1238)\
**Post date:** [March 14, 2024, 10:53am UTC](https://discuss.tvm.apache.org/t/profile-mlc-chat-cli-on-android-phone/16506/2 "2024-03-14T10:53:57Z")

</div>

MLC uses vm executor(not graph executor).

Both of them ends up in opencl runtime and the OpenCL kernel launch/enqueu happens at

> <https://github.com/apache/tvm/blob/c00cc031de929ba04f46689bb42ced1a3a44d3ef/src/runtime/opencl/opencl_module.cc#L85>

You may try using OpenCL profiling using events here.

Also, you might need to enabled opencl profiling while creating queue at

> <https://github.com/apache/tvm/blob/695f958bc9ef40e625a84ad9355df2e75e6498a0/src/runtime/opencl/opencl_device_api.cc#L541>

---

<div class="post-metadata">

**Author:** ![yige0617](https://discuss.tvm.apache.org/letter_avatar_proxy/v4/letter/y/b782af/32.png) [@yige0617](https://discuss.tvm.apache.org/u/yige0617)\
**Post date:** [March 14, 2024, 6:45pm UTC](https://discuss.tvm.apache.org/t/profile-mlc-chat-cli-on-android-phone/16506/3 "2024-03-14T18:45:47Z")

</div>

@srkreddy1238 really appreciated for your reply, I tried to profile it on per Op based. Any feedback how to do it?
