2014-07-04 16:17:05 -04:00
|
|
|
//
|
|
|
|
|
// Copyright (c) 2008 Advanced Micro Devices, Inc. All rights reserved.
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
/*! \file program.hpp
|
|
|
|
|
* \brief Declarations for Program and ProgramBinary objects.
|
|
|
|
|
*
|
|
|
|
|
* \author Laurent Morichetti (laurent.morichetti@amd.com)
|
|
|
|
|
* \date October 2008
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#ifndef PROGRAM_HPP_
|
|
|
|
|
#define PROGRAM_HPP_
|
|
|
|
|
|
|
|
|
|
#include "top.hpp"
|
|
|
|
|
#include "device/device.hpp"
|
|
|
|
|
#include "platform/object.hpp"
|
|
|
|
|
#include "platform/kernel.hpp"
|
|
|
|
|
|
|
|
|
|
#include <set>
|
|
|
|
|
#include <string>
|
|
|
|
|
#include <vector>
|
|
|
|
|
#include <map>
|
|
|
|
|
#include <utility>
|
|
|
|
|
|
|
|
|
|
namespace amd {
|
|
|
|
|
|
|
|
|
|
/*! \addtogroup Runtime
|
|
|
|
|
* @{
|
|
|
|
|
*
|
|
|
|
|
* \addtogroup Program Programs and Kernel functions
|
|
|
|
|
* @{
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
//! A kernel function symbol
|
2017-04-13 13:56:38 -04:00
|
|
|
class Symbol : public HeapObject {
|
|
|
|
|
public:
|
2018-04-04 18:00:17 -04:00
|
|
|
typedef std::unordered_map<const Device*, const device::Kernel*> devicekernels_t;
|
2017-04-13 13:56:38 -04:00
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
devicekernels_t deviceKernels_; //! All device kernels objects.
|
|
|
|
|
KernelSignature signature_; //! Kernel signature.
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
//! Default constructor
|
|
|
|
|
Symbol() {}
|
|
|
|
|
|
|
|
|
|
//! Set the entry point and check or set the signature.
|
|
|
|
|
bool setDeviceKernel(const Device& device, //!< Device object.
|
2018-05-24 10:45:00 -04:00
|
|
|
const device::Kernel* func //!< Device kernel object.
|
2017-04-13 13:56:38 -04:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
//! Return the device kernel.
|
2018-05-24 10:45:00 -04:00
|
|
|
const device::Kernel* getDeviceKernel(const Device& device //!< Device object.
|
2017-04-13 13:56:38 -04:00
|
|
|
) const;
|
|
|
|
|
|
|
|
|
|
//! Return this Symbol's signature.
|
|
|
|
|
const KernelSignature& signature() const { return signature_; }
|
2014-07-04 16:17:05 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class Context;
|
|
|
|
|
|
|
|
|
|
//! A collection of binaries for devices in the associated context.
|
2017-04-13 13:56:38 -04:00
|
|
|
class Program : public RuntimeObject {
|
|
|
|
|
public:
|
|
|
|
|
typedef std::pair<uint8_t*, size_t> binary_t;
|
|
|
|
|
typedef std::set<Device const*> devicelist_t;
|
2018-04-04 18:00:17 -04:00
|
|
|
typedef std::unordered_map<Device const*, binary_t> devicebinary_t;
|
|
|
|
|
typedef std::unordered_map<Device const*, device::Program*> deviceprograms_t;
|
|
|
|
|
typedef std::unordered_map<std::string, Symbol> symbols_t;
|
2017-04-13 13:56:38 -04:00
|
|
|
|
2017-11-28 11:41:42 -05:00
|
|
|
enum Language {
|
|
|
|
|
Binary = 0,
|
|
|
|
|
OpenCL_C,
|
|
|
|
|
SPIRV,
|
2019-09-26 17:47:32 -04:00
|
|
|
Assembly,
|
|
|
|
|
HIP
|
2017-11-28 11:41:42 -05:00
|
|
|
};
|
2019-08-11 18:53:11 -04:00
|
|
|
|
|
|
|
|
typedef bool(CL_CALLBACK* VarInfoCallback)(cl_program, std::string, void**, size_t*);
|
|
|
|
|
VarInfoCallback varcallback;
|
|
|
|
|
|
2017-04-13 13:56:38 -04:00
|
|
|
private:
|
|
|
|
|
//! Replaces the compiled program with the new version from HD
|
|
|
|
|
void StubProgramSource(const std::string& app_name);
|
|
|
|
|
|
|
|
|
|
//! The context this program is part of.
|
|
|
|
|
SharedReference<Context> context_;
|
|
|
|
|
|
|
|
|
|
std::string sourceCode_; //!< Strings that make up the source code
|
2017-11-28 11:41:42 -05:00
|
|
|
Language language_; //!< Input source language
|
2017-04-13 13:56:38 -04:00
|
|
|
devicebinary_t binary_; //!< The binary image, provided by the app
|
|
|
|
|
symbols_t* symbolTable_; //!< The program's kernels symbol table
|
|
|
|
|
std::string kernelNames_; //!< The program kernel names
|
|
|
|
|
|
|
|
|
|
//! The device program objects included in this program
|
|
|
|
|
deviceprograms_t devicePrograms_;
|
|
|
|
|
devicelist_t deviceList_;
|
|
|
|
|
|
|
|
|
|
std::string programLog_; //!< Log for parsing options, etc.
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
//! Destroy this program.
|
|
|
|
|
~Program();
|
|
|
|
|
|
|
|
|
|
//! Clears the program object if the app attempts to rebuild the program
|
|
|
|
|
void clear();
|
|
|
|
|
|
|
|
|
|
//! Global build lock (remove when LLVM is thread-safe).
|
|
|
|
|
static Monitor buildLock_;
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
//! Construct a new program to be compiled from the given source code.
|
2017-11-28 11:41:42 -05:00
|
|
|
Program(Context& context, const std::string& sourceCode, Language language)
|
2017-04-13 13:56:38 -04:00
|
|
|
: context_(context),
|
|
|
|
|
sourceCode_(sourceCode),
|
2017-11-28 11:41:42 -05:00
|
|
|
language_(language),
|
2017-04-13 13:56:38 -04:00
|
|
|
symbolTable_(NULL),
|
|
|
|
|
programLog_() {}
|
|
|
|
|
|
|
|
|
|
//! Construct a new program associated with a context.
|
2017-11-28 11:41:42 -05:00
|
|
|
Program(Context& context, Language language = Binary)
|
|
|
|
|
: context_(context), language_(language), symbolTable_(NULL) {}
|
2017-04-13 13:56:38 -04:00
|
|
|
|
|
|
|
|
//! Returns context, associated with the current program.
|
|
|
|
|
const Context& context() const { return context_(); }
|
|
|
|
|
|
|
|
|
|
//! Return the sections for this program.
|
|
|
|
|
const deviceprograms_t& devicePrograms() const { return devicePrograms_; }
|
|
|
|
|
|
|
|
|
|
//! Return the associated devices.
|
|
|
|
|
const devicelist_t& deviceList() const { return deviceList_; }
|
|
|
|
|
|
|
|
|
|
//! Return the symbols for this program.
|
|
|
|
|
const symbols_t& symbols() const { return *symbolTable_; }
|
|
|
|
|
|
|
|
|
|
//! Return the pointer to symbols for this program.
|
|
|
|
|
const symbols_t* symbolsPtr() const { return symbolTable_; }
|
|
|
|
|
|
|
|
|
|
//! Return the program source code.
|
|
|
|
|
const std::string& sourceCode() const { return sourceCode_; }
|
|
|
|
|
|
2019-09-26 17:47:32 -04:00
|
|
|
//! Append to source code.
|
|
|
|
|
void appendToSource(const char* newCode) { sourceCode_.append(newCode); }
|
|
|
|
|
|
2017-04-13 13:56:38 -04:00
|
|
|
//! Return the program log.
|
|
|
|
|
const std::string& programLog() const { return programLog_; }
|
|
|
|
|
|
|
|
|
|
//! Add a new device program with or without binary image and options.
|
|
|
|
|
cl_int addDeviceProgram(Device&, const void* image = NULL, size_t len = 0,
|
|
|
|
|
amd::option::Options* options = NULL);
|
|
|
|
|
|
|
|
|
|
//! Find the section for the given device. Return NULL if not found.
|
|
|
|
|
device::Program* getDeviceProgram(const Device& device) const;
|
|
|
|
|
|
|
|
|
|
//! Return the symbol for the given kernel name.
|
|
|
|
|
const Symbol* findSymbol(const char* name) const;
|
|
|
|
|
|
|
|
|
|
//! Return the binary image.
|
2018-05-29 18:13:40 -04:00
|
|
|
const binary_t& binary(const Device& device) { return binary_[&device]; }
|
2017-04-13 13:56:38 -04:00
|
|
|
|
|
|
|
|
//! Return the program kernel names
|
|
|
|
|
const std::string& kernelNames() const { return kernelNames_; }
|
|
|
|
|
|
|
|
|
|
//! Compile the program for the given devices.
|
|
|
|
|
cl_int compile(const std::vector<Device*>& devices, size_t numHeaders,
|
|
|
|
|
const std::vector<const Program*>& headerPrograms, const char** headerIncludeNames,
|
|
|
|
|
const char* options = NULL,
|
|
|
|
|
void(CL_CALLBACK* notifyFptr)(cl_program, void*) = NULL, void* data = NULL,
|
|
|
|
|
bool optionChangable = true);
|
|
|
|
|
|
|
|
|
|
//! Link the programs for the given devices.
|
|
|
|
|
cl_int link(const std::vector<Device*>& devices, size_t numInputs,
|
|
|
|
|
const std::vector<Program*>& inputPrograms, const char* options = NULL,
|
|
|
|
|
void(CL_CALLBACK* notifyFptr)(cl_program, void*) = NULL, void* data = NULL,
|
|
|
|
|
bool optionChangable = true);
|
|
|
|
|
|
|
|
|
|
//! Build the program for the given devices.
|
|
|
|
|
cl_int build(const std::vector<Device*>& devices, const char* options = NULL,
|
|
|
|
|
void(CL_CALLBACK* notifyFptr)(cl_program, void*) = NULL, void* data = NULL,
|
|
|
|
|
bool optionChangable = true);
|
|
|
|
|
|
|
|
|
|
//! RTTI internal implementation
|
|
|
|
|
virtual ObjectType objectType() const { return ObjectTypeProgram; }
|
|
|
|
|
|
|
|
|
|
static int GetOclCVersion(const char* clVer);
|
|
|
|
|
|
2019-08-27 11:42:23 -04:00
|
|
|
bool static ParseAllOptions(const std::string& options, option::Options& parsedOptions,
|
2019-08-28 18:09:33 -04:00
|
|
|
bool optionChangable, bool linkOptsOnly, bool isLC);
|
2019-08-11 18:53:11 -04:00
|
|
|
|
|
|
|
|
void setVarInfoCallBack(VarInfoCallback callback) {
|
|
|
|
|
varcallback = callback;
|
|
|
|
|
}
|
2014-07-04 16:17:05 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/*! @}
|
|
|
|
|
* @}
|
|
|
|
|
*/
|
|
|
|
|
|
2017-04-13 13:56:38 -04:00
|
|
|
} // namespace amd
|
2014-07-04 16:17:05 -04:00
|
|
|
|
|
|
|
|
#endif /*PROGRAM_HPP_*/
|