Skip to content

Commit 04b4495

Browse files
committed
ocl: define ProgramSource before program
no changes in code
1 parent 2c1b4f5 commit 04b4495

File tree

1 file changed

+124
-119
lines changed

1 file changed

+124
-119
lines changed

modules/core/src/ocl.cpp

Lines changed: 124 additions & 119 deletions
Original file line numberDiff line numberDiff line change
@@ -2489,6 +2489,130 @@ size_t Kernel::localMemSize() const
24892489
sizeof(val), &val, &retsz) == CL_SUCCESS ? (size_t)val : 0;
24902490
}
24912491

2492+
2493+
2494+
///////////////////////////////////////// ProgramSource ///////////////////////////////////////////////
2495+
2496+
struct ProgramSource::Impl
2497+
{
2498+
Impl(const String& src)
2499+
{
2500+
init(cv::String(), cv::String(), src, cv::String());
2501+
}
2502+
Impl(const String& module, const String& name, const String& codeStr, const String& codeHash)
2503+
{
2504+
init(module, name, codeStr, codeHash);
2505+
}
2506+
void init(const String& module, const String& name, const String& codeStr, const String& codeHash)
2507+
{
2508+
refcount = 1;
2509+
module_ = module;
2510+
name_ = name;
2511+
codeStr_ = codeStr;
2512+
codeHash_ = codeHash;
2513+
2514+
isHashUpdated = false;
2515+
if (codeHash_.empty())
2516+
{
2517+
updateHash();
2518+
codeHash_ = cv::format("%08llx", hash_);
2519+
}
2520+
}
2521+
2522+
void updateHash()
2523+
{
2524+
hash_ = crc64((uchar*)codeStr_.c_str(), codeStr_.size());
2525+
isHashUpdated = true;
2526+
}
2527+
2528+
IMPLEMENT_REFCOUNTABLE();
2529+
2530+
String module_;
2531+
String name_;
2532+
String codeStr_;
2533+
String codeHash_;
2534+
// TODO std::vector<ProgramSource> includes_;
2535+
2536+
bool isHashUpdated;
2537+
ProgramSource::hash_t hash_;
2538+
};
2539+
2540+
2541+
ProgramSource::ProgramSource()
2542+
{
2543+
p = 0;
2544+
}
2545+
2546+
ProgramSource::ProgramSource(const String& module, const String& name, const String& codeStr, const String& codeHash)
2547+
{
2548+
p = new Impl(module, name, codeStr, codeHash);
2549+
}
2550+
2551+
ProgramSource::ProgramSource(const char* prog)
2552+
{
2553+
p = new Impl(prog);
2554+
}
2555+
2556+
ProgramSource::ProgramSource(const String& prog)
2557+
{
2558+
p = new Impl(prog);
2559+
}
2560+
2561+
ProgramSource::~ProgramSource()
2562+
{
2563+
if(p)
2564+
p->release();
2565+
}
2566+
2567+
ProgramSource::ProgramSource(const ProgramSource& prog)
2568+
{
2569+
p = prog.p;
2570+
if(p)
2571+
p->addref();
2572+
}
2573+
2574+
ProgramSource& ProgramSource::operator = (const ProgramSource& prog)
2575+
{
2576+
Impl* newp = (Impl*)prog.p;
2577+
if(newp)
2578+
newp->addref();
2579+
if(p)
2580+
p->release();
2581+
p = newp;
2582+
return *this;
2583+
}
2584+
2585+
const String& ProgramSource::source() const
2586+
{
2587+
CV_Assert(p);
2588+
return p->codeStr_;
2589+
}
2590+
2591+
ProgramSource::hash_t ProgramSource::hash() const
2592+
{
2593+
CV_Assert(p);
2594+
if (!p->isHashUpdated)
2595+
p->updateHash();
2596+
return p->hash_;
2597+
}
2598+
2599+
2600+
internal::ProgramEntry::operator ProgramSource&() const
2601+
{
2602+
if (this->pProgramSource == NULL)
2603+
{
2604+
cv::AutoLock lock(cv::getInitializationMutex());
2605+
if (this->pProgramSource == NULL)
2606+
{
2607+
ProgramSource* ps = new ProgramSource(this->module, this->name, this->programCode, this->programHash);
2608+
const_cast<ProgramEntry*>(this)->pProgramSource = ps;
2609+
}
2610+
}
2611+
return *this->pProgramSource;
2612+
}
2613+
2614+
2615+
24922616
/////////////////////////////////////////// Program /////////////////////////////////////////////
24932617

24942618
struct Program::Impl
@@ -2717,125 +2841,6 @@ String Program::getPrefix(const String& buildflags)
27172841
dev.name().c_str(), dev.driverVersion().c_str(), buildflags.c_str());
27182842
}
27192843

2720-
///////////////////////////////////////// ProgramSource ///////////////////////////////////////////////
2721-
2722-
struct ProgramSource::Impl
2723-
{
2724-
Impl(const String& src)
2725-
{
2726-
init(cv::String(), cv::String(), src, cv::String());
2727-
}
2728-
Impl(const String& module, const String& name, const String& codeStr, const String& codeHash)
2729-
{
2730-
init(module, name, codeStr, codeHash);
2731-
}
2732-
void init(const String& module, const String& name, const String& codeStr, const String& codeHash)
2733-
{
2734-
refcount = 1;
2735-
module_ = module;
2736-
name_ = name;
2737-
codeStr_ = codeStr;
2738-
codeHash_ = codeHash;
2739-
2740-
isHashUpdated = false;
2741-
if (codeHash_.empty())
2742-
{
2743-
updateHash();
2744-
codeHash_ = cv::format("%08llx", hash_);
2745-
}
2746-
}
2747-
2748-
void updateHash()
2749-
{
2750-
hash_ = crc64((uchar*)codeStr_.c_str(), codeStr_.size());
2751-
isHashUpdated = true;
2752-
}
2753-
2754-
IMPLEMENT_REFCOUNTABLE();
2755-
2756-
String module_;
2757-
String name_;
2758-
String codeStr_;
2759-
String codeHash_;
2760-
// TODO std::vector<ProgramSource> includes_;
2761-
2762-
bool isHashUpdated;
2763-
ProgramSource::hash_t hash_;
2764-
};
2765-
2766-
2767-
ProgramSource::ProgramSource()
2768-
{
2769-
p = 0;
2770-
}
2771-
2772-
ProgramSource::ProgramSource(const String& module, const String& name, const String& codeStr, const String& codeHash)
2773-
{
2774-
p = new Impl(module, name, codeStr, codeHash);
2775-
}
2776-
2777-
ProgramSource::ProgramSource(const char* prog)
2778-
{
2779-
p = new Impl(prog);
2780-
}
2781-
2782-
ProgramSource::ProgramSource(const String& prog)
2783-
{
2784-
p = new Impl(prog);
2785-
}
2786-
2787-
ProgramSource::~ProgramSource()
2788-
{
2789-
if(p)
2790-
p->release();
2791-
}
2792-
2793-
ProgramSource::ProgramSource(const ProgramSource& prog)
2794-
{
2795-
p = prog.p;
2796-
if(p)
2797-
p->addref();
2798-
}
2799-
2800-
ProgramSource& ProgramSource::operator = (const ProgramSource& prog)
2801-
{
2802-
Impl* newp = (Impl*)prog.p;
2803-
if(newp)
2804-
newp->addref();
2805-
if(p)
2806-
p->release();
2807-
p = newp;
2808-
return *this;
2809-
}
2810-
2811-
const String& ProgramSource::source() const
2812-
{
2813-
CV_Assert(p);
2814-
return p->codeStr_;
2815-
}
2816-
2817-
ProgramSource::hash_t ProgramSource::hash() const
2818-
{
2819-
CV_Assert(p);
2820-
if (!p->isHashUpdated)
2821-
p->updateHash();
2822-
return p->hash_;
2823-
}
2824-
2825-
2826-
internal::ProgramEntry::operator ProgramSource&() const
2827-
{
2828-
if (this->pProgramSource == NULL)
2829-
{
2830-
cv::AutoLock lock(cv::getInitializationMutex());
2831-
if (this->pProgramSource == NULL)
2832-
{
2833-
ProgramSource* ps = new ProgramSource(this->module, this->name, this->programCode, this->programHash);
2834-
const_cast<ProgramEntry*>(this)->pProgramSource = ps;
2835-
}
2836-
}
2837-
return *this->pProgramSource;
2838-
}
28392844

28402845

28412846
//////////////////////////////////////////// OpenCLAllocator //////////////////////////////////////////////////

0 commit comments

Comments
 (0)