summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (from parent 1: c96fc79)
raw | patch | inline | side by side (from parent 1: c96fc79)
author | Ajay Jayaraj <ajayj@ti.com> | |
Mon, 13 Aug 2018 17:30:40 +0000 (12:30 -0500) | ||
committer | Ajay Jayaraj <ajayj@ti.com> | |
Mon, 13 Aug 2018 18:07:43 +0000 (13:07 -0500) |
Implementation details such as argument kind and PipeInfo should not be
a part of the user facing ArgInfo class. Also, PipeInfo is relevant only
for input/output arguments.
Moved implementation details out of ArgInfo and created 2 new classes:
DeviceArgInfo and IODeviceArgInfo.
DeviceArgInfo inherits from ArgInfo and adds an
argument kind (buffer, local or scalar). IODeviceArgInfo consists of
DeviceArgInfo and PipeInfo.
(MCT-1030)
a part of the user facing ArgInfo class. Also, PipeInfo is relevant only
for input/output arguments.
Moved implementation details out of ArgInfo and created 2 new classes:
DeviceArgInfo and IODeviceArgInfo.
DeviceArgInfo inherits from ArgInfo and adds an
argument kind (buffer, local or scalar). IODeviceArgInfo consists of
DeviceArgInfo and PipeInfo.
(MCT-1030)
examples/Makefile | patch | blob | history | |
examples/make.common | patch | blob | history | |
tidl_api/Makefile | patch | blob | history | |
tidl_api/inc/execution_object.h | patch | blob | history | |
tidl_api/inc/executor.h | patch | blob | history | |
tidl_api/src/device_arginfo.h | [new file with mode: 0644] | patch | blob |
tidl_api/src/execution_object.cpp | patch | blob | history | |
tidl_api/src/executor.cpp | patch | blob | history | |
tidl_api/src/ocl_device.cpp | patch | blob | history | |
tidl_api/src/ocl_device.h | patch | blob | history |
diff --git a/examples/Makefile b/examples/Makefile
index 69c708600066f1dbd22ac98d8b7a7552ddba0dda..cf3bbc3dc68ae8306a41bf5244d8e352bc408f81 100644 (file)
--- a/examples/Makefile
+++ b/examples/Makefile
all:
$(call make_in_dirs, $(DIRS), )
+.PHONY: run
+run:
+ $(call make_in_dirs, $(DIRS), run)
+
.PHONY: clean
clean:
$(call make_in_dirs, $(DIRS), clean)
diff --git a/examples/make.common b/examples/make.common
index e0111173572380e0ddc4c2c2ec0419829204ce25..87a4f3130a1fe5a10d22033b18a22d4a80f1163b 100644 (file)
--- a/examples/make.common
+++ b/examples/make.common
clean::
$(RM) -f $(EXE) stats_tool_out.* *.out
+run:
+ ./$(EXE)
diff --git a/tidl_api/Makefile b/tidl_api/Makefile
index bc0a416c398f5dc6543ac314ed5eff75bee127eb..05a3704af885d2f055b38b0f5f74c92748a485eb 100644 (file)
--- a/tidl_api/Makefile
+++ b/tidl_api/Makefile
HEADERS = src/common_defines.h src/executor_impl.h src/ocl_device.h
HEADERS += src/parameters.h src/tidl_create_params.h src/trace.h src/util.h
HEADERS += inc/configuration.h inc/execution_object.h inc/executor.h
-HEADERS += inc/imgutil.h
+HEADERS += inc/imgutil.h src/device_arginfo.h
ifeq ($(BUILD), debug)
index bd4a0717f9a1d155360a8a91810f2d4e57c3e28d..ccc088180dd975e92e79e2e01ee0ce3f55873996 100644 (file)
class LayerOutput
{
public:
+ //! @private
+ //! Constructor called within API, not by the user
LayerOutput(int layer_index, int output_index, int buffer_id,
int num_roi_m, int num_channels, size_t height,
size_t width, const char* data);
+
+ //! Must be called to delete the data pointer.
~LayerOutput();
+ //! @return The index of a layer
int LayerIndex() const { return layer_index_m; }
+
+ //! @return The number of channels associated with an output
int NumberOfChannels() const { return num_channels_m; }
+
+ //! @return The height of the output. Can be 1 for 1D outputs
size_t Height() const { return height_m; }
+
+ //! @return The width of the output
size_t Width() const { return width_m; }
+
+ //! @return Size of the output in bytes
size_t Size() const { return height_m * width_m *
num_channels_m; }
+ //! @return Pointer to output. Must call destructor to free the
+ //! memory used to hold the output.
const char* Data() const { return data_m; }
+ //! @private Disable copy construction and assignment since
+ //! class holds a pointer to allocated data
+ LayerOutput(const LayerOutput&) = delete;
+ LayerOutput& operator= (const LayerOutput&) = delete;
+
private:
int layer_index_m;
int output_index_m;
index 2b20eaf9b3c5a5acd0238f76e21c776c1b193556..23d92ffef1b2ff815ca3ae23a267e24472dd8b02 100644 (file)
--- a/tidl_api/inc/executor.h
+++ b/tidl_api/inc/executor.h
std::unique_ptr<ExecutorImpl> pimpl_m;
};
-/*! @class PipeInfo
- * @brief Describe input and output required by piping output and input
- * between Execution Objects
- */
-class PipeInfo
-{
- public:
- uint32_t dataQ_m[OCL_TIDL_MAX_IN_BUFS];
- uint32_t bufAddr_m[OCL_TIDL_MAX_IN_BUFS];
-};
-
/*! @class ArgInfo
* @brief Describe input and output buffers required by ExecutionObjects
*/
public:
enum class DeviceAccess { R_ONLY=0, W_ONLY, RW };
- //! Enumerates the types of arguments represented by ArgInfo
- enum class Kind { BUFFER=0, SCALAR };
-
//! Construct an ArgInfo object from a pointer to a chunk of memory
//! and its size.
ArgInfo(void *p, size_t size) :
- ptr_m(p), size_m(size),
- access_m(DeviceAccess::RW), kind_m(Kind::BUFFER)
- { pipe_m = std::make_shared<PipeInfo>(); }
+ ptr_m(p), size_m(size), access_m(DeviceAccess::RW) {}
- //! Construct an ArgInfo object from a pointer to a chunk of memory
- //! its size and kind
- ArgInfo(void *p, size_t size, Kind kind) :
- ptr_m(p), size_m(size), access_m(DeviceAccess::RW), kind_m(kind) {}
+ ArgInfo(const ArgInfo& arg) = default;
+ ArgInfo& operator=(const ArgInfo& arg) = default;
//! @return Pointer to the buffer or scalar represented by ArgInfo
void *ptr() const { return ptr_m; }
//! @return The size of the buffer or scalar represented by ArgInfo
size_t size() const { return size_m; }
- // Only used by tidl::Device
- Kind kind() const { return kind_m; }
- bool isLocal() const { return (ptr_m == nullptr) && (size_m > 0); }
-
- // Only used by tidl::ExecutionObject::Impl
- PipeInfo *GetPipe() const { return pipe_m.get(); }
-
- private:
+ protected:
void* ptr_m;
size_t size_m;
DeviceAccess access_m;
- Kind kind_m;
- std::shared_ptr<PipeInfo> pipe_m;
};
diff --git a/tidl_api/src/device_arginfo.h b/tidl_api/src/device_arginfo.h
--- /dev/null
@@ -0,0 +1,63 @@
+/******************************************************************************
+ * Copyright (c) 2017-2018 Texas Instruments Incorporated - http://www.ti.com/
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * * Neither the name of Texas Instruments Incorporated nor the
+ * names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ *****************************************************************************/
+
+//! @file device_arginfo.h
+
+#pragma once
+
+#include "executor.h"
+
+namespace tidl
+{
+
+/*! @class DeviceArgInfo
+ * @brief Describe input and output buffers required by ExecutionObjects
+ */
+class DeviceArgInfo: public ArgInfo
+{
+ public:
+ //! Enumerates the types of arguments represented by DeviceArgInfo
+ enum class Kind { BUFFER=0, LOCAL, SCALAR };
+
+ //! Construct an DeviceArgInfo object
+ DeviceArgInfo(const ArgInfo& ai, Kind kind) :
+ ArgInfo(ai), kind_m(kind)
+ {}
+
+ DeviceArgInfo(void *p, size_t size, Kind kind) :
+ ArgInfo(p, size), kind_m(kind)
+ {}
+
+ Kind kind() const { return kind_m; }
+ bool isLocal() const { return (ptr_m == nullptr) && (size_m > 0); }
+
+ private:
+ Kind kind_m;
+};
+
+} //namespace
index 6ebf653d46710e9e9828986da257ee90f3053ebf..18237fb276a8eec9d5bae55575b699a594028d19 100644 (file)
using namespace tidl;
+/*! @class PipeInfo
+ * @brief Describe input and output required by piping output and input
+ * between Execution Objects
+ */
+class PipeInfo
+{
+ public:
+ uint32_t dataQ_m[OCL_TIDL_MAX_IN_BUFS];
+ uint32_t bufAddr_m[OCL_TIDL_MAX_IN_BUFS];
+};
+
+
+class IODeviceArgInfo
+{
+ public:
+ IODeviceArgInfo(const ArgInfo& arg):
+ arg_m(arg, DeviceArgInfo::Kind::BUFFER) {} explicit
+
+ IODeviceArgInfo(): arg_m(nullptr, 0, DeviceArgInfo::Kind::BUFFER) {}
+
+ PipeInfo& GetPipe() { return pipe_m; }
+ const DeviceArgInfo& GetArg() const { return arg_m; }
+
+ private:
+ DeviceArgInfo arg_m;
+ PipeInfo pipe_m;
+};
+
class ExecutionObject::Impl
{
public:
Impl(Device* d, uint8_t device_index,
- const ArgInfo& create_arg,
- const ArgInfo& param_heap_arg,
+ const DeviceArgInfo& create_arg,
+ const DeviceArgInfo& param_heap_arg,
size_t extmem_heap_size,
bool internal_input);
~Impl() {}
size_t in_size_m;
size_t out_size_m;
- ArgInfo in_m;
- ArgInfo out_m;
+ IODeviceArgInfo in_m;
+ IODeviceArgInfo out_m;
// Frame being processed by the EO
int current_frame_idx_m;
size_t trace_buf_params_sz_m;
private:
- void SetupInitializeKernel(const ArgInfo& create_arg,
- const ArgInfo& param_heap_arg,
+ void SetupInitializeKernel(const DeviceArgInfo& create_arg,
+ const DeviceArgInfo& param_heap_arg,
size_t extmem_heap_size,
bool internal_input);
void SetupProcessKernel();
size_t extmem_heap_size,
bool internal_input)
{
+ DeviceArgInfo create_arg_d(create_arg, DeviceArgInfo::Kind::BUFFER);
+ DeviceArgInfo param_heap_arg_d(param_heap_arg, DeviceArgInfo::Kind::BUFFER);
+
pimpl_m = std::unique_ptr<ExecutionObject::Impl>
{ new ExecutionObject::Impl(d, device_index,
- create_arg,
- param_heap_arg,
+ create_arg_d,
+ param_heap_arg_d,
extmem_heap_size,
internal_input) };
}
ExecutionObject::Impl::Impl(Device* d,
uint8_t device_index,
- const ArgInfo& create_arg,
- const ArgInfo& param_heap_arg,
+ const DeviceArgInfo& create_arg,
+ const DeviceArgInfo& param_heap_arg,
size_t extmem_heap_size,
bool internal_input):
device_m(d),
shared_process_params_m(nullptr, &__free_ddr),
in_size_m(0),
out_size_m(0),
- in_m(nullptr, 0),
- out_m(nullptr, 0),
+ in_m(),
+ out_m(),
current_frame_idx_m(0),
num_network_layers_m(0),
trace_buf_params_m(nullptr, &__free_ddr),
char* ExecutionObject::GetInputBufferPtr() const
{
- return static_cast<char *>(pimpl_m->in_m.ptr());
+ return static_cast<char *>(pimpl_m->in_m.GetArg().ptr());
}
size_t ExecutionObject::GetInputBufferSizeInBytes() const
{
- if (pimpl_m->in_m.ptr() == nullptr) return pimpl_m->in_size_m;
- else return pimpl_m->in_m.size();
+ const DeviceArgInfo& arg = pimpl_m->in_m.GetArg();
+ if (arg.ptr() == nullptr) return pimpl_m->in_size_m;
+ else return arg.size();
}
char* ExecutionObject::GetOutputBufferPtr() const
{
- return static_cast<char *>(pimpl_m->out_m.ptr());
+ return static_cast<char *>(pimpl_m->out_m.GetArg().ptr());
}
size_t ExecutionObject::GetOutputBufferSizeInBytes() const
{
- if (pimpl_m->out_m.ptr() == nullptr) return pimpl_m->out_size_m;
- else return pimpl_m->shared_process_params_m.get()->bytesWritten;
+ const DeviceArgInfo& arg = pimpl_m->out_m.GetArg();
+ if (arg.ptr() == nullptr)
+ return pimpl_m->out_size_m;
+ else
+ return pimpl_m->shared_process_params_m.get()->bytesWritten;
}
void ExecutionObject::SetFrameIndex(int idx)
@@ -194,8 +229,8 @@ void ExecutionObject::SetInputOutputBuffer(const ArgInfo& in, const ArgInfo& out
assert(in.ptr() != nullptr && in.size() > 0);
assert(out.ptr() != nullptr && out.size() > 0);
- pimpl_m->in_m = in;
- pimpl_m->out_m = out;
+ pimpl_m->in_m = IODeviceArgInfo(in);
+ pimpl_m->out_m = IODeviceArgInfo(out);
}
bool ExecutionObject::ProcessFrameStartAsync()
@@ -282,8 +317,8 @@ ExecutionObject::WriteLayerOutputsToFile(const std::string& filename_prefix) con
// Create a kernel to call the "initialize" function
//
void
-ExecutionObject::Impl::SetupInitializeKernel(const ArgInfo& create_arg,
- const ArgInfo& param_heap_arg,
+ExecutionObject::Impl::SetupInitializeKernel(const DeviceArgInfo& create_arg,
+ const DeviceArgInfo& param_heap_arg,
size_t extmem_heap_size,
bool internal_input)
{
// Setup kernel arguments for initialize
KernelArgs args = { create_arg,
param_heap_arg,
- ArgInfo(tidl_extmem_heap_m.get(),
- extmem_heap_size),
- ArgInfo(shared_initialize_params_m.get(),
- sizeof(OCL_TIDL_InitializeParams)),
+ DeviceArgInfo(tidl_extmem_heap_m.get(),
+ extmem_heap_size,
+ DeviceArgInfo::Kind::BUFFER),
+ DeviceArgInfo(shared_initialize_params_m.get(),
+ sizeof(OCL_TIDL_InitializeParams),
+ DeviceArgInfo::Kind::BUFFER),
device_m->type() == CL_DEVICE_TYPE_ACCELERATOR ?
- ArgInfo(nullptr, tidl::internal::DMEM1_SIZE):
- ArgInfo(nullptr, 4) };
+ DeviceArgInfo(nullptr, tidl::internal::DMEM1_SIZE,
+ DeviceArgInfo::Kind::LOCAL):
+ DeviceArgInfo(nullptr, 4,
+ DeviceArgInfo::Kind::LOCAL) };
k_initialize_m.reset(new Kernel(device_m,
STRING(INIT_KERNEL), args,
shared_initialize_params_m->enableInternalInput;
shared_process_params_m->cycles = 0;
- KernelArgs args = { ArgInfo(shared_process_params_m.get(),
- sizeof(OCL_TIDL_ProcessParams)),
- ArgInfo(tidl_extmem_heap_m.get(),
- shared_initialize_params_m->tidlHeapSize),
- ArgInfo(trace_buf_params_m.get(),
- trace_buf_params_sz_m)
+ KernelArgs args = { DeviceArgInfo(shared_process_params_m.get(),
+ sizeof(OCL_TIDL_ProcessParams),
+ DeviceArgInfo::Kind::BUFFER),
+ DeviceArgInfo(tidl_extmem_heap_m.get(),
+ shared_initialize_params_m->tidlHeapSize,
+ DeviceArgInfo::Kind::BUFFER),
+ DeviceArgInfo(trace_buf_params_m.get(),
+ trace_buf_params_sz_m,
+ DeviceArgInfo::Kind::BUFFER)
};
//
void ExecutionObject::Impl::HostWriteNetInput()
{
- const char* readPtr = (const char *) in_m.ptr();
- const PipeInfo* pipe = in_m.GetPipe();
+ const char* readPtr = (const char *) in_m.GetArg().ptr();
+ const PipeInfo& pipe = in_m.GetPipe();
for (unsigned int i = 0; i < shared_initialize_params_m->numInBufs; i++)
{
}
else
{
- shared_process_params_m->inBufAddr[i] = pipe->bufAddr_m[i];
+ shared_process_params_m->inBufAddr[i] = pipe.bufAddr_m[i];
}
- shared_process_params_m->inDataQ[i] = pipe->dataQ_m[i];
+ shared_process_params_m->inDataQ[i] = pipe.dataQ_m[i];
}
}
//
void ExecutionObject::Impl::HostReadNetOutput()
{
- char* writePtr = (char *) out_m.ptr();
- PipeInfo* pipe = out_m.GetPipe();
+ char* writePtr = (char *) out_m.GetArg().ptr();
+ PipeInfo& pipe = out_m.GetPipe();
for (unsigned int i = 0; i < shared_initialize_params_m->numOutBufs; i++)
{
outBuf->numChannels));
}
- pipe->dataQ_m[i] = shared_process_params_m->outDataQ[i];
- pipe->bufAddr_m[i] = shared_initialize_params_m->bufAddrBase
+ pipe.dataQ_m[i] = shared_process_params_m->outDataQ[i];
+ pipe.bufAddr_m[i] = shared_initialize_params_m->bufAddrBase
+ outBuf->bufPlaneBufOffset;
}
- shared_process_params_m->bytesWritten = writePtr - (char *) out_m.ptr();
+ shared_process_params_m->bytesWritten = writePtr -
+ (char *) out_m.GetArg().ptr();
}
void ExecutionObject::Impl::ComputeInputOutputSizes()
index 7929c42a06b1c8051021d0ecf77a57d84ca61b33..b644728afe8f92a75dc65f3bd200ec8aaa8e26fe 100644 (file)
// kernel to allocate and initialize network parameters for the layers
shared_networkparam_heap_m.reset(malloc_ddr<char>(setupParams->networkParamHeapSize));
- KernelArgs args = { ArgInfo(cp, sizeof(TIDL_CreateParams)),
- ArgInfo(networkparam.get(), networkparam_size),
- ArgInfo(shared_networkparam_heap_m.get(),
- setupParams->networkParamHeapSize),
- ArgInfo(setupParams.get(),
- sizeof(OCL_TIDL_SetupParams)) };
+ KernelArgs args = { DeviceArgInfo(cp, sizeof(TIDL_CreateParams),
+ DeviceArgInfo::Kind::BUFFER),
+ DeviceArgInfo(networkparam.get(), networkparam_size,
+ DeviceArgInfo::Kind::BUFFER),
+ DeviceArgInfo(shared_networkparam_heap_m.get(),
+ setupParams->networkParamHeapSize,
+ DeviceArgInfo::Kind::BUFFER),
+ DeviceArgInfo(setupParams.get(),
+ sizeof(OCL_TIDL_SetupParams),
+ DeviceArgInfo::Kind::BUFFER) };
// Execute kernel on first available device in the Executor
uint8_t id = static_cast<uint8_t>(*(device_ids_m.cbegin()));
index f20305d1cba21547f84066455207968401f959e0..fba4f94305da4659de311f604a320ebec8219159 100644 (file)
errorCheck(err, __LINE__);
int arg_index = 0;
- for (auto arg : args)
+ for (const auto& arg : args)
{
if (!arg.isLocal())
{
- if (arg.kind() == ArgInfo::Kind::BUFFER)
+ if (arg.kind() == DeviceArgInfo::Kind::BUFFER)
{
cl_mem buffer = device_m->CreateBuffer(arg);
buffers_m.push_back(buffer);
}
- else if (arg.kind() == ArgInfo::Kind::SCALAR)
+ else if (arg.kind() == DeviceArgInfo::Kind::SCALAR)
{
clSetKernelArg(kernel_m, arg_index, arg.size(), arg.ptr());
TRACE::print(" Arg[%d]: %p\n", arg_index, arg.ptr());
}
else
{
- assert ("ArgInfo kind not supported");
+ assert ("DeviceArgInfo kind not supported");
}
}
else
clReleaseKernel(kernel_m);
}
-cl_mem Device::CreateBuffer(const ArgInfo &Arg)
+cl_mem Device::CreateBuffer(const DeviceArgInfo &Arg)
{
size_t size = Arg.size();
void *host_ptr = Arg.ptr();
index f1aa2dd3253070bbb801daafa1788b4430a78f20..6e80166e5f77b9a046d757c821b7a1ca979a6015 100644 (file)
#include <vector>
#include <memory>
#include "executor.h"
+#include "device_arginfo.h"
namespace tidl
{
-typedef std::vector<ArgInfo> KernelArgs;
+typedef std::vector<DeviceArgInfo> KernelArgs;
class Kernel;
protected:
static const int MAX_DEVICES = 4;
- cl_mem CreateBuffer(const ArgInfo &Arg);
+ cl_mem CreateBuffer(const DeviceArgInfo &Arg);
void ReleaseBuffer(cl_mem M);