Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,15 @@ if(MLLM_BUILD_SDK_C_BINDING)
RUNTIME DESTINATION bin)
endif()

if(MLLM_TRACY_ENABLE)
install(
TARGETS MllmTracy
EXPORT MllmTargets
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
RUNTIME DESTINATION bin)
endif()

install(
DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/mllm/
DESTINATION include/mllm
Expand Down
1 change: 1 addition & 0 deletions mllm/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ endif()

if(MLLM_TRACY_ENABLE)
add_subdirectory(tracy_perf)
target_link_libraries(MllmRT PUBLIC MllmTracy)
endif()

# Host backend will be build by default
Expand Down
11 changes: 10 additions & 1 deletion mllm/backends/cpu/CPUAllocator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include "mllm/backends/cpu/CPUAllocator.hpp"
#include "mllm/backends/cpu/kernels/Kernels.hpp"
#include "mllm/tracy_perf/Tracy.hpp"

namespace mllm::cpu {

Expand All @@ -18,12 +19,20 @@ void align_alloc(void** ptr, size_t required_bytes, size_t align) {
*ptr = nullptr;
return;
}
#if defined(MLLM_TRACY_ENABLE) && MLLM_TRACY_ENABLE == 1
TracyAlloc(p1, required_bytes + offset);
#endif
p2 = (void**)(((size_t)(p1) + offset) & ~(align - 1)); // NOLINT
p2[-1] = p1;
*ptr = p2;
}

void align_free(void* ptr) { free(((void**)ptr)[-1]); }
void align_free(void* ptr) {
#if defined(MLLM_TRACY_ENABLE) && MLLM_TRACY_ENABLE == 1
TracyFree(((void**)ptr)[-1]);
#endif
free(((void**)ptr)[-1]);
}
Comment thread
chenghuaWang marked this conversation as resolved.

bool CPUAllocator::alloc(Storage* storage) {
void* ptr;
Expand Down
2 changes: 2 additions & 0 deletions mllm/backends/cpu/CPUDispatcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "mllm/engine/Dispatcher.hpp"
#include "mllm/utils/Common.hpp"
#include "mllm/nn/Module.hpp"
#include "mllm/tracy_perf/Tracy.hpp"

#ifdef MLLM_PERFETTO_ENABLE
#include "mllm/engine/Perf.hpp"
Expand Down Expand Up @@ -39,6 +40,7 @@ TaskResult::sender_t CPUDispatcher::asyncReceive(const Task::ptr_t& task) {
}

void CPUDispatcher::process(const Task::ptr_t& task) {
MLLM_TRACY_ZONE_SCOPED;
switch (task->type) {
case TaskTypes::kExecuteOp: {
#ifdef MLLM_PERFETTO_ENABLE
Expand Down
2 changes: 2 additions & 0 deletions mllm/engine/Context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "mllm/engine/Context.hpp"
#include "mllm/engine/SessionTCB.hpp"
#include "mllm/engine/DispatcherManager.hpp"
#include "mllm/tracy_perf/Tracy.hpp"

namespace mllm {

Expand Down Expand Up @@ -42,6 +43,7 @@ Backend::ptr_t Context::getBackend(const DeviceTypes& device) {

std::vector<Tensor> Context::buildOpAndSubmitTask(OpTypes op_type, const BaseOpOptionsBase& base_options,
const std::vector<Tensor>& inputs, DeviceTypes special_device) {
MLLM_TRACY_ZONE_SCOPED;
auto device = special_device != kDeviceTypes_End ? special_device : inputs[0].device();

// If input device and special device are different, prefer non-CPU device
Expand Down
6 changes: 5 additions & 1 deletion mllm/engine/DispatcherManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "exec/static_thread_pool.hpp"
#include "mllm/utils/Common.hpp"
#include "mllm/engine/Context.hpp"
#include "mllm/tracy_perf/Tracy.hpp"

namespace mllm {

Expand All @@ -14,7 +15,10 @@ DispatcherManager::DispatcherManager(const DispatcherManagerOptions& options)
exec::numa_policy numa{exec::no_numa_policy{}};
}

void DispatcherManager::submit(dispatcher_id_t id, const Task::ptr_t& task) { dispatchers_[id]->receive(task); }
void DispatcherManager::submit(dispatcher_id_t id, const Task::ptr_t& task) {
MLLM_TRACY_ZONE_SCOPED;
dispatchers_[id]->receive(task);
}

TaskResult::sender_t DispatcherManager::asyncSubmit(dispatcher_id_t id, const Task::ptr_t& task) {
return dispatchers_[id]->asyncReceive(task);
Expand Down
3 changes: 3 additions & 0 deletions mllm/engine/MemoryManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include "mllm/utils/Common.hpp"
#include "mllm/engine/MemoryManager.hpp"
#include "mllm/tracy_perf/Tracy.hpp"

#ifdef MLLM_PERFETTO_ENABLE
#include "mllm/engine/Perf.hpp"
Expand All @@ -25,6 +26,7 @@ void MemoryManager::registerAllocator(const DeviceTypes& device, const Allocator
}

void MemoryManager::alloc(Storage* s) {
MLLM_TRACY_ZONE_SCOPED;
auto& allocator = allocators_[s->device_];
auto try_to_alloc_size = allocator->allocSize(s);

Expand Down Expand Up @@ -58,6 +60,7 @@ void MemoryManager::alloc(Storage* s) {
void MemoryManager::alloc(const std::shared_ptr<Storage>& s) { alloc(s.get()); }

void MemoryManager::free(Storage* s) {
MLLM_TRACY_ZONE_SCOPED;
auto& allocator = allocators_[s->device_];
auto try_to_alloc_size = allocator->allocSize(s);

Expand Down
3 changes: 2 additions & 1 deletion mllm/tracy_perf/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
if(MLLM_TRACY_ENABLE)
add_library(MllmTracy SHARED Tracy.cpp)
target_link_libraries(MllmTracy PUBLIC tracy)
target_link_libraries(MllmTracy PUBLIC Tracy::TracyClient)
target_include_directories(MllmTracy PUBLIC ${MLLM_INCLUDE_DIR})
target_compile_definitions(MllmTracy PUBLIC MLLM_TRACY_ENABLE)
endif()
7 changes: 5 additions & 2 deletions mllm/tracy_perf/Tracy.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright (c) MLLM Team.
// Licensed under the MIT License.

#ifdef MLLM_TRACY_ENABLE
#include "tracy/Tracy.cpp"
#endif
#include "mllm/tracy_perf/Tracy.hpp"
#endif
10 changes: 5 additions & 5 deletions mllm/tracy_perf/Tracy.hpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#ifndef MLLM_TRACY_HPP
#define MLLM_TRACY_HPP
// Copyright (c) MLLM Team.
// Licensed under the MIT License.

#pragma once

#ifdef MLLM_TRACY_ENABLE
#include "tracy/Tracy.hpp"
#include <tracy/Tracy.hpp>
#define MLLM_TRACY_ZONE_SCOPED ZoneScoped
#define MLLM_TRACY_ZONE_SCOPED_NAMED(name) ZoneScopedN(name)
#define MLLM_TRACY_FRAME_MARK FrameMark
Expand All @@ -11,5 +13,3 @@
#define MLLM_TRACY_ZONE_SCOPED_NAMED(name)
#define MLLM_TRACY_FRAME_MARK
#endif

#endif // MLLM_TRACY_HPP
1 change: 1 addition & 0 deletions tasks/build_osx_apple_silicon_accelerate.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Tasks:
- "-DMLLM_KERNEL_USE_THREADS=ON"
- "-DMLLM_KERNEL_THREADS_VENDOR_OPENMP=OFF"
- "-DMLLM_KERNEL_THREADS_VENDOR_APPLE_GCD=ON"
- "-DMLLM_TRACY_ENABLE=OFF"

- CMakeBuildTask:
cmake_cfg_path: "build-osx-accelerate"