1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147
|
/*****************************************************************************
* Copyright (C) 2013-2020 MulticoreWare, Inc
*
* Authors: Steve Borho <steve@borho.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA.
*
* This program is also available under a commercial proprietary license.
* For more information, contact us at license @ x265.com.
*****************************************************************************/
#if defined(ENABLE_PPA)
#include "ppa.h"
#include <stdlib.h>
#define PPA_REGISTER_CPU_EVENT2GROUP(x, y) # x, # y,
#define CPU_EVENT(x) PPA_REGISTER_CPU_EVENT2GROUP(x, NoGroup)
const char *PPACpuAndGroup[] =
{
#include "../cpuEvents.h"
""
};
#undef CPU_EVENT
#undef PPA_REGISTER_CPU_EVENT2GROUP
extern "C" {
typedef ppa::Base *(FUNC_PPALibInit)(const char **, int);
typedef void (FUNC_PPALibRelease)(ppa::Base* &);
}
using namespace ppa;
static FUNC_PPALibRelease *_pfuncPpaRelease;
ppa::Base *ppa::ppabase;
static void _ppaReleaseAtExit()
{
_pfuncPpaRelease(ppabase);
}
#ifdef _WIN32
#include <windows.h>
#if defined(_M_X64) || defined(__x86_64__) || defined(__amd64__)
# ifdef UNICODE
# define PPA_DLL_NAME L"ppa64.dll"
# else
# define PPA_DLL_NAME "ppa64.dll"
# endif
#else
# ifdef UNICODE
# define PPA_DLL_NAME L"ppa.dll"
# else
# define PPA_DLL_NAME "ppa.dll"
# endif
#endif // if defined(_M_X64) || defined(__x86_64__) || defined(__amd64__)
void initializePPA(void)
{
if (ppabase)
return;
HMODULE _ppaLibHandle = LoadLibrary(PPA_DLL_NAME);
if (!_ppaLibHandle)
return;
FUNC_PPALibInit *_pfuncPpaInit = (FUNC_PPALibInit*)GetProcAddress(_ppaLibHandle, "InitPpaUtil");
_pfuncPpaRelease = (FUNC_PPALibRelease*)GetProcAddress(_ppaLibHandle, "DeletePpa");
if (!_pfuncPpaInit || !_pfuncPpaRelease)
{
FreeLibrary(_ppaLibHandle);
return;
}
ppabase = _pfuncPpaInit(PPACpuAndGroup, PPACpuGroupNums);
if (!ppabase)
{
FreeLibrary(_ppaLibHandle);
return;
}
atexit(_ppaReleaseAtExit);
}
#else /* linux & unix & cygwin */
#include <dlfcn.h>
#include <stdio.h>
#if defined(_M_X64) || defined(__x86_64__) || defined(__amd64__)
# define PPA_LIB_NAME "libppa64.so"
#else
# define PPA_LIB_NAME "libppa.so"
#endif
void initializePPA(void)
{
if (ppabase)
{
printf("PPA: already initialized\n");
return;
}
void *_ppaDllHandle = dlopen(PPA_LIB_NAME, RTLD_LAZY);
if (!_ppaDllHandle)
{
printf("PPA: Unable to load %s\n", PPA_LIB_NAME);
return;
}
FUNC_PPALibInit *_pfuncPpaInit = (FUNC_PPALibInit*)dlsym(_ppaDllHandle, "InitPpaUtil");
_pfuncPpaRelease = (FUNC_PPALibRelease*)dlsym(_ppaDllHandle, "DeletePpa");
if (!_pfuncPpaInit || !_pfuncPpaRelease)
{
printf("PPA: Function bindings failed\n");
dlclose(_ppaDllHandle);
return;
}
ppabase = _pfuncPpaInit(PPACpuAndGroup, PPACpuGroupNums);
if (!ppabase)
{
printf("PPA: Init failed\n");
dlclose(_ppaDllHandle);
return;
}
atexit(_ppaReleaseAtExit);
}
#endif /* !_WIN32 */
#endif /* defined(ENABLE_PPA) */
|