diff --git a/projects/clr/hipamd/src/hip_intercept.cpp b/projects/clr/hipamd/src/hip_intercept.cpp index bac8e40caf..e20f1e59ca 100644 --- a/projects/clr/hipamd/src/hip_intercept.cpp +++ b/projects/clr/hipamd/src/hip_intercept.cpp @@ -51,5 +51,5 @@ const char* hipApiName(uint32_t id) { return hip_api_name(id); } extern "C" void hipRegisterTracerCallback(int (*function)(activity_domain_t domain, uint32_t operation_id, void* data)) { - activity_prof::report_activity.store(function, std::memory_order_relaxed); + amd::activity_prof::report_activity.store(function, std::memory_order_relaxed); } diff --git a/projects/clr/hipamd/src/hip_prof_api.h b/projects/clr/hipamd/src/hip_prof_api.h index f85d1a8756..14a018f0b1 100644 --- a/projects/clr/hipamd/src/hip_prof_api.h +++ b/projects/clr/hipamd/src/hip_prof_api.h @@ -50,9 +50,11 @@ template class api_callbacks_spawner_t { static_assert(operation_id >= HIP_API_ID_FIRST && operation_id <= HIP_API_ID_LAST, "invalid HIP_API operation id"); - if (auto function = activity_prof::report_activity.load(std::memory_order_relaxed); function && - (enabled_ = function(ACTIVITY_DOMAIN_HIP_API, operation_id, &trace_data_) == 0)) { - activity_prof::correlation_id = trace_data_.api_data.correlation_id; + if (auto function = + amd::activity_prof::report_activity.load(std::memory_order_relaxed); + function && (enabled_ = function(ACTIVITY_DOMAIN_HIP_API, operation_id, + &trace_data_) == 0)) { + amd::activity_prof::correlation_id = trace_data_.api_data.correlation_id; if (trace_data_.phase_enter != nullptr) { init_cb_args_data(trace_data_.api_data); @@ -64,7 +66,7 @@ template class api_callbacks_spawner_t { ~api_callbacks_spawner_t() { if (enabled_) { if (trace_data_.phase_exit != nullptr) trace_data_.phase_exit(operation_id, &trace_data_); - activity_prof::correlation_id = 0; + amd::activity_prof::correlation_id = 0; } } diff --git a/projects/clr/rocclr/device/devhcmessages.cpp b/projects/clr/rocclr/device/devhcmessages.cpp index f654958224..53fe6054a0 100644 --- a/projects/clr/rocclr/device/devhcmessages.cpp +++ b/projects/clr/rocclr/device/devhcmessages.cpp @@ -25,6 +25,7 @@ #include "devhcmessages.hpp" #include +namespace amd { enum { DESCRIPTOR_OFFSET_FLAG_BEGIN = 0, @@ -133,9 +134,9 @@ void MessageHandler::discardMessage(Message* message) { } // Defined in devhcprintf.cpp -namespace amd { + void handlePrintf(uint64_t* output, const uint64_t* input, uint64_t len); -} // namespace amd + bool MessageHandler::handlePayload(uint32_t service, uint64_t* payload) { Message* message = nullptr; @@ -178,3 +179,4 @@ bool MessageHandler::handlePayload(uint32_t service, uint64_t* payload) { discardMessage(message); return true; } +} // namespace amd \ No newline at end of file diff --git a/projects/clr/rocclr/device/devhcmessages.hpp b/projects/clr/rocclr/device/devhcmessages.hpp index 13f7cddbae..b61ff4408c 100644 --- a/projects/clr/rocclr/device/devhcmessages.hpp +++ b/projects/clr/rocclr/device/devhcmessages.hpp @@ -66,6 +66,8 @@ #include +namespace amd { + enum ServiceID { SERVICE_RESERVED = 0, SERVICE_FUNCTION_CALL = 1, @@ -92,3 +94,4 @@ class MessageHandler { ~MessageHandler(); bool handlePayload(uint32_t service, uint64_t* payload); }; +}// namespace amd \ No newline at end of file diff --git a/projects/clr/rocclr/device/devhostcall.cpp b/projects/clr/rocclr/device/devhostcall.cpp index c924fad8be..99da349697 100644 --- a/projects/clr/rocclr/device/devhostcall.cpp +++ b/projects/clr/rocclr/device/devhostcall.cpp @@ -42,6 +42,8 @@ #endif #endif +namespace amd { + PacketHeader* HostcallBuffer::getHeader(uint64_t ptr) const { return headers_ + (ptr & index_mask_); } @@ -459,3 +461,4 @@ void disableHostcalls(void* bfr) { ClPrint(amd::LOG_INFO, amd::LOG_INIT, "Terminated hostcall listener"); } } +}// namespace amd diff --git a/projects/clr/rocclr/device/devhostcall.hpp b/projects/clr/rocclr/device/devhostcall.hpp index f529c10207..93b05291af 100644 --- a/projects/clr/rocclr/device/devhostcall.hpp +++ b/projects/clr/rocclr/device/devhostcall.hpp @@ -30,6 +30,9 @@ #include "device/devurilocator.hpp" #endif #endif + +namespace amd { + /** \file Support for invoking host services from the device. * * A hostcall is a fixed-size request generated by a kernel running @@ -175,3 +178,5 @@ class HostcallBuffer { static_assert(std::is_standard_layout::value, "the hostcall buffer must be useable from other languages"); + +}// namespace amd \ No newline at end of file diff --git a/projects/clr/rocclr/device/pal/palvirtual.cpp b/projects/clr/rocclr/device/pal/palvirtual.cpp index f50e94e368..2fd822e73c 100644 --- a/projects/clr/rocclr/device/pal/palvirtual.cpp +++ b/projects/clr/rocclr/device/pal/palvirtual.cpp @@ -1155,7 +1155,7 @@ VirtualGPU::~VirtualGPU() { ClPrint(amd::LOG_INFO, amd::LOG_QUEUE, "deleting hostcall buffer %p for virtual queue %p", hostcallBuffer_, this); - disableHostcalls(hostcallBuffer_); + amd::disableHostcalls(hostcallBuffer_); dev().svmFree(hostcallBuffer_); } } @@ -3775,8 +3775,8 @@ void* VirtualGPU::getOrCreateHostcallBuffer() { auto wavesPerCu = dev().info().maxThreadsPerCU_ / dev().info().wavefrontWidth_; auto numPackets = dev().info().maxComputeUnits_ * wavesPerCu; - auto size = getHostcallBufferSize(numPackets); - auto align = getHostcallBufferAlignment(); + auto size = amd::getHostcallBufferSize(numPackets); + auto align = amd::getHostcallBufferAlignment(); hostcallBuffer_ = dev().svmAlloc(dev().context(), size, align, CL_MEM_SVM_FINE_GRAIN_BUFFER | CL_MEM_SVM_ATOMICS, nullptr); @@ -3794,7 +3794,7 @@ void* VirtualGPU::getOrCreateHostcallBuffer() { align, this); - if (!enableHostcalls(dev(), hostcallBuffer_, numPackets)) { + if (!amd::enableHostcalls(dev(), hostcallBuffer_, numPackets)) { ClPrint(amd::LOG_ERROR, amd::LOG_QUEUE, "Failed to register hostcall buffer %p with listener", hostcallBuffer_); diff --git a/projects/clr/rocclr/device/rocm/roccounters.cpp b/projects/clr/rocclr/device/rocm/roccounters.cpp index 4b7b6c4ef4..b56452f5af 100644 --- a/projects/clr/rocclr/device/rocm/roccounters.cpp +++ b/projects/clr/rocclr/device/rocm/roccounters.cpp @@ -22,6 +22,7 @@ #include "device/rocm/rocvirtual.hpp" #include +namespace roc { hsa_status_t PerfCounterCallback( hsa_ven_amd_aqlprofile_info_type_t info_type, @@ -37,9 +38,6 @@ hsa_status_t PerfCounterCallback( return HSA_STATUS_SUCCESS; } - -namespace roc { - /* Converting from ORCA cmndefs.h to ROCR hsa_ven_amd_aqlprofile.h Note that some blocks are not defined in cmndefs.h diff --git a/projects/clr/rocclr/device/rocm/rocdevice.cpp b/projects/clr/rocclr/device/rocm/rocdevice.cpp index 67d72dbd68..2c5d041de9 100644 --- a/projects/clr/rocclr/device/rocm/rocdevice.cpp +++ b/projects/clr/rocclr/device/rocm/rocdevice.cpp @@ -274,7 +274,7 @@ Device::~Device() { if (qInfo.hostcallBuffer_) { ClPrint(amd::LOG_INFO, amd::LOG_QUEUE, "Deleting hostcall buffer %p for hardware queue %p", qInfo.hostcallBuffer_, qIter->first->base_address); - disableHostcalls(qInfo.hostcallBuffer_); + amd::disableHostcalls(qInfo.hostcallBuffer_); context().svmFree(qInfo.hostcallBuffer_); } ClPrint(amd::LOG_INFO, amd::LOG_QUEUE, "Deleting hardware queue %p with refCount 0", @@ -301,7 +301,7 @@ Device::~Device() { delete[] p2p_agents_list_; if (coopHostcallBuffer_) { - disableHostcalls(coopHostcallBuffer_); + amd::disableHostcalls(coopHostcallBuffer_); context().svmFree(coopHostcallBuffer_); coopHostcallBuffer_ = nullptr; } @@ -3248,8 +3248,8 @@ void* Device::getOrCreateHostcallBuffer(hsa_queue_t* queue, bool coop_queue, auto wavesPerCu = info().maxThreadsPerCU_ / info().wavefrontWidth_; auto numPackets = info().maxComputeUnits_ * wavesPerCu; - auto size = getHostcallBufferSize(numPackets); - auto align = getHostcallBufferAlignment(); + auto size = amd::getHostcallBufferSize(numPackets); + auto align = amd::getHostcallBufferAlignment(); void* buffer = context().svmAlloc(size, align, CL_MEM_SVM_FINE_GRAIN_BUFFER | CL_MEM_SVM_ATOMICS); if (!buffer) { @@ -3264,7 +3264,7 @@ void* Device::getOrCreateHostcallBuffer(hsa_queue_t* queue, bool coop_queue, } else { coopHostcallBuffer_ = buffer; } - if (!enableHostcalls(*this, buffer, numPackets)) { + if (!amd::enableHostcalls(*this, buffer, numPackets)) { ClPrint(amd::LOG_ERROR, amd::LOG_QUEUE, "Failed to register hostcall buffer %p with listener", buffer); return nullptr; diff --git a/projects/clr/rocclr/device/rocm/rocvirtual.cpp b/projects/clr/rocclr/device/rocm/rocvirtual.cpp index c56d79678e..e604b7619c 100644 --- a/projects/clr/rocclr/device/rocm/rocvirtual.cpp +++ b/projects/clr/rocclr/device/rocm/rocvirtual.cpp @@ -192,7 +192,7 @@ bool HsaAmdSignalHandler(hsa_signal_value_t value, void* arg) { return false; } - if (activity_prof::IsEnabled(OP_ID_DISPATCH)) { + if (amd::activity_prof::IsEnabled(OP_ID_DISPATCH)) { amd::Command* head = ts->getParsedCommand(); if (head == nullptr) { head = ts->command().GetBatchHead(); @@ -871,7 +871,7 @@ bool VirtualGPU::dispatchGenericAqlPacket( if (std::is_same::value) { // If profiling is enabled, store the correlation ID in the dispatch packet. The profiler can // retrieve this correlation ID to attribute waves to specific dispatch locations. - if (activity_prof::IsEnabled(OP_ID_DISPATCH)) { + if (amd::activity_prof::IsEnabled(OP_ID_DISPATCH)) { auto dispatchPacket = reinterpret_cast(packet); dispatchPacket->reserved2 = timestamp_->command().profilingInfo().correlation_id_; } diff --git a/projects/clr/rocclr/platform/activity.cpp b/projects/clr/rocclr/platform/activity.cpp index 518bca55e8..2f9bed578b 100644 --- a/projects/clr/rocclr/platform/activity.cpp +++ b/projects/clr/rocclr/platform/activity.cpp @@ -25,7 +25,7 @@ #include -namespace activity_prof { +namespace amd::activity_prof { decltype(report_activity) report_activity{nullptr}; @@ -122,7 +122,7 @@ void ReportActivity(const amd::Command& command) { } } -} // namespace activity_prof +} // namespace amd::activity_prof #define CASE_STRING(X, C) \ case X: \ diff --git a/projects/clr/rocclr/platform/activity.hpp b/projects/clr/rocclr/platform/activity.hpp index 873e48a7b2..7dbd0adef6 100644 --- a/projects/clr/rocclr/platform/activity.hpp +++ b/projects/clr/rocclr/platform/activity.hpp @@ -36,7 +36,7 @@ enum OpId { OP_ID_DISPATCH = 0, OP_ID_COPY = 1, OP_ID_BARRIER = 2, OP_ID_NUMBER #include "prof_protocol.h" -namespace activity_prof { +namespace amd::activity_prof { extern std::atomic report_activity; @@ -76,6 +76,6 @@ constexpr OpId OperationId(cl_command_type commandType) { bool IsEnabled(OpId operation_id); void ReportActivity(const amd::Command& command); -} // namespace activity_prof +} // namespace amd::activity_prof const char* getOclCommandKindString(cl_command_type kind); diff --git a/projects/clr/rocclr/platform/command.cpp b/projects/clr/rocclr/platform/command.cpp index 068652e529..7424279ac8 100644 --- a/projects/clr/rocclr/platform/command.cpp +++ b/projects/clr/rocclr/platform/command.cpp @@ -150,8 +150,8 @@ bool Event::setStatus(int32_t status, uint64_t timeStamp) { releaseResources(); } - if (profilingInfo().enabled_ && activity_prof::IsEnabled(OP_ID_DISPATCH)) { - activity_prof::ReportActivity(command()); + if (profilingInfo().enabled_ && amd::activity_prof::IsEnabled(OP_ID_DISPATCH)) { + amd::activity_prof::ReportActivity(command()); } // Broadcast all the waiters. @@ -303,7 +303,7 @@ const Event::EventWaitList Event::nullWaitList(0); Command::Command(HostQueue& queue, cl_command_type type, const EventWaitList& eventWaitList, uint32_t commandWaitBits, const Event* waitingEvent) : Event(queue, - activity_prof::IsEnabled(activity_prof::OperationId(type)) || + amd::activity_prof::IsEnabled(amd::activity_prof::OperationId(type)) || queue.properties().test(CL_QUEUE_PROFILING_ENABLE) || Agent::shouldPostEventEvents()), queue_(&queue), diff --git a/projects/clr/rocclr/platform/command.hpp b/projects/clr/rocclr/platform/command.hpp index aec5417e30..03ecaaf4c8 100644 --- a/projects/clr/rocclr/platform/command.hpp +++ b/projects/clr/rocclr/platform/command.hpp @@ -102,7 +102,7 @@ class Event : public RuntimeObject { : enabled_(enabled), marker_ts_(false) { if (enabled) { clear(); - correlation_id_ = activity_prof::correlation_id; + correlation_id_ = amd::activity_prof::correlation_id; } } @@ -148,7 +148,7 @@ class Event : public RuntimeObject { void EnableProfiling() { profilingInfo_.enabled_ = true; profilingInfo_.clear(); - profilingInfo_.correlation_id_ = activity_prof::correlation_id; + profilingInfo_.correlation_id_ = amd::activity_prof::correlation_id; } public: diff --git a/projects/clr/rocclr/platform/memory.cpp b/projects/clr/rocclr/platform/memory.cpp index 1242ccd15d..d26b6c802e 100644 --- a/projects/clr/rocclr/platform/memory.cpp +++ b/projects/clr/rocclr/platform/memory.cpp @@ -28,11 +28,11 @@ #include +namespace amd { + // Stores the no. of memory allocations std::atomic numAllocs = {0}; -namespace amd { - bool BufferRect::create(const size_t* bufferOrigin, const size_t* region, size_t bufferRowPitch, size_t bufferSlicePitch) { bool valid = false; diff --git a/projects/clr/rocclr/utils/debug.cpp b/projects/clr/rocclr/utils/debug.cpp index 1c1dfd355b..92cb5bc813 100644 --- a/projects/clr/rocclr/utils/debug.cpp +++ b/projects/clr/rocclr/utils/debug.cpp @@ -40,15 +40,6 @@ namespace amd { FILE* outFile = stderr; -// ================================================================================================ -//! \cond ignore -extern "C" void breakpoint(void) { -#ifdef _MSC_VER - DebugBreak(); -#endif // _MSC_VER -} -//! \endcond - // ================================================================================================ void report_warning(const char* message) { fprintf(outFile, "Warning: %s\n", message); } diff --git a/projects/clr/rocclr/utils/debug.hpp b/projects/clr/rocclr/utils/debug.hpp index 1fa864c1e5..8e21d6c981 100644 --- a/projects/clr/rocclr/utils/debug.hpp +++ b/projects/clr/rocclr/utils/debug.hpp @@ -64,10 +64,6 @@ enum LogMask { //! \brief log file output extern FILE* outFile; -//! \cond ignore -extern "C" void breakpoint(); -//! \endcond - //! \brief Display a warning message. extern void report_warning(const char* message);