Files
rocm-systems/rocclr/runtime/device/rocm/rockernel.hpp
T
foreman 1c37625aa2 P4 to Git Change 1311256 by lmoriche@lmoriche_opencl_dev on 2016/09/06 13:16:58
SWDEV-101853 - roc::Kernel cleanups:
	- Remove unused classes & member functions/variables.
	- Flatten vector arguments for the HSAIL path to  remove the need for numElem_.
	- Consolidate initArguments in a single loop for the HSAIL path.
	- Use the Kernel::Argument to fill the OCL descriptor as much as possible.
	- Set the access qualifier for both buffers and images.
	- Fix the indentation and coding conventions.
	- Add new ROC_ARG_TYPE type for hidden arguments
	- Add an index_ field the roc::Kernel::Argument to record the OCL signature index for this argument, or -1 for hidden arguments
	- Handle the hidden arguments as any other argument at dispatch (now included in the hsailArgList_)
	- roc::Kernel::hsailArgAt(int) now returns the kernel argument for the given position in the OCL signature, not the position the the hsailArgList_.

Affected files ...

... //depot/stg/opencl/drivers/opencl/runtime/device/rocm/rockernel.cpp#12 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/rocm/rockernel.hpp#6 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/rocm/rocvirtual.cpp#12 edit
2016-09-06 13:21:14 -04:00

183 lines
5.1 KiB
C++

//
// Copyright (c) 2009 Advanced Micro Devices, Inc. All rights reserved.
//
#pragma once
#include <memory>
#include "acl.h"
#include "rocprogram.hpp"
#include "top.hpp"
#include "rocprintf.hpp"
#ifndef WITHOUT_HSA_BACKEND
namespace roc {
#define MAX_INFO_STRING_LEN 0x40
enum ROC_ARG_TYPE
{
ROC_ARGTYPE_ERROR = 0,
ROC_ARGTYPE_POINTER,
ROC_ARGTYPE_VALUE,
ROC_ARGTYPE_IMAGE,
ROC_ARGTYPE_SAMPLER,
ROC_ARGTYPE_HIDDEN_GLOBAL_OFFSET_X,
ROC_ARGTYPE_HIDDEN_GLOBAL_OFFSET_Y,
ROC_ARGTYPE_HIDDEN_GLOBAL_OFFSET_Z,
ROC_ARGTYPE_HIDDEN_PRINTF_BUFFER,
ROC_ARGTYPE_HIDDEN_DEFAULT_QUEUE,
ROC_ARGTYPE_HIDDEN_COMPLETION_ACTION,
ROC_ARGTYPE_HIDDEN_NONE,
ROC_ARGMAX_ARG_TYPES
};
enum ROC_ADDRESS_QUALIFIER
{
ROC_ADDRESS_ERROR = 0,
ROC_ADDRESS_GLOBAL,
ROC_ADDRESS_CONSTANT,
ROC_ADDRESS_LOCAL,
ROC_MAX_ADDRESS_QUALIFIERS
};
enum ROC_DATA_TYPE
{
ROC_DATATYPE_ERROR = 0,
ROC_DATATYPE_B1,
ROC_DATATYPE_B8,
ROC_DATATYPE_B16,
ROC_DATATYPE_B32,
ROC_DATATYPE_B64,
ROC_DATATYPE_S8,
ROC_DATATYPE_S16,
ROC_DATATYPE_S32,
ROC_DATATYPE_S64,
ROC_DATATYPE_U8,
ROC_DATATYPE_U16,
ROC_DATATYPE_U32,
ROC_DATATYPE_U64,
ROC_DATATYPE_F16,
ROC_DATATYPE_F32,
ROC_DATATYPE_F64,
ROC_DATATYPE_STRUCT,
ROC_DATATYPE_OPAQUE,
ROC_DATATYPE_MAX_TYPES
};
enum ROC_ACCESS_TYPE
{
ROC_ACCESS_TYPE_NONE = 0,
ROC_ACCESS_TYPE_RO,
ROC_ACCESS_TYPE_WO,
ROC_ACCESS_TYPE_RW
};
class Kernel : public device::Kernel
{
public:
struct Argument
{
uint index_; //!< Argument's index in the OCL signature
std::string name_; //!< Argument's name
std::string typeName_; //!< Argument's type name
uint size_; //!< Size in bytes
uint alignment_; //!< Argument's alignment
uint pointeeAlignment_; //!< Alignment of the data pointed to
ROC_ARG_TYPE type_; //!< Type of the argument
ROC_ADDRESS_QUALIFIER addrQual_; //!< Address qualifier of the argument
ROC_DATA_TYPE dataType_; //!< The type of data
ROC_ACCESS_TYPE access_; //!< Access type for the argument
};
Kernel(std::string name,
HSAILProgram* prog,
const uint64_t &kernelCodeHandle,
const uint32_t workgroupGroupSegmentByteSize,
const uint32_t workitemPrivateSegmentByteSize,
const uint32_t kernargSegmentByteSize,
const uint32_t kernargSegmentAlignment,
uint extraArgsNum);
const uint64_t& KernelCodeHandle() {
return kernelCodeHandle_;
}
const uint32_t WorkgroupGroupSegmentByteSize() const {
return workgroupGroupSegmentByteSize_;
}
const uint32_t workitemPrivateSegmentByteSize() const {
return workitemPrivateSegmentByteSize_;
}
const uint64_t KernargSegmentByteSize() const {
return kernargSegmentByteSize_;
}
const uint8_t KernargSegmentAlignment() const {
return kernargSegmentAlignment_;
}
~Kernel();
//! Initializes the metadata required for this kernel
bool init();
#if defined(WITH_LIGHTNING_COMPILER)
//! Initializes the metadata required for this kernel
bool init_LC();
#endif // defined(WITH_LIGHTNING_COMPILER)
const HSAILProgram* program() {
return static_cast<const HSAILProgram*>(program_);
}
//! Returns the kernel argument list
const std::vector<Argument*>& hsailArgs() const {
return hsailArgList_;
}
//! Returns a pointer to the hsail argument at the specified index
Argument* hsailArgAt(size_t index) const {
for (auto arg : hsailArgList_) if (arg->index_ == index) return arg;
assert(!"Should not reach here");
}
//! Max number of possible extra (hidden) kernel arguments
static const uint MaxExtraArgumentsNum = 6;
uint extraArgumentsNum() const { return extraArgumentsNum_; }
//! Return printf info array
const std::vector<PrintfInfo>& printfInfo() const {return printf_;}
private:
//! Populates hsailArgList_
void initArguments(const aclArgData* aclArg);
#if defined(WITH_LIGHTNING_COMPILER)
//! Initializes Hsail Argument metadata and info for LC
void initArguments_LC(const amd::hsa::code::Kernel::Metadata& kernelMD);
#endif // defined(WITH_LIGHTNING_COMPILER)
//! Initializes HSAIL Printf metadata and info
void initPrintf(const aclPrintfFmt* aclPrintf);
HSAILProgram *program_; //!< The roc::HSAILProgram context
std::vector<Argument*> hsailArgList_; //!< Vector list of HSAIL Arguments
std::string compileOptions_; //!< compile used for finalizing this kernel
uint64_t kernelCodeHandle_; //!< Kernel code handle (aka amd_kernel_code_t)
const uint32_t workgroupGroupSegmentByteSize_;
const uint32_t workitemPrivateSegmentByteSize_;
const uint32_t kernargSegmentByteSize_;
const uint32_t kernargSegmentAlignment_;
size_t kernelDirectiveOffset_;
const uint extraArgumentsNum_; // Number of arguments in Kernenv
std::vector<PrintfInfo> printf_;
};
} // namespace roc
#endif // WITHOUT_HSA_BACKEND