Commit 25d1190c683a6b70b30fcbecc2f4d705fd3f3087
1 parent
78254b65
llvm refactoring
Showing
2 changed files
with
575 additions
and
546 deletions
sdk/jitcv/jitcv.h
| ... | ... | @@ -90,6 +90,11 @@ typedef void (*BinaryFunction)(const Matrix *srcA, const Matrix *srcB, Matrix *d |
| 90 | 90 | BR_EXPORT UnaryFunction makeUnaryFunction(const char *description); |
| 91 | 91 | BR_EXPORT BinaryFunction makeBinaryFunction(const char *description); |
| 92 | 92 | |
| 93 | +typedef uint32_t (*UnaryAllocation)(const Matrix *src, Matrix *dst); | |
| 94 | +typedef uint32_t (*BinaryAllocation)(const Matrix *srcA, const Matrix *srcB, Matrix *dst); | |
| 95 | +BR_EXPORT UnaryAllocation makeUnaryAllocation(const char *description, const Matrix *src); | |
| 96 | +BR_EXPORT BinaryAllocation makeBinaryAllocation(const char *description, const Matrix *srcA, const Matrix *srcB); | |
| 97 | + | |
| 93 | 98 | typedef void (*UnaryKernel)(const Matrix *src, Matrix *dst, uint32_t size); |
| 94 | 99 | typedef void (*BinaryKernel)(const Matrix *srcA, const Matrix *srcB, Matrix *dst, uint32_t size); |
| 95 | 100 | BR_EXPORT UnaryKernel makeUnaryKernel(const char *description, const Matrix *src); | ... | ... |
sdk/plugins/llvm.cpp
| ... | ... | @@ -32,8 +32,6 @@ static ExecutionEngine *TheExecutionEngine = NULL; |
| 32 | 32 | static FunctionPassManager *TheFunctionPassManager = NULL; |
| 33 | 33 | static FunctionPassManager *TheExtraFunctionPassManager = NULL; |
| 34 | 34 | static StructType *TheMatrixStruct = NULL; |
| 35 | -static Function *makeUnaryKernelFunction = NULL; | |
| 36 | -static Function *makeBinaryKernelFunction = NULL; | |
| 37 | 35 | |
| 38 | 36 | static QString MatrixToString(const Matrix &m) |
| 39 | 37 | { |
| ... | ... | @@ -129,22 +127,6 @@ struct MatrixBuilder |
| 129 | 127 | setHash(other.hash()); |
| 130 | 128 | } |
| 131 | 129 | |
| 132 | - void allocate() const { | |
| 133 | - static Function *malloc = TheModule->getFunction("malloc"); | |
| 134 | - if (!malloc) { | |
| 135 | - Type *mallocReturn = Type::getInt8PtrTy(getGlobalContext()); | |
| 136 | - std::vector<Type*> mallocParams; | |
| 137 | - mallocParams.push_back(Type::getInt32Ty(getGlobalContext())); | |
| 138 | - FunctionType* mallocType = FunctionType::get(mallocReturn, mallocParams, false); | |
| 139 | - malloc = Function::Create(mallocType, GlobalValue::ExternalLinkage, "malloc", TheModule); | |
| 140 | - malloc->setCallingConv(CallingConv::C); | |
| 141 | - } | |
| 142 | - | |
| 143 | - std::vector<Value*> mallocArgs; | |
| 144 | - mallocArgs.push_back(bytes()); | |
| 145 | - setData(b->CreateCall(malloc, mallocArgs)); | |
| 146 | - } | |
| 147 | - | |
| 148 | 130 | void deallocate() const { |
| 149 | 131 | static Function *free = TheModule->getFunction("free"); |
| 150 | 132 | if (!free) { |
| ... | ... | @@ -328,13 +310,11 @@ class UnaryTransform : public UntrainableMetaTransform |
| 328 | 310 | { |
| 329 | 311 | Q_OBJECT |
| 330 | 312 | uint32_t fileIndex; |
| 331 | - UnaryKernel kernel; | |
| 332 | - uint16_t hash; | |
| 333 | 313 | |
| 334 | 314 | public: |
| 335 | 315 | static QHash<uint32_t, File> fileTable; |
| 336 | 316 | |
| 337 | - UnaryTransform() : fileIndex(0), kernel(NULL), hash(0) {} | |
| 317 | + UnaryTransform() : fileIndex(0) {} | |
| 338 | 318 | |
| 339 | 319 | void init() |
| 340 | 320 | { |
| ... | ... | @@ -342,9 +322,8 @@ public: |
| 342 | 322 | fileTable.insert(fileIndex, file); |
| 343 | 323 | } |
| 344 | 324 | |
| 345 | - virtual int preallocate(const Matrix &src, Matrix &dst) const = 0; /*!< Preallocate destintation matrix based on source matrix. */ | |
| 346 | - virtual Value *buildPreallocate(const MatrixBuilder &src, const MatrixBuilder &dst) const { (void) src; (void) dst; return MatrixBuilder::constant(0); } | |
| 347 | - virtual void build(const MatrixBuilder &src, const MatrixBuilder &dst, PHINode *i) const = 0; /*!< Build the kernel. */ | |
| 325 | + virtual Value *preallocation(const MatrixBuilder &src, const MatrixBuilder &dst) const = 0; /*!< Allocate the destintation matrix given the source matrix. */ | |
| 326 | + virtual void kernel(const MatrixBuilder &src, const MatrixBuilder &dst, PHINode *i) const = 0; /*!< Run the computation given the source matrix. */ | |
| 348 | 327 | |
| 349 | 328 | void optimize(Function *f) const |
| 350 | 329 | { |
| ... | ... | @@ -352,19 +331,184 @@ public: |
| 352 | 331 | TheExtraFunctionPassManager->run(*f); |
| 353 | 332 | } |
| 354 | 333 | |
| 355 | - UnaryFunction getFunction(const Matrix *src) const | |
| 334 | + UnaryFunction getFunction() const | |
| 356 | 335 | { |
| 357 | - const QString functionName = mangledName(); | |
| 358 | - Function *function = TheModule->getFunction(qPrintable(functionName)); | |
| 359 | - if (function == NULL) function = compile(*src); | |
| 336 | + const QString name = mangledName(); | |
| 337 | + Function *function = TheModule->getFunction(qPrintable(name)); | |
| 338 | + | |
| 339 | + if (function == NULL) { | |
| 340 | + static Function *makeAllocationFunction = NULL; | |
| 341 | + static PointerType *allocationType = NULL; | |
| 342 | + if (makeAllocationFunction == NULL) { | |
| 343 | + std::vector<Type*> allocationParams; | |
| 344 | + allocationParams.push_back(PointerType::getUnqual(TheMatrixStruct)); | |
| 345 | + allocationParams.push_back(PointerType::getUnqual(TheMatrixStruct)); | |
| 346 | + Type *allocationReturn = Type::getInt32Ty(getGlobalContext()); | |
| 347 | + allocationType = PointerType::getUnqual(FunctionType::get(allocationReturn, allocationParams, false)); | |
| 348 | + std::vector<Type*> makeAllocationParams; | |
| 349 | + makeAllocationParams.push_back(Type::getInt8PtrTy(getGlobalContext())); | |
| 350 | + makeAllocationParams.push_back(PointerType::getUnqual(TheMatrixStruct)); | |
| 351 | + FunctionType* makeAllocationType = FunctionType::get(allocationType, makeAllocationParams, false); | |
| 352 | + makeAllocationFunction = Function::Create(makeAllocationType, GlobalValue::ExternalLinkage, "makeUnaryAllocation", TheModule); | |
| 353 | + makeAllocationFunction->setCallingConv(CallingConv::C); | |
| 354 | + } | |
| 355 | + | |
| 356 | + static Function *makeKernelFunction = NULL; | |
| 357 | + static PointerType *kernelType = NULL; | |
| 358 | + if (makeKernelFunction == NULL) { | |
| 359 | + std::vector<Type*> kernelParams; | |
| 360 | + kernelParams.push_back(PointerType::getUnqual(TheMatrixStruct)); | |
| 361 | + kernelParams.push_back(PointerType::getUnqual(TheMatrixStruct)); | |
| 362 | + kernelParams.push_back(Type::getInt32Ty(getGlobalContext())); | |
| 363 | + Type *kernelReturn = Type::getVoidTy(getGlobalContext()); | |
| 364 | + kernelType = PointerType::getUnqual(FunctionType::get(kernelReturn, kernelParams, false)); | |
| 365 | + std::vector<Type*> makeKernelParams; | |
| 366 | + makeKernelParams.push_back(Type::getInt8PtrTy(getGlobalContext())); | |
| 367 | + makeKernelParams.push_back(PointerType::getUnqual(TheMatrixStruct)); | |
| 368 | + FunctionType* makeUnaryKernelType = FunctionType::get(kernelType, makeKernelParams, false); | |
| 369 | + makeKernelFunction = Function::Create(makeUnaryKernelType, GlobalValue::ExternalLinkage, "makeUnaryKernel", TheModule); | |
| 370 | + makeKernelFunction->setCallingConv(CallingConv::C); | |
| 371 | + } | |
| 372 | + | |
| 373 | + function = cast<Function>(TheModule->getOrInsertFunction(qPrintable(name), | |
| 374 | + Type::getVoidTy(getGlobalContext()), | |
| 375 | + PointerType::getUnqual(TheMatrixStruct), | |
| 376 | + PointerType::getUnqual(TheMatrixStruct), | |
| 377 | + NULL)); | |
| 378 | + function->setCallingConv(CallingConv::C); | |
| 379 | + | |
| 380 | + Function::arg_iterator args = function->arg_begin(); | |
| 381 | + Value *src = args++; | |
| 382 | + src->setName("src"); | |
| 383 | + Value *dst = args++; | |
| 384 | + dst->setName("dst"); | |
| 385 | + | |
| 386 | + BasicBlock *entry = BasicBlock::Create(getGlobalContext(), "entry", function); | |
| 387 | + IRBuilder<> builder(entry); | |
| 388 | + | |
| 389 | + GlobalVariable *kernelHash; { | |
| 390 | + kernelHash = cast<GlobalVariable>(TheModule->getOrInsertGlobal(qPrintable(name+"_hash"), Type::getInt16Ty(getGlobalContext()))); | |
| 391 | + kernelHash->setInitializer(MatrixBuilder::constant(0, 16)); | |
| 392 | + } | |
| 393 | + | |
| 394 | + GlobalVariable *allocationFunction; { | |
| 395 | + allocationFunction = cast<GlobalVariable>(TheModule->getOrInsertGlobal(qPrintable(name+"_allocation"), allocationType)); | |
| 396 | + allocationFunction->setInitializer(ConstantPointerNull::get(allocationType)); | |
| 397 | + } | |
| 398 | + | |
| 399 | + GlobalVariable *kernelFunction; { | |
| 400 | + kernelFunction = cast<GlobalVariable>(TheModule->getOrInsertGlobal(qPrintable(name+"_kernel"), kernelType)); | |
| 401 | + kernelFunction->setInitializer(ConstantPointerNull::get(kernelType)); | |
| 402 | + } | |
| 403 | + | |
| 404 | + BasicBlock *hashFail = BasicBlock::Create(getGlobalContext(), "hash_fail", function); | |
| 405 | + BasicBlock *execute = BasicBlock::Create(getGlobalContext(), "execute", function); | |
| 406 | + Value *srcHash = builder.CreateLoad(builder.CreateStructGEP(src, 5), "src_hash"); | |
| 407 | + Value *hashTest = builder.CreateICmpEQ(srcHash, builder.CreateLoad(kernelHash), "hash_fail_test"); | |
| 408 | + builder.CreateCondBr(hashTest, execute, hashFail); | |
| 409 | + | |
| 410 | + builder.SetInsertPoint(hashFail); | |
| 411 | + builder.CreateStore(builder.CreateCall2(makeAllocationFunction, | |
| 412 | + builder.CreateIntToPtr(MatrixBuilder::constant(fileIndex, 32), Type::getInt8PtrTy(getGlobalContext())), | |
| 413 | + src), allocationFunction); | |
| 414 | + builder.CreateStore(builder.CreateCall2(makeKernelFunction, | |
| 415 | + builder.CreateIntToPtr(MatrixBuilder::constant(fileIndex, 32), Type::getInt8PtrTy(getGlobalContext())), | |
| 416 | + src), kernelFunction); | |
| 417 | + builder.CreateStore(srcHash, kernelHash); | |
| 418 | + builder.CreateBr(execute); | |
| 419 | + | |
| 420 | + builder.SetInsertPoint(execute); | |
| 421 | + Value *kernelSize = builder.CreateCall2(builder.CreateLoad(allocationFunction), src, dst); | |
| 422 | + builder.CreateCall3(builder.CreateLoad(kernelFunction), src, dst, kernelSize); | |
| 423 | + builder.CreateRetVoid(); | |
| 424 | + | |
| 425 | + optimize(function); | |
| 426 | + } | |
| 427 | + | |
| 360 | 428 | return (UnaryFunction)TheExecutionEngine->getPointerToFunction(function); |
| 361 | 429 | } |
| 362 | 430 | |
| 363 | - UnaryKernel getKernel(const Matrix *src) const | |
| 431 | + UnaryAllocation getAllocation(const Matrix *m) const | |
| 364 | 432 | { |
| 365 | - const QString functionName = mangledName(*src); | |
| 366 | - Function *function = TheModule->getFunction(qPrintable(functionName)); | |
| 367 | - if (function == NULL) function = compileKernel(*src); | |
| 433 | + const QString name = mangledName(*m)+"_allocation"; | |
| 434 | + Function *function = TheModule->getFunction(qPrintable(name)); | |
| 435 | + | |
| 436 | + if (function == NULL) { | |
| 437 | + static Function *malloc = TheModule->getFunction("malloc"); | |
| 438 | + if (malloc == NULL) { | |
| 439 | + Type *mallocReturn = Type::getInt8PtrTy(getGlobalContext()); | |
| 440 | + std::vector<Type*> mallocParams; | |
| 441 | + mallocParams.push_back(Type::getInt32Ty(getGlobalContext())); | |
| 442 | + FunctionType* mallocType = FunctionType::get(mallocReturn, mallocParams, false); | |
| 443 | + malloc = Function::Create(mallocType, GlobalValue::ExternalLinkage, "malloc", TheModule); | |
| 444 | + malloc->setCallingConv(CallingConv::C); | |
| 445 | + } | |
| 446 | + | |
| 447 | + function = cast<Function>(TheModule->getOrInsertFunction(qPrintable(name), | |
| 448 | + Type::getInt32Ty(getGlobalContext()), | |
| 449 | + PointerType::getUnqual(TheMatrixStruct), | |
| 450 | + PointerType::getUnqual(TheMatrixStruct), | |
| 451 | + NULL)); | |
| 452 | + function->setCallingConv(CallingConv::C); | |
| 453 | + | |
| 454 | + Function::arg_iterator args = function->arg_begin(); | |
| 455 | + Value *src = args++; | |
| 456 | + src->setName("src"); | |
| 457 | + Value *dst = args++; | |
| 458 | + dst->setName("dst"); | |
| 459 | + | |
| 460 | + BasicBlock *entry = BasicBlock::Create(getGlobalContext(), "entry", function); | |
| 461 | + IRBuilder<> builder(entry); | |
| 462 | + MatrixBuilder mb(m, src, &builder, function, "src"); | |
| 463 | + MatrixBuilder nb(NULL, dst, &builder, function, "dst"); | |
| 464 | + | |
| 465 | + Value *kernelSize = preallocation(mb, nb); | |
| 466 | + nb.setData(builder.CreateCall(malloc, nb.bytes())); | |
| 467 | + builder.CreateRet(kernelSize); | |
| 468 | + | |
| 469 | + optimize(function); | |
| 470 | + } | |
| 471 | + | |
| 472 | + return (UnaryAllocation)TheExecutionEngine->getPointerToFunction(function); | |
| 473 | + } | |
| 474 | + | |
| 475 | + UnaryKernel getKernel(const Matrix *m) const | |
| 476 | + { | |
| 477 | + const QString name = mangledName(*m)+"_kernel"; | |
| 478 | + Function *function = TheModule->getFunction(qPrintable(name)); | |
| 479 | + | |
| 480 | + if (function == NULL) { | |
| 481 | + function = cast<Function>(TheModule->getOrInsertFunction(qPrintable(name), | |
| 482 | + Type::getVoidTy(getGlobalContext()), | |
| 483 | + PointerType::getUnqual(TheMatrixStruct), | |
| 484 | + PointerType::getUnqual(TheMatrixStruct), | |
| 485 | + Type::getInt32Ty(getGlobalContext()), | |
| 486 | + NULL)); | |
| 487 | + function->setCallingConv(CallingConv::C); | |
| 488 | + | |
| 489 | + Function::arg_iterator args = function->arg_begin(); | |
| 490 | + Value *src = args++; | |
| 491 | + src->setName("src"); | |
| 492 | + Value *dst = args++; | |
| 493 | + dst->setName("dst"); | |
| 494 | + Value *len = args++; | |
| 495 | + len->setName("len"); | |
| 496 | + | |
| 497 | + BasicBlock *entry = BasicBlock::Create(getGlobalContext(), "entry", function); | |
| 498 | + IRBuilder<> builder(entry); | |
| 499 | + | |
| 500 | + BasicBlock *loop, *exit; | |
| 501 | + PHINode *i = MatrixBuilder::beginLoop(builder, function, entry, loop, exit, len, "i"); | |
| 502 | + | |
| 503 | + Matrix n; | |
| 504 | + kernel(MatrixBuilder(m, src, &builder, function, "src"), MatrixBuilder(&n, dst, &builder, function, "dst"), i); | |
| 505 | + | |
| 506 | + MatrixBuilder::endLoop(builder, loop, exit); | |
| 507 | + builder.CreateRetVoid(); | |
| 508 | + | |
| 509 | + optimize(function); | |
| 510 | + } | |
| 511 | + | |
| 368 | 512 | return (UnaryKernel)TheExecutionEngine->getPointerToFunction(function); |
| 369 | 513 | } |
| 370 | 514 | |
| ... | ... | @@ -383,114 +527,11 @@ private: |
| 383 | 527 | return mangledName() + "_" + MatrixToString(src); |
| 384 | 528 | } |
| 385 | 529 | |
| 386 | - Function *compile(const Matrix &m) const | |
| 387 | - { | |
| 388 | - Constant *c = TheModule->getOrInsertFunction(qPrintable(mangledName()), | |
| 389 | - Type::getVoidTy(getGlobalContext()), | |
| 390 | - PointerType::getUnqual(TheMatrixStruct), | |
| 391 | - PointerType::getUnqual(TheMatrixStruct), | |
| 392 | - NULL); | |
| 393 | - | |
| 394 | - Function *function = cast<Function>(c); | |
| 395 | - function->setCallingConv(CallingConv::C); | |
| 396 | - | |
| 397 | - Function::arg_iterator args = function->arg_begin(); | |
| 398 | - Value *src = args++; | |
| 399 | - src->setName("src"); | |
| 400 | - Value *dst = args++; | |
| 401 | - dst->setName("dst"); | |
| 402 | - | |
| 403 | - BasicBlock *entry = BasicBlock::Create(getGlobalContext(), "entry", function); | |
| 404 | - IRBuilder<> builder(entry); | |
| 405 | - MatrixBuilder mb(&m, src, &builder, function, "src"); | |
| 406 | - MatrixBuilder nb(&m, dst, &builder, function, "dst"); | |
| 407 | - | |
| 408 | - std::vector<Type*> kernelArgs; | |
| 409 | - kernelArgs.push_back(PointerType::getUnqual(TheMatrixStruct)); | |
| 410 | - kernelArgs.push_back(PointerType::getUnqual(TheMatrixStruct)); | |
| 411 | - kernelArgs.push_back(Type::getInt32Ty(getGlobalContext())); | |
| 412 | - PointerType *kernelType = PointerType::getUnqual(FunctionType::get(Type::getVoidTy(getGlobalContext()), kernelArgs, false)); | |
| 413 | - QString kernelFunctionName = mangledName()+"_kernel"; | |
| 414 | - TheModule->getOrInsertGlobal(qPrintable(kernelFunctionName), kernelType); | |
| 415 | - GlobalVariable *kernelFunction = TheModule->getGlobalVariable(qPrintable(kernelFunctionName)); | |
| 416 | - kernelFunction->setInitializer(ConstantPointerNull::get(kernelType)); | |
| 417 | - | |
| 418 | - QString kernelHashName = mangledName()+"_hash"; | |
| 419 | - TheModule->getOrInsertGlobal(qPrintable(kernelHashName), Type::getInt16Ty(getGlobalContext())); | |
| 420 | - GlobalVariable *kernelHash = TheModule->getGlobalVariable(qPrintable(kernelHashName)); | |
| 421 | - kernelHash->setInitializer(MatrixBuilder::constant(0, 16)); | |
| 422 | - | |
| 423 | - BasicBlock *getKernel = BasicBlock::Create(getGlobalContext(), "get_kernel", function); | |
| 424 | - BasicBlock *preallocate = BasicBlock::Create(getGlobalContext(), "preallocate", function); | |
| 425 | - Value *hashTest = builder.CreateICmpNE(mb.hash(), builder.CreateLoad(kernelHash), "hash_fail_test"); | |
| 426 | - builder.CreateCondBr(hashTest, getKernel, preallocate); | |
| 427 | - | |
| 428 | - builder.SetInsertPoint(getKernel); | |
| 429 | - builder.CreateStore(builder.CreateCall2(makeUnaryKernelFunction, | |
| 430 | - builder.CreateIntToPtr(MatrixBuilder::constant(fileIndex, 32), Type::getInt8PtrTy(getGlobalContext())), | |
| 431 | - src), | |
| 432 | - kernelFunction); | |
| 433 | - builder.CreateStore(mb.hash(), kernelHash); | |
| 434 | - builder.CreateBr(preallocate); | |
| 435 | - builder.SetInsertPoint(preallocate); | |
| 436 | - Value *kernelSize = buildPreallocate(mb, nb); | |
| 437 | - | |
| 438 | - BasicBlock *allocate = BasicBlock::Create(getGlobalContext(), "allocate", function); | |
| 439 | - builder.CreateBr(allocate); | |
| 440 | - builder.SetInsertPoint(allocate); | |
| 441 | - nb.allocate(); | |
| 442 | - | |
| 443 | - BasicBlock *callKernel = BasicBlock::Create(getGlobalContext(), "call_kernel", function); | |
| 444 | - builder.CreateBr(callKernel); | |
| 445 | - builder.SetInsertPoint(callKernel); | |
| 446 | - builder.CreateCall3(builder.CreateLoad(kernelFunction), src, dst, kernelSize); | |
| 447 | - builder.CreateRetVoid(); | |
| 448 | - | |
| 449 | - optimize(function); | |
| 450 | - return function; | |
| 451 | - } | |
| 452 | - | |
| 453 | - Function *compileKernel(const Matrix &m) const | |
| 454 | - { | |
| 455 | - Constant *c = TheModule->getOrInsertFunction(qPrintable(mangledName(m)), | |
| 456 | - Type::getVoidTy(getGlobalContext()), | |
| 457 | - PointerType::getUnqual(TheMatrixStruct), | |
| 458 | - PointerType::getUnqual(TheMatrixStruct), | |
| 459 | - Type::getInt32Ty(getGlobalContext()), | |
| 460 | - NULL); | |
| 461 | - | |
| 462 | - Function *function = cast<Function>(c); | |
| 463 | - function->setCallingConv(CallingConv::C); | |
| 464 | - | |
| 465 | - Function::arg_iterator args = function->arg_begin(); | |
| 466 | - Value *src = args++; | |
| 467 | - src->setName("src"); | |
| 468 | - Value *dst = args++; | |
| 469 | - dst->setName("dst"); | |
| 470 | - Value *len = args++; | |
| 471 | - len->setName("len"); | |
| 472 | - | |
| 473 | - BasicBlock *entry = BasicBlock::Create(getGlobalContext(), "entry", function); | |
| 474 | - IRBuilder<> builder(entry); | |
| 475 | - | |
| 476 | - BasicBlock *loop, *exit; | |
| 477 | - PHINode *i = MatrixBuilder::beginLoop(builder, function, entry, loop, exit, len, "i"); | |
| 478 | - | |
| 479 | - Matrix n; | |
| 480 | - preallocate(m, n); | |
| 481 | - build(MatrixBuilder(&m, src, &builder, function, "src"), MatrixBuilder(&n, dst, &builder, function, "dst"), i); | |
| 482 | - | |
| 483 | - MatrixBuilder::endLoop(builder, loop, exit); | |
| 484 | - | |
| 485 | - builder.CreateRetVoid(); | |
| 486 | - return function; | |
| 487 | - } | |
| 488 | - | |
| 489 | 530 | void project(const Template &src, Template &dst) const |
| 490 | 531 | { |
| 491 | 532 | const Matrix m(MatrixFromMat(src)); |
| 492 | 533 | Matrix n; |
| 493 | - UnaryFunction function = getFunction(&m); | |
| 534 | + UnaryFunction function = getFunction(); | |
| 494 | 535 | function(&m, &n); |
| 495 | 536 | dst.m() = MatFromMatrix(n); |
| 496 | 537 | } |
| ... | ... | @@ -502,96 +543,96 @@ QHash<uint32_t, File> UnaryTransform::fileTable; |
| 502 | 543 | * \brief LLVM Binary Kernel |
| 503 | 544 | * \author Josh Klontz \cite jklontz |
| 504 | 545 | */ |
| 505 | -class BinaryTransform: public UntrainableMetaTransform | |
| 506 | -{ | |
| 507 | - Q_OBJECT | |
| 508 | - | |
| 509 | - BinaryKernel kernel; | |
| 510 | - quint16 hashA, hashB; | |
| 511 | - | |
| 512 | -public: | |
| 513 | - BinaryTransform() : kernel(NULL), hashA(0), hashB(0) {} | |
| 514 | - virtual int preallocate(const Matrix &srcA, const Matrix &srcB, Matrix &dst) const = 0; /*!< Preallocate destintation matrix based on source matrix. */ | |
| 515 | - virtual void build(const MatrixBuilder &srcA, const MatrixBuilder &srcB, const MatrixBuilder &dst, PHINode *i) const = 0; /*!< Build the kernel. */ | |
| 516 | - | |
| 517 | - void apply(const Matrix &srcA, const Matrix &srcB, Matrix &dst) const | |
| 518 | - { | |
| 519 | - const int size = preallocate(srcA, srcB, dst); | |
| 520 | - dst.allocate(); | |
| 521 | - invoke(srcA, srcB, dst, size); | |
| 522 | - } | |
| 523 | - | |
| 524 | -private: | |
| 525 | - QString mangledName(const Matrix &srcA, const Matrix &srcB) const | |
| 526 | - { | |
| 527 | - return "jitcv_" + objectName() + "_" + MatrixToString(srcA) + "_" + MatrixToString(srcB); | |
| 528 | - } | |
| 529 | - | |
| 530 | - Function *compile(const Matrix &m, const Matrix &n) const | |
| 531 | - { | |
| 532 | - Constant *c = TheModule->getOrInsertFunction(qPrintable(mangledName(m, n)), | |
| 533 | - Type::getVoidTy(getGlobalContext()), | |
| 534 | - PointerType::getUnqual(TheMatrixStruct), | |
| 535 | - PointerType::getUnqual(TheMatrixStruct), | |
| 536 | - PointerType::getUnqual(TheMatrixStruct), | |
| 537 | - Type::getInt32Ty(getGlobalContext()), | |
| 538 | - NULL); | |
| 539 | - | |
| 540 | - Function *function = cast<Function>(c); | |
| 541 | - function->setCallingConv(CallingConv::C); | |
| 542 | - | |
| 543 | - Function::arg_iterator args = function->arg_begin(); | |
| 544 | - Value *srcA = args++; | |
| 545 | - srcA->setName("srcA"); | |
| 546 | - Value *srcB = args++; | |
| 547 | - srcB->setName("srcB"); | |
| 548 | - Value *dst = args++; | |
| 549 | - dst->setName("dst"); | |
| 550 | - Value *len = args++; | |
| 551 | - len->setName("len"); | |
| 552 | - | |
| 553 | - BasicBlock *entry = BasicBlock::Create(getGlobalContext(), "entry", function); | |
| 554 | - IRBuilder<> builder(entry); | |
| 555 | - | |
| 556 | - BasicBlock *loop, *exit; | |
| 557 | - PHINode *i = MatrixBuilder::beginLoop(builder, function, entry, loop, exit, len, "i"); | |
| 558 | - | |
| 559 | - Matrix o; | |
| 560 | - preallocate(m, n, o); | |
| 561 | - build(MatrixBuilder(&m, srcA, &builder, function, "srcA"), MatrixBuilder(&n, srcB, &builder, function, "srcB"), MatrixBuilder(&o, dst, &builder, function, "dst"), i); | |
| 562 | - | |
| 563 | - MatrixBuilder::endLoop(builder, loop, exit); | |
| 564 | - | |
| 565 | - builder.CreateRetVoid(); | |
| 566 | - return function; | |
| 567 | - } | |
| 568 | - | |
| 569 | - void invoke(const Matrix &srcA, const Matrix &srcB, Matrix &dst, int size) const | |
| 570 | - { | |
| 571 | - if ((srcA.hash != hashA) || (srcB.hash != hashB)) { | |
| 572 | - static QMutex compilerLock; | |
| 573 | - QMutexLocker locker(&compilerLock); | |
| 574 | - | |
| 575 | - if ((srcA.hash != hashA) || (srcB.hash != hashB)) { | |
| 576 | - const QString functionName = mangledName(srcA, srcB); | |
| 577 | - | |
| 578 | - Function *function = TheModule->getFunction(qPrintable(functionName)); | |
| 579 | - if (function == NULL) { | |
| 580 | - function = compile(srcA, srcB); | |
| 581 | - while (TheFunctionPassManager->run(*function)); | |
| 582 | - TheExtraFunctionPassManager->run(*function); | |
| 583 | - function = TheModule->getFunction(qPrintable(functionName)); | |
| 584 | - } | |
| 585 | - | |
| 586 | - const_cast<BinaryTransform*>(this)->kernel = (BinaryKernel)TheExecutionEngine->getPointerToFunction(function); | |
| 587 | - const_cast<BinaryTransform*>(this)->hashA = srcA.hash; | |
| 588 | - const_cast<BinaryTransform*>(this)->hashB = srcB.hash; | |
| 589 | - } | |
| 590 | - } | |
| 591 | - | |
| 592 | - kernel(&srcA, &srcB, &dst, size); | |
| 593 | - } | |
| 594 | -}; | |
| 546 | +//class BinaryTransform: public UntrainableMetaTransform | |
| 547 | +//{ | |
| 548 | +// Q_OBJECT | |
| 549 | + | |
| 550 | +// BinaryKernel kernel; | |
| 551 | +// quint16 hashA, hashB; | |
| 552 | + | |
| 553 | +//public: | |
| 554 | +// BinaryTransform() : kernel(NULL), hashA(0), hashB(0) {} | |
| 555 | +// virtual int preallocate(const Matrix &srcA, const Matrix &srcB, Matrix &dst) const = 0; /*!< Preallocate destintation matrix based on source matrix. */ | |
| 556 | +// virtual void build(const MatrixBuilder &srcA, const MatrixBuilder &srcB, const MatrixBuilder &dst, PHINode *i) const = 0; /*!< Build the kernel. */ | |
| 557 | + | |
| 558 | +// void apply(const Matrix &srcA, const Matrix &srcB, Matrix &dst) const | |
| 559 | +// { | |
| 560 | +// const int size = preallocate(srcA, srcB, dst); | |
| 561 | +// dst.allocate(); | |
| 562 | +// invoke(srcA, srcB, dst, size); | |
| 563 | +// } | |
| 564 | + | |
| 565 | +//private: | |
| 566 | +// QString mangledName(const Matrix &srcA, const Matrix &srcB) const | |
| 567 | +// { | |
| 568 | +// return "jitcv_" + objectName() + "_" + MatrixToString(srcA) + "_" + MatrixToString(srcB); | |
| 569 | +// } | |
| 570 | + | |
| 571 | +// Function *compile(const Matrix &m, const Matrix &n) const | |
| 572 | +// { | |
| 573 | +// Constant *c = TheModule->getOrInsertFunction(qPrintable(mangledName(m, n)), | |
| 574 | +// Type::getVoidTy(getGlobalContext()), | |
| 575 | +// PointerType::getUnqual(TheMatrixStruct), | |
| 576 | +// PointerType::getUnqual(TheMatrixStruct), | |
| 577 | +// PointerType::getUnqual(TheMatrixStruct), | |
| 578 | +// Type::getInt32Ty(getGlobalContext()), | |
| 579 | +// NULL); | |
| 580 | + | |
| 581 | +// Function *function = cast<Function>(c); | |
| 582 | +// function->setCallingConv(CallingConv::C); | |
| 583 | + | |
| 584 | +// Function::arg_iterator args = function->arg_begin(); | |
| 585 | +// Value *srcA = args++; | |
| 586 | +// srcA->setName("srcA"); | |
| 587 | +// Value *srcB = args++; | |
| 588 | +// srcB->setName("srcB"); | |
| 589 | +// Value *dst = args++; | |
| 590 | +// dst->setName("dst"); | |
| 591 | +// Value *len = args++; | |
| 592 | +// len->setName("len"); | |
| 593 | + | |
| 594 | +// BasicBlock *entry = BasicBlock::Create(getGlobalContext(), "entry", function); | |
| 595 | +// IRBuilder<> builder(entry); | |
| 596 | + | |
| 597 | +// BasicBlock *loop, *exit; | |
| 598 | +// PHINode *i = MatrixBuilder::beginLoop(builder, function, entry, loop, exit, len, "i"); | |
| 599 | + | |
| 600 | +// Matrix o; | |
| 601 | +// preallocate(m, n, o); | |
| 602 | +// build(MatrixBuilder(&m, srcA, &builder, function, "srcA"), MatrixBuilder(&n, srcB, &builder, function, "srcB"), MatrixBuilder(&o, dst, &builder, function, "dst"), i); | |
| 603 | + | |
| 604 | +// MatrixBuilder::endLoop(builder, loop, exit); | |
| 605 | + | |
| 606 | +// builder.CreateRetVoid(); | |
| 607 | +// return function; | |
| 608 | +// } | |
| 609 | + | |
| 610 | +// void invoke(const Matrix &srcA, const Matrix &srcB, Matrix &dst, int size) const | |
| 611 | +// { | |
| 612 | +// if ((srcA.hash != hashA) || (srcB.hash != hashB)) { | |
| 613 | +// static QMutex compilerLock; | |
| 614 | +// QMutexLocker locker(&compilerLock); | |
| 615 | + | |
| 616 | +// if ((srcA.hash != hashA) || (srcB.hash != hashB)) { | |
| 617 | +// const QString functionName = mangledName(srcA, srcB); | |
| 618 | + | |
| 619 | +// Function *function = TheModule->getFunction(qPrintable(functionName)); | |
| 620 | +// if (function == NULL) { | |
| 621 | +// function = compile(srcA, srcB); | |
| 622 | +// while (TheFunctionPassManager->run(*function)); | |
| 623 | +// TheExtraFunctionPassManager->run(*function); | |
| 624 | +// function = TheModule->getFunction(qPrintable(functionName)); | |
| 625 | +// } | |
| 626 | + | |
| 627 | +// const_cast<BinaryTransform*>(this)->kernel = (BinaryKernel)TheExecutionEngine->getPointerToFunction(function); | |
| 628 | +// const_cast<BinaryTransform*>(this)->hashA = srcA.hash; | |
| 629 | +// const_cast<BinaryTransform*>(this)->hashB = srcB.hash; | |
| 630 | +// } | |
| 631 | +// } | |
| 632 | + | |
| 633 | +// kernel(&srcA, &srcB, &dst, size); | |
| 634 | +// } | |
| 635 | +//}; | |
| 595 | 636 | |
| 596 | 637 | /*! |
| 597 | 638 | * \brief LLVM Stitchable Kernel |
| ... | ... | @@ -604,20 +645,14 @@ class StitchableTransform : public UnaryTransform |
| 604 | 645 | public: |
| 605 | 646 | virtual Value *stitch(const MatrixBuilder &src, const MatrixBuilder &dst, Value *val) const = 0; /*!< A simplification of Kernel::build() for stitchable kernels. */ |
| 606 | 647 | |
| 607 | - virtual int preallocate(const Matrix &src, Matrix &dst) const | |
| 608 | - { | |
| 609 | - dst.copyHeader(src); | |
| 610 | - return dst.elements(); | |
| 611 | - } | |
| 612 | - | |
| 613 | - virtual Value *buildPreallocate(const MatrixBuilder &src, const MatrixBuilder &dst) const | |
| 648 | + virtual Value *preallocation(const MatrixBuilder &src, const MatrixBuilder &dst) const | |
| 614 | 649 | { |
| 615 | 650 | dst.copyHeader(src); |
| 616 | 651 | return dst.elements(); |
| 617 | 652 | } |
| 618 | 653 | |
| 619 | 654 | private: |
| 620 | - void build(const MatrixBuilder &src, const MatrixBuilder &dst, PHINode *i) const | |
| 655 | + void kernel(const MatrixBuilder &src, const MatrixBuilder &dst, PHINode *i) const | |
| 621 | 656 | { |
| 622 | 657 | dst.store(i, stitch(src, dst, src.load(i))); |
| 623 | 658 | } |
| ... | ... | @@ -630,278 +665,278 @@ private: |
| 630 | 665 | * \brief LLVM stitch transform |
| 631 | 666 | * \author Josh Klontz \cite jklontz |
| 632 | 667 | */ |
| 633 | -class stitchTransform : public UnaryTransform | |
| 634 | -{ | |
| 635 | - Q_OBJECT | |
| 636 | - Q_PROPERTY(QList<br::Transform*> kernels READ get_kernels WRITE set_kernels RESET reset_kernels STORED false) | |
| 637 | - BR_PROPERTY(QList<br::Transform*>, kernels, QList<br::Transform*>()) | |
| 638 | - | |
| 639 | - void init() | |
| 640 | - { | |
| 641 | - foreach (Transform *transform, kernels) | |
| 642 | - if (dynamic_cast<StitchableTransform*>(transform) == NULL) | |
| 643 | - qFatal("%s is not a stitchable transform!", qPrintable(transform->objectName())); | |
| 644 | - } | |
| 645 | - | |
| 646 | - int preallocate(const Matrix &src, Matrix &dst) const | |
| 647 | - { | |
| 648 | - Matrix tmp = src; | |
| 649 | - foreach (const Transform *kernel, kernels) { | |
| 650 | - static_cast<const UnaryTransform*>(kernel)->preallocate(tmp, dst); | |
| 651 | - tmp = dst; | |
| 652 | - } | |
| 653 | - return dst.elements(); | |
| 654 | - } | |
| 655 | - | |
| 656 | - void build(const MatrixBuilder &src_, const MatrixBuilder &dst_, PHINode *i) const | |
| 657 | - { | |
| 658 | - MatrixBuilder src(src_); | |
| 659 | - MatrixBuilder dst(dst_); | |
| 660 | - Value *val = src.load(i); | |
| 661 | - foreach (Transform *transform, kernels) { | |
| 662 | - static_cast<UnaryTransform*>(transform)->preallocate(*src.m, *const_cast<Matrix*>(dst.m)); | |
| 663 | - val = static_cast<StitchableTransform*>(transform)->stitch(src, dst, val); | |
| 664 | - //src.m->copyHeader(*dst.m); | |
| 665 | - //src.v = dst.v; | |
| 666 | - } | |
| 667 | - dst.store(i, val); | |
| 668 | - } | |
| 669 | -}; | |
| 670 | - | |
| 671 | -BR_REGISTER(Transform, stitchTransform) | |
| 668 | +//class stitchTransform : public UnaryTransform | |
| 669 | +//{ | |
| 670 | +// Q_OBJECT | |
| 671 | +// Q_PROPERTY(QList<br::Transform*> kernels READ get_kernels WRITE set_kernels RESET reset_kernels STORED false) | |
| 672 | +// BR_PROPERTY(QList<br::Transform*>, kernels, QList<br::Transform*>()) | |
| 673 | + | |
| 674 | +// void init() | |
| 675 | +// { | |
| 676 | +// foreach (Transform *transform, kernels) | |
| 677 | +// if (dynamic_cast<StitchableTransform*>(transform) == NULL) | |
| 678 | +// qFatal("%s is not a stitchable transform!", qPrintable(transform->objectName())); | |
| 679 | +// } | |
| 680 | + | |
| 681 | +// int preallocate(const Matrix &src, Matrix &dst) const | |
| 682 | +// { | |
| 683 | +// Matrix tmp = src; | |
| 684 | +// foreach (const Transform *kernel, kernels) { | |
| 685 | +// static_cast<const UnaryTransform*>(kernel)->preallocate(tmp, dst); | |
| 686 | +// tmp = dst; | |
| 687 | +// } | |
| 688 | +// return dst.elements(); | |
| 689 | +// } | |
| 690 | + | |
| 691 | +// void build(const MatrixBuilder &src_, const MatrixBuilder &dst_, PHINode *i) const | |
| 692 | +// { | |
| 693 | +// MatrixBuilder src(src_); | |
| 694 | +// MatrixBuilder dst(dst_); | |
| 695 | +// Value *val = src.load(i); | |
| 696 | +// foreach (Transform *transform, kernels) { | |
| 697 | +// static_cast<UnaryTransform*>(transform)->preallocate(*src.m, *const_cast<Matrix*>(dst.m)); | |
| 698 | +// val = static_cast<StitchableTransform*>(transform)->stitch(src, dst, val); | |
| 699 | +// //src.m->copyHeader(*dst.m); | |
| 700 | +// //src.v = dst.v; | |
| 701 | +// } | |
| 702 | +// dst.store(i, val); | |
| 703 | +// } | |
| 704 | +//}; | |
| 705 | + | |
| 706 | +//BR_REGISTER(Transform, stitchTransform) | |
| 672 | 707 | |
| 673 | 708 | /*! |
| 674 | 709 | * \ingroup transforms |
| 675 | 710 | * \brief LLVM square transform |
| 676 | 711 | * \author Josh Klontz \cite jklontz |
| 677 | 712 | */ |
| 678 | -class squareTransform : public StitchableTransform | |
| 679 | -{ | |
| 680 | - Q_OBJECT | |
| 713 | +//class squareTransform : public StitchableTransform | |
| 714 | +//{ | |
| 715 | +// Q_OBJECT | |
| 681 | 716 | |
| 682 | - Value *stitch(const MatrixBuilder &src, const MatrixBuilder &dst, Value *val) const | |
| 683 | - { | |
| 684 | - (void) src; | |
| 685 | - return dst.multiply(val, val); | |
| 686 | - } | |
| 687 | -}; | |
| 717 | +// Value *stitch(const MatrixBuilder &src, const MatrixBuilder &dst, Value *val) const | |
| 718 | +// { | |
| 719 | +// (void) src; | |
| 720 | +// return dst.multiply(val, val); | |
| 721 | +// } | |
| 722 | +//}; | |
| 688 | 723 | |
| 689 | -BR_REGISTER(Transform, squareTransform) | |
| 724 | +//BR_REGISTER(Transform, squareTransform) | |
| 690 | 725 | |
| 691 | 726 | /*! |
| 692 | 727 | * \ingroup transforms |
| 693 | 728 | * \brief LLVM pow transform |
| 694 | 729 | * \author Josh Klontz \cite jklontz |
| 695 | 730 | */ |
| 696 | -class powTransform : public StitchableTransform | |
| 697 | -{ | |
| 698 | - Q_OBJECT | |
| 699 | - Q_PROPERTY(double exponent READ get_exponent WRITE set_exponent RESET reset_exponent STORED false) | |
| 700 | - BR_PROPERTY(double, exponent, 2) | |
| 701 | - | |
| 702 | - int preallocate(const Matrix &src, Matrix &dst) const | |
| 703 | - { | |
| 704 | - dst.copyHeader(src); | |
| 705 | - dst.setFloating(true); | |
| 706 | - dst.setBits(max(src.bits(), 32)); | |
| 707 | - return dst.elements(); | |
| 708 | - } | |
| 709 | - | |
| 710 | - Value *stitch(const MatrixBuilder &src, const MatrixBuilder &dst, Value *val) const | |
| 711 | - { | |
| 712 | - Value *load = src.cast(val, dst); | |
| 713 | - | |
| 714 | - Value *pow; | |
| 715 | - if (exponent == ceil(exponent)) { | |
| 716 | - if (exponent == 0) pow = dst.autoConstant(1); | |
| 717 | - else if (exponent == 1) pow = load; | |
| 718 | - else if (exponent == 2) pow = dst.multiply(load, load); | |
| 719 | - else pow = src.b->CreateCall2(Intrinsic::getDeclaration(TheModule, Intrinsic::powi, dst.tys()), load, MatrixBuilder::constant(int(exponent))); | |
| 720 | - } else { | |
| 721 | - pow = src.b->CreateCall2(Intrinsic::getDeclaration(TheModule, Intrinsic::pow, dst.tys()), load, dst.autoConstant(exponent)); | |
| 722 | - } | |
| 723 | - | |
| 724 | - return pow; | |
| 725 | - } | |
| 726 | -}; | |
| 727 | - | |
| 728 | -BR_REGISTER(Transform, powTransform) | |
| 731 | +//class powTransform : public StitchableTransform | |
| 732 | +//{ | |
| 733 | +// Q_OBJECT | |
| 734 | +// Q_PROPERTY(double exponent READ get_exponent WRITE set_exponent RESET reset_exponent STORED false) | |
| 735 | +// BR_PROPERTY(double, exponent, 2) | |
| 736 | + | |
| 737 | +// int preallocate(const Matrix &src, Matrix &dst) const | |
| 738 | +// { | |
| 739 | +// dst.copyHeader(src); | |
| 740 | +// dst.setFloating(true); | |
| 741 | +// dst.setBits(max(src.bits(), 32)); | |
| 742 | +// return dst.elements(); | |
| 743 | +// } | |
| 744 | + | |
| 745 | +// Value *stitch(const MatrixBuilder &src, const MatrixBuilder &dst, Value *val) const | |
| 746 | +// { | |
| 747 | +// Value *load = src.cast(val, dst); | |
| 748 | + | |
| 749 | +// Value *pow; | |
| 750 | +// if (exponent == ceil(exponent)) { | |
| 751 | +// if (exponent == 0) pow = dst.autoConstant(1); | |
| 752 | +// else if (exponent == 1) pow = load; | |
| 753 | +// else if (exponent == 2) pow = dst.multiply(load, load); | |
| 754 | +// else pow = src.b->CreateCall2(Intrinsic::getDeclaration(TheModule, Intrinsic::powi, dst.tys()), load, MatrixBuilder::constant(int(exponent))); | |
| 755 | +// } else { | |
| 756 | +// pow = src.b->CreateCall2(Intrinsic::getDeclaration(TheModule, Intrinsic::pow, dst.tys()), load, dst.autoConstant(exponent)); | |
| 757 | +// } | |
| 758 | + | |
| 759 | +// return pow; | |
| 760 | +// } | |
| 761 | +//}; | |
| 762 | + | |
| 763 | +//BR_REGISTER(Transform, powTransform) | |
| 729 | 764 | |
| 730 | 765 | /*! |
| 731 | 766 | * \ingroup transforms |
| 732 | 767 | * \brief LLVM sum transform |
| 733 | 768 | * \author Josh Klontz \cite jklontz |
| 734 | 769 | */ |
| 735 | -class sumTransform : public UnaryTransform | |
| 736 | -{ | |
| 737 | - Q_OBJECT | |
| 738 | - Q_PROPERTY(bool channels READ get_channels WRITE set_channels RESET reset_channels STORED false) | |
| 739 | - Q_PROPERTY(bool columns READ get_columns WRITE set_columns RESET reset_columns STORED false) | |
| 740 | - Q_PROPERTY(bool rows READ get_rows WRITE set_rows RESET reset_rows STORED false) | |
| 741 | - Q_PROPERTY(bool frames READ get_frames WRITE set_frames RESET reset_frames STORED false) | |
| 742 | - BR_PROPERTY(bool, channels, true) | |
| 743 | - BR_PROPERTY(bool, columns, true) | |
| 744 | - BR_PROPERTY(bool, rows, true) | |
| 745 | - BR_PROPERTY(bool, frames, true) | |
| 746 | - | |
| 747 | - int preallocate(const Matrix &src, Matrix &dst) const | |
| 748 | - { | |
| 749 | - dst = Matrix(channels ? 1 : src.channels, columns ? 1 : src.columns, rows ? 1 : src.rows, frames ? 1 : src.frames, src.hash); | |
| 750 | - dst.setBits(std::min(2*dst.bits(), dst.isFloating() ? 64 : 32)); | |
| 751 | - return dst.elements(); | |
| 752 | - } | |
| 753 | - | |
| 754 | - Value *buildPreallocate(const MatrixBuilder &src, const MatrixBuilder &dst) const | |
| 755 | - { | |
| 756 | - (void) src; | |
| 757 | - (void) dst; | |
| 758 | - return MatrixBuilder::constant(0); | |
| 759 | - } | |
| 760 | - | |
| 761 | - void build(const MatrixBuilder &src, const MatrixBuilder &dst, PHINode *i) const | |
| 762 | - { | |
| 763 | - Value *c, *x, *y, *t; | |
| 764 | - dst.deindex(i, &c, &x, &y, &t); | |
| 765 | - AllocaInst *sum = dst.autoAlloca(0, "sum"); | |
| 766 | - | |
| 767 | - QList<BasicBlock*> loops, exits; | |
| 768 | - loops.push_back(i->getParent()); | |
| 769 | - Value *src_c, *src_x, *src_y, *src_t; | |
| 770 | - | |
| 771 | - if (frames && !src.m->singleFrame()) { | |
| 772 | - BasicBlock *loop, *exit; | |
| 773 | - src_t = dst.beginLoop(loops.last(), loop, exit, src.frames(), "src_t"); | |
| 774 | - loops.append(loop); | |
| 775 | - exits.append(exit); | |
| 776 | - } else { | |
| 777 | - src_t = t; | |
| 778 | - } | |
| 779 | - | |
| 780 | - if (rows && !src.m->singleRow()) { | |
| 781 | - BasicBlock *loop, *exit; | |
| 782 | - src_y = dst.beginLoop(loops.last(), loop, exit, src.rows(), "src_y"); | |
| 783 | - loops.append(loop); | |
| 784 | - exits.append(exit); | |
| 785 | - } else { | |
| 786 | - src_y = y; | |
| 787 | - } | |
| 788 | - | |
| 789 | - if (columns && !src.m->singleColumn()) { | |
| 790 | - BasicBlock *loop, *exit; | |
| 791 | - src_x = dst.beginLoop(loops.last(), loop, exit, src.columns(), "src_x"); | |
| 792 | - loops.append(loop); | |
| 793 | - exits.append(exit); | |
| 794 | - } else { | |
| 795 | - src_x = x; | |
| 796 | - } | |
| 797 | - | |
| 798 | - if (channels && !src.m->singleChannel()) { | |
| 799 | - BasicBlock *loop, *exit; | |
| 800 | - src_c = dst.beginLoop(loops.last(), loop, exit, src.channels(), "src_c"); | |
| 801 | - loops.append(loop); | |
| 802 | - exits.append(exit); | |
| 803 | - } else { | |
| 804 | - src_c = c; | |
| 805 | - } | |
| 806 | - | |
| 807 | - dst.b->CreateStore(dst.add(dst.b->CreateLoad(sum), src.cast(src.load(src.aliasIndex(dst, src_c, src_x, src_y, src_t)), dst), "accumulate"), sum); | |
| 808 | - | |
| 809 | - if (channels && !src.m->singleChannel()) dst.endLoop(loops.takeLast(), exits.takeLast()); | |
| 810 | - if (columns && !src.m->singleColumn()) dst.endLoop(loops.takeLast(), exits.takeLast()); | |
| 811 | - if (rows && !src.m->singleRow()) dst.endLoop(loops.takeLast(), exits.takeLast()); | |
| 812 | - if (frames && !src.m->singleFrame()) dst.endLoop(loops.takeLast(), exits.takeLast()); | |
| 813 | - | |
| 814 | - dst.store(i, dst.b->CreateLoad(sum)); | |
| 815 | - } | |
| 816 | -}; | |
| 817 | - | |
| 818 | -BR_REGISTER(Transform, sumTransform) | |
| 770 | +//class sumTransform : public UnaryTransform | |
| 771 | +//{ | |
| 772 | +// Q_OBJECT | |
| 773 | +// Q_PROPERTY(bool channels READ get_channels WRITE set_channels RESET reset_channels STORED false) | |
| 774 | +// Q_PROPERTY(bool columns READ get_columns WRITE set_columns RESET reset_columns STORED false) | |
| 775 | +// Q_PROPERTY(bool rows READ get_rows WRITE set_rows RESET reset_rows STORED false) | |
| 776 | +// Q_PROPERTY(bool frames READ get_frames WRITE set_frames RESET reset_frames STORED false) | |
| 777 | +// BR_PROPERTY(bool, channels, true) | |
| 778 | +// BR_PROPERTY(bool, columns, true) | |
| 779 | +// BR_PROPERTY(bool, rows, true) | |
| 780 | +// BR_PROPERTY(bool, frames, true) | |
| 781 | + | |
| 782 | +// int preallocate(const Matrix &src, Matrix &dst) const | |
| 783 | +// { | |
| 784 | +// dst = Matrix(channels ? 1 : src.channels, columns ? 1 : src.columns, rows ? 1 : src.rows, frames ? 1 : src.frames, src.hash); | |
| 785 | +// dst.setBits(std::min(2*dst.bits(), dst.isFloating() ? 64 : 32)); | |
| 786 | +// return dst.elements(); | |
| 787 | +// } | |
| 788 | + | |
| 789 | +// Value *buildPreallocate(const MatrixBuilder &src, const MatrixBuilder &dst) const | |
| 790 | +// { | |
| 791 | +// (void) src; | |
| 792 | +// (void) dst; | |
| 793 | +// return MatrixBuilder::constant(0); | |
| 794 | +// } | |
| 795 | + | |
| 796 | +// void build(const MatrixBuilder &src, const MatrixBuilder &dst, PHINode *i) const | |
| 797 | +// { | |
| 798 | +// Value *c, *x, *y, *t; | |
| 799 | +// dst.deindex(i, &c, &x, &y, &t); | |
| 800 | +// AllocaInst *sum = dst.autoAlloca(0, "sum"); | |
| 801 | + | |
| 802 | +// QList<BasicBlock*> loops, exits; | |
| 803 | +// loops.push_back(i->getParent()); | |
| 804 | +// Value *src_c, *src_x, *src_y, *src_t; | |
| 805 | + | |
| 806 | +// if (frames && !src.m->singleFrame()) { | |
| 807 | +// BasicBlock *loop, *exit; | |
| 808 | +// src_t = dst.beginLoop(loops.last(), loop, exit, src.frames(), "src_t"); | |
| 809 | +// loops.append(loop); | |
| 810 | +// exits.append(exit); | |
| 811 | +// } else { | |
| 812 | +// src_t = t; | |
| 813 | +// } | |
| 814 | + | |
| 815 | +// if (rows && !src.m->singleRow()) { | |
| 816 | +// BasicBlock *loop, *exit; | |
| 817 | +// src_y = dst.beginLoop(loops.last(), loop, exit, src.rows(), "src_y"); | |
| 818 | +// loops.append(loop); | |
| 819 | +// exits.append(exit); | |
| 820 | +// } else { | |
| 821 | +// src_y = y; | |
| 822 | +// } | |
| 823 | + | |
| 824 | +// if (columns && !src.m->singleColumn()) { | |
| 825 | +// BasicBlock *loop, *exit; | |
| 826 | +// src_x = dst.beginLoop(loops.last(), loop, exit, src.columns(), "src_x"); | |
| 827 | +// loops.append(loop); | |
| 828 | +// exits.append(exit); | |
| 829 | +// } else { | |
| 830 | +// src_x = x; | |
| 831 | +// } | |
| 832 | + | |
| 833 | +// if (channels && !src.m->singleChannel()) { | |
| 834 | +// BasicBlock *loop, *exit; | |
| 835 | +// src_c = dst.beginLoop(loops.last(), loop, exit, src.channels(), "src_c"); | |
| 836 | +// loops.append(loop); | |
| 837 | +// exits.append(exit); | |
| 838 | +// } else { | |
| 839 | +// src_c = c; | |
| 840 | +// } | |
| 841 | + | |
| 842 | +// dst.b->CreateStore(dst.add(dst.b->CreateLoad(sum), src.cast(src.load(src.aliasIndex(dst, src_c, src_x, src_y, src_t)), dst), "accumulate"), sum); | |
| 843 | + | |
| 844 | +// if (channels && !src.m->singleChannel()) dst.endLoop(loops.takeLast(), exits.takeLast()); | |
| 845 | +// if (columns && !src.m->singleColumn()) dst.endLoop(loops.takeLast(), exits.takeLast()); | |
| 846 | +// if (rows && !src.m->singleRow()) dst.endLoop(loops.takeLast(), exits.takeLast()); | |
| 847 | +// if (frames && !src.m->singleFrame()) dst.endLoop(loops.takeLast(), exits.takeLast()); | |
| 848 | + | |
| 849 | +// dst.store(i, dst.b->CreateLoad(sum)); | |
| 850 | +// } | |
| 851 | +//}; | |
| 852 | + | |
| 853 | +//BR_REGISTER(Transform, sumTransform) | |
| 819 | 854 | |
| 820 | 855 | /*! |
| 821 | 856 | * \ingroup transforms |
| 822 | 857 | * \brief LLVM casting transform |
| 823 | 858 | * \author Josh Klontz \cite jklontz |
| 824 | 859 | */ |
| 825 | -class castTransform : public StitchableTransform | |
| 826 | -{ | |
| 827 | - Q_OBJECT | |
| 828 | - Q_ENUMS(Type) | |
| 829 | - Q_PROPERTY(Type type READ get_type WRITE set_type RESET reset_type STORED false) | |
| 830 | - | |
| 831 | -public: | |
| 832 | - /*!< */ | |
| 833 | - enum Type { u1 = Matrix::u1, | |
| 834 | - u8 = Matrix::u8, | |
| 835 | - u16 = Matrix::u16, | |
| 836 | - u32 = Matrix::u32, | |
| 837 | - u64 = Matrix::u64, | |
| 838 | - s8 = Matrix::s8, | |
| 839 | - s16 = Matrix::s16, | |
| 840 | - s32 = Matrix::s32, | |
| 841 | - s64 = Matrix::s64, | |
| 842 | - f16 = Matrix::f16, | |
| 843 | - f32 = Matrix::f32, | |
| 844 | - f64 = Matrix::f64 }; | |
| 845 | - | |
| 846 | -private: | |
| 847 | - BR_PROPERTY(Type, type, f32) | |
| 848 | - | |
| 849 | - int preallocate(const Matrix &src, Matrix &dst) const | |
| 850 | - { | |
| 851 | - dst.copyHeader(src); | |
| 852 | - dst.setType(type); | |
| 853 | - return dst.elements(); | |
| 854 | - } | |
| 855 | - | |
| 856 | - Value *stitch(const MatrixBuilder &src, const MatrixBuilder &dst, Value *val) const | |
| 857 | - { | |
| 858 | - return src.cast(val, dst); | |
| 859 | - } | |
| 860 | -}; | |
| 861 | - | |
| 862 | -BR_REGISTER(Transform, castTransform) | |
| 860 | +//class castTransform : public StitchableTransform | |
| 861 | +//{ | |
| 862 | +// Q_OBJECT | |
| 863 | +// Q_ENUMS(Type) | |
| 864 | +// Q_PROPERTY(Type type READ get_type WRITE set_type RESET reset_type STORED false) | |
| 865 | + | |
| 866 | +//public: | |
| 867 | +// /*!< */ | |
| 868 | +// enum Type { u1 = Matrix::u1, | |
| 869 | +// u8 = Matrix::u8, | |
| 870 | +// u16 = Matrix::u16, | |
| 871 | +// u32 = Matrix::u32, | |
| 872 | +// u64 = Matrix::u64, | |
| 873 | +// s8 = Matrix::s8, | |
| 874 | +// s16 = Matrix::s16, | |
| 875 | +// s32 = Matrix::s32, | |
| 876 | +// s64 = Matrix::s64, | |
| 877 | +// f16 = Matrix::f16, | |
| 878 | +// f32 = Matrix::f32, | |
| 879 | +// f64 = Matrix::f64 }; | |
| 880 | + | |
| 881 | +//private: | |
| 882 | +// BR_PROPERTY(Type, type, f32) | |
| 883 | + | |
| 884 | +// int preallocate(const Matrix &src, Matrix &dst) const | |
| 885 | +// { | |
| 886 | +// dst.copyHeader(src); | |
| 887 | +// dst.setType(type); | |
| 888 | +// return dst.elements(); | |
| 889 | +// } | |
| 890 | + | |
| 891 | +// Value *stitch(const MatrixBuilder &src, const MatrixBuilder &dst, Value *val) const | |
| 892 | +// { | |
| 893 | +// return src.cast(val, dst); | |
| 894 | +// } | |
| 895 | +//}; | |
| 896 | + | |
| 897 | +//BR_REGISTER(Transform, castTransform) | |
| 863 | 898 | |
| 864 | 899 | /*! |
| 865 | 900 | * \ingroup transforms |
| 866 | 901 | * \brief LLVM scale transform |
| 867 | 902 | * \author Josh Klontz \cite jklontz |
| 868 | 903 | */ |
| 869 | -class scaleTransform : public StitchableTransform | |
| 870 | -{ | |
| 871 | - Q_OBJECT | |
| 872 | - Q_PROPERTY(double a READ get_a WRITE set_a RESET reset_a STORED false) | |
| 873 | - BR_PROPERTY(double, a, 1) | |
| 904 | +//class scaleTransform : public StitchableTransform | |
| 905 | +//{ | |
| 906 | +// Q_OBJECT | |
| 907 | +// Q_PROPERTY(double a READ get_a WRITE set_a RESET reset_a STORED false) | |
| 908 | +// BR_PROPERTY(double, a, 1) | |
| 874 | 909 | |
| 875 | - Value *stitch(const MatrixBuilder &src, const MatrixBuilder &dst, Value *val) const | |
| 876 | - { | |
| 877 | - (void) src; | |
| 878 | - return dst.multiply(val, dst.autoConstant(a)); | |
| 879 | - } | |
| 880 | -}; | |
| 910 | +// Value *stitch(const MatrixBuilder &src, const MatrixBuilder &dst, Value *val) const | |
| 911 | +// { | |
| 912 | +// (void) src; | |
| 913 | +// return dst.multiply(val, dst.autoConstant(a)); | |
| 914 | +// } | |
| 915 | +//}; | |
| 881 | 916 | |
| 882 | -BR_REGISTER(Transform, scaleTransform) | |
| 917 | +//BR_REGISTER(Transform, scaleTransform) | |
| 883 | 918 | |
| 884 | 919 | /*! |
| 885 | 920 | * \ingroup absTransform |
| 886 | 921 | * \brief LLVM abs transform |
| 887 | 922 | * \author Josh Klontz \cite jklontz |
| 888 | 923 | */ |
| 889 | -class absTransform : public StitchableTransform | |
| 890 | -{ | |
| 891 | - Q_OBJECT | |
| 892 | - | |
| 893 | - Value *stitch(const MatrixBuilder &src, const MatrixBuilder &dst, Value *val) const | |
| 894 | - { | |
| 895 | - (void) dst; | |
| 896 | - if (!src.m->isSigned()) return val; | |
| 897 | - if (src.m->isFloating()) return src.b->CreateCall(Intrinsic::getDeclaration(TheModule, Intrinsic::fabs, src.tys()), val); | |
| 898 | - else return src.b->CreateSelect(src.b->CreateICmpSLT(val, src.autoConstant(0)), | |
| 899 | - src.b->CreateSub(src.autoConstant(0), val), | |
| 900 | - val); | |
| 901 | - } | |
| 902 | -}; | |
| 903 | - | |
| 904 | -BR_REGISTER(Transform, absTransform) | |
| 924 | +//class absTransform : public StitchableTransform | |
| 925 | +//{ | |
| 926 | +// Q_OBJECT | |
| 927 | + | |
| 928 | +// Value *stitch(const MatrixBuilder &src, const MatrixBuilder &dst, Value *val) const | |
| 929 | +// { | |
| 930 | +// (void) dst; | |
| 931 | +// if (!src.m->isSigned()) return val; | |
| 932 | +// if (src.m->isFloating()) return src.b->CreateCall(Intrinsic::getDeclaration(TheModule, Intrinsic::fabs, src.tys()), val); | |
| 933 | +// else return src.b->CreateSelect(src.b->CreateICmpSLT(val, src.autoConstant(0)), | |
| 934 | +// src.b->CreateSub(src.autoConstant(0), val), | |
| 935 | +// val); | |
| 936 | +// } | |
| 937 | +//}; | |
| 938 | + | |
| 939 | +//BR_REGISTER(Transform, absTransform) | |
| 905 | 940 | |
| 906 | 941 | /*! |
| 907 | 942 | * \ingroup transforms |
| ... | ... | @@ -928,63 +963,63 @@ BR_REGISTER(Transform, addTransform) |
| 928 | 963 | * \brief LLVM clamp transform |
| 929 | 964 | * \author Josh Klontz \cite jklontz |
| 930 | 965 | */ |
| 931 | -class clampTransform : public StitchableTransform | |
| 932 | -{ | |
| 933 | - Q_OBJECT | |
| 934 | - Q_PROPERTY(double min READ get_min WRITE set_min RESET reset_min STORED false) | |
| 935 | - Q_PROPERTY(double max READ get_max WRITE set_max RESET reset_max STORED false) | |
| 936 | - BR_PROPERTY(double, min, -std::numeric_limits<double>::max()) | |
| 937 | - BR_PROPERTY(double, max, std::numeric_limits<double>::max()) | |
| 938 | - | |
| 939 | - Value *stitch(const MatrixBuilder &src, const MatrixBuilder &dst, Value *val) const | |
| 940 | - { | |
| 941 | - (void) src; | |
| 942 | - Value *clampedVal = val; | |
| 943 | - if (min > -std::numeric_limits<double>::max()) { | |
| 944 | - Value *low = dst.autoConstant(min); | |
| 945 | - clampedVal = dst.b->CreateSelect(dst.compareLT(clampedVal, low), low, clampedVal); | |
| 946 | - } | |
| 947 | - if (max < std::numeric_limits<double>::max()) { | |
| 948 | - Value *high = dst.autoConstant(max); | |
| 949 | - clampedVal = dst.b->CreateSelect(dst.compareGT(clampedVal, high), high, clampedVal); | |
| 950 | - } | |
| 951 | - return clampedVal; | |
| 952 | - } | |
| 953 | -}; | |
| 954 | - | |
| 955 | -BR_REGISTER(Transform, clampTransform) | |
| 966 | +//class clampTransform : public StitchableTransform | |
| 967 | +//{ | |
| 968 | +// Q_OBJECT | |
| 969 | +// Q_PROPERTY(double min READ get_min WRITE set_min RESET reset_min STORED false) | |
| 970 | +// Q_PROPERTY(double max READ get_max WRITE set_max RESET reset_max STORED false) | |
| 971 | +// BR_PROPERTY(double, min, -std::numeric_limits<double>::max()) | |
| 972 | +// BR_PROPERTY(double, max, std::numeric_limits<double>::max()) | |
| 973 | + | |
| 974 | +// Value *stitch(const MatrixBuilder &src, const MatrixBuilder &dst, Value *val) const | |
| 975 | +// { | |
| 976 | +// (void) src; | |
| 977 | +// Value *clampedVal = val; | |
| 978 | +// if (min > -std::numeric_limits<double>::max()) { | |
| 979 | +// Value *low = dst.autoConstant(min); | |
| 980 | +// clampedVal = dst.b->CreateSelect(dst.compareLT(clampedVal, low), low, clampedVal); | |
| 981 | +// } | |
| 982 | +// if (max < std::numeric_limits<double>::max()) { | |
| 983 | +// Value *high = dst.autoConstant(max); | |
| 984 | +// clampedVal = dst.b->CreateSelect(dst.compareGT(clampedVal, high), high, clampedVal); | |
| 985 | +// } | |
| 986 | +// return clampedVal; | |
| 987 | +// } | |
| 988 | +//}; | |
| 989 | + | |
| 990 | +//BR_REGISTER(Transform, clampTransform) | |
| 956 | 991 | |
| 957 | 992 | /*! |
| 958 | 993 | * \ingroup transforms |
| 959 | 994 | * \brief LLVM quantize transform |
| 960 | 995 | * \author Josh Klontz \cite jklontz |
| 961 | 996 | */ |
| 962 | -class _QuantizeTransform : public Transform | |
| 963 | -{ | |
| 964 | - Q_OBJECT | |
| 965 | - Q_PROPERTY(float a READ get_a WRITE set_a RESET reset_a) | |
| 966 | - Q_PROPERTY(float b READ get_b WRITE set_b RESET reset_b) | |
| 967 | - BR_PROPERTY(float, a, 1) | |
| 968 | - BR_PROPERTY(float, b, 0) | |
| 969 | - | |
| 970 | - QScopedPointer<Transform> transform; | |
| 971 | - | |
| 972 | - void init() | |
| 973 | - { | |
| 974 | - transform.reset(Transform::make(QString("stitch([scale(%1),add(%2),clamp(0,255),cast(u8)])").arg(QString::number(a), QString::number(b)))); | |
| 975 | - } | |
| 976 | - | |
| 977 | - void train(const TemplateList &data) | |
| 978 | - { | |
| 979 | - (void) data; | |
| 980 | - qFatal("_Quantize::train not implemented."); | |
| 981 | - } | |
| 982 | - | |
| 983 | - void project(const Template &src, Template &dst) const | |
| 984 | - { | |
| 985 | - transform->project(src, dst); | |
| 986 | - } | |
| 987 | -}; | |
| 997 | +//class _QuantizeTransform : public Transform | |
| 998 | +//{ | |
| 999 | +// Q_OBJECT | |
| 1000 | +// Q_PROPERTY(float a READ get_a WRITE set_a RESET reset_a) | |
| 1001 | +// Q_PROPERTY(float b READ get_b WRITE set_b RESET reset_b) | |
| 1002 | +// BR_PROPERTY(float, a, 1) | |
| 1003 | +// BR_PROPERTY(float, b, 0) | |
| 1004 | + | |
| 1005 | +// QScopedPointer<Transform> transform; | |
| 1006 | + | |
| 1007 | +// void init() | |
| 1008 | +// { | |
| 1009 | +// transform.reset(Transform::make(QString("stitch([scale(%1),add(%2),clamp(0,255),cast(u8)])").arg(QString::number(a), QString::number(b)))); | |
| 1010 | +// } | |
| 1011 | + | |
| 1012 | +// void train(const TemplateList &data) | |
| 1013 | +// { | |
| 1014 | +// (void) data; | |
| 1015 | +// qFatal("_Quantize::train not implemented."); | |
| 1016 | +// } | |
| 1017 | + | |
| 1018 | +// void project(const Template &src, Template &dst) const | |
| 1019 | +// { | |
| 1020 | +// transform->project(src, dst); | |
| 1021 | +// } | |
| 1022 | +//}; | |
| 988 | 1023 | |
| 989 | 1024 | // BR_REGISTER(Transform, _QuantizeTransform) |
| 990 | 1025 | |
| ... | ... | @@ -1029,34 +1064,6 @@ class LLVMInitializer : public Initializer |
| 1029 | 1064 | Type::getInt16Ty(getGlobalContext()), // hash |
| 1030 | 1065 | NULL); |
| 1031 | 1066 | |
| 1032 | - std::vector<Type*> unaryKernelParams; | |
| 1033 | - unaryKernelParams.push_back(PointerType::getUnqual(TheMatrixStruct)); | |
| 1034 | - unaryKernelParams.push_back(PointerType::getUnqual(TheMatrixStruct)); | |
| 1035 | - unaryKernelParams.push_back(Type::getInt32Ty(getGlobalContext())); | |
| 1036 | - Type *unaryKernelReturn = Type::getVoidTy(getGlobalContext()); | |
| 1037 | - Type *unaryKernelType = PointerType::getUnqual(FunctionType::get(unaryKernelReturn, unaryKernelParams, false)); | |
| 1038 | - std::vector<Type*> makeUnaryKernelParams; | |
| 1039 | - makeUnaryKernelParams.push_back(Type::getInt8PtrTy(getGlobalContext())); | |
| 1040 | - makeUnaryKernelParams.push_back(PointerType::getUnqual(TheMatrixStruct)); | |
| 1041 | - FunctionType* makeUnaryKernelType = FunctionType::get(unaryKernelType, makeUnaryKernelParams, false); | |
| 1042 | - makeUnaryKernelFunction = Function::Create(makeUnaryKernelType, GlobalValue::ExternalLinkage, "makeUnaryKernel", TheModule); | |
| 1043 | - makeUnaryKernelFunction->setCallingConv(CallingConv::C); | |
| 1044 | - | |
| 1045 | - std::vector<Type*> binaryKernelParams; | |
| 1046 | - binaryKernelParams.push_back(PointerType::getUnqual(TheMatrixStruct)); | |
| 1047 | - binaryKernelParams.push_back(PointerType::getUnqual(TheMatrixStruct)); | |
| 1048 | - binaryKernelParams.push_back(PointerType::getUnqual(TheMatrixStruct)); | |
| 1049 | - binaryKernelParams.push_back(Type::getInt32Ty(getGlobalContext())); | |
| 1050 | - Type *binaryKernelReturn = Type::getVoidTy(getGlobalContext()); | |
| 1051 | - Type *binaryKernelType = PointerType::getUnqual(FunctionType::get(binaryKernelReturn, binaryKernelParams, false)); | |
| 1052 | - std::vector<Type*> makeBinaryKernelParams; | |
| 1053 | - makeBinaryKernelParams.push_back(Type::getInt8PtrTy(getGlobalContext())); | |
| 1054 | - makeBinaryKernelParams.push_back(PointerType::getUnqual(TheMatrixStruct)); | |
| 1055 | - makeBinaryKernelParams.push_back(PointerType::getUnqual(TheMatrixStruct)); | |
| 1056 | - FunctionType* makeBinaryKernelType = FunctionType::get(binaryKernelType, makeBinaryKernelParams, false); | |
| 1057 | - makeBinaryKernelFunction = Function::Create(makeBinaryKernelType, GlobalValue::ExternalLinkage, "makeBinaryKernel", TheModule); | |
| 1058 | - makeBinaryKernelFunction->setCallingConv(CallingConv::C); | |
| 1059 | - | |
| 1060 | 1067 | QSharedPointer<Transform> kernel(Transform::make("add(1)", NULL)); |
| 1061 | 1068 | |
| 1062 | 1069 | Template src, dst; |
| ... | ... | @@ -1124,7 +1131,7 @@ UnaryFunction makeUnaryFunction(const char *description) |
| 1124 | 1131 | { |
| 1125 | 1132 | QScopedPointer<UnaryTransform> unaryTransform(dynamic_cast<UnaryTransform*>(Transform::make(description, NULL))); |
| 1126 | 1133 | if (unaryTransform == NULL) qFatal("makeUnaryFunction NULL transform!"); |
| 1127 | - return unaryTransform->getFunction(NULL); | |
| 1134 | + return unaryTransform->getFunction(); | |
| 1128 | 1135 | } |
| 1129 | 1136 | |
| 1130 | 1137 | BinaryFunction makeBinaryFunction(const char *description) |
| ... | ... | @@ -1133,6 +1140,23 @@ BinaryFunction makeBinaryFunction(const char *description) |
| 1133 | 1140 | return NULL; |
| 1134 | 1141 | } |
| 1135 | 1142 | |
| 1143 | +UnaryAllocation makeUnaryAllocation(const char *description, const Matrix *src) | |
| 1144 | +{ | |
| 1145 | + if (description == NULL) qFatal("makeUnaryAllocation NULL description!"); | |
| 1146 | + const File f = long(description) < 1000 ? UnaryTransform::fileTable[long(description)] : File(description); | |
| 1147 | + QScopedPointer<UnaryTransform> unaryTransform(dynamic_cast<UnaryTransform*>(Transform::make(f, NULL))); | |
| 1148 | + if (unaryTransform == NULL) qFatal("makeUnaryKernel NULL transform!"); | |
| 1149 | + return unaryTransform->getAllocation(src); | |
| 1150 | +} | |
| 1151 | + | |
| 1152 | +BinaryAllocation makeBinaryAllocation(const char *description, const Matrix *srcA, const Matrix *srcB) | |
| 1153 | +{ | |
| 1154 | + (void) description; | |
| 1155 | + (void) srcA; | |
| 1156 | + (void) srcB; | |
| 1157 | + return NULL; | |
| 1158 | +} | |
| 1159 | + | |
| 1136 | 1160 | UnaryKernel makeUnaryKernel(const char *description, const Matrix *src) |
| 1137 | 1161 | { |
| 1138 | 1162 | if (description == NULL) qFatal("makeUnaryKernel NULL description!"); | ... | ... |