returnValue VectorspaceElement::printToString( char** string, const char* const name, PrintScheme printScheme, BooleanType allocateMemory ) const { char* startString = 0; char* endString = 0; uint width = 0; uint precision = 0; char* colSeparator = 0; char* rowSeparator = 0; returnValue returnvalue; returnvalue = getGlobalStringDefinitions( printScheme,&startString,&endString, width,precision,&colSeparator,&rowSeparator ); if ( returnvalue == SUCCESSFUL_RETURN ) { returnvalue = printToString( string,name,startString,endString,width,precision,colSeparator,rowSeparator,allocateMemory ); } if ( startString != 0 ) delete[] startString; if ( endString != 0 ) delete[] endString; if ( colSeparator != 0 ) delete[] colSeparator; if ( rowSeparator != 0 ) delete[] rowSeparator; return returnvalue; }
void puts(char *s) { char c; // Loops through each character in string 's' while (c = *s++) { if(toSer) sendByte(c); else printToString(c); } }
returnValue VectorspaceElement::print( const char* const name, PrintScheme printScheme ) const { char* string = 0; printToString( &string, name,printScheme ); acadoPrintf( "%s",string ); if ( string != 0 ) delete[] string; return SUCCESSFUL_RETURN; }
returnValue VectorspaceElement::print( const char* const name, const char* const startString, const char* const endString, uint width, uint precision, const char* const colSeparator, const char* const rowSeparator ) const { char* string = 0; printToString( &string, name,startString,endString,width,precision,colSeparator,rowSeparator ); acadoPrintf( "%s",string ); if ( string != 0 ) delete[] string; return SUCCESSFUL_RETURN; }
std::vector<std::string> generateLibraryPtx(int devMajor, int devMinor) { if (libdevicePtxCache.size() > 0 && intrinsicsPtxCache.size() > 0) { return {libdevicePtxCache, intrinsicsPtxCache}; } // Build libdevice (math libraries, etc.) module // // Reference: // http://docs.nvidia.com/cuda/libdevice-users-guide/basic-usage.html // // The device to libdevice version mapping is weird (note 3.1-3.4=compute_20) // 2.0 ≤ Arch < 3.0 libdevice.compute_20.XX.bc // Arch = 3.0 libdevice.compute_30.XX.bc // 3.1 ≤ Arch < 3.5 libdevice.compute_20.XX.bc // Arch = 3.5 libdevice.compute_35.XX.bc // Identify device by Compute API level const char *libdevice; int libdevice_length; if ((devMajor == 3 && devMinor >= 5) || devMajor > 3) { libdevice = reinterpret_cast<const char*>(simit_gpu_libdevice_compute_35); libdevice_length = simit_gpu_libdevice_compute_35_length; } else if (devMajor == 3 && devMinor >= 0) { libdevice = reinterpret_cast<const char*>(simit_gpu_libdevice_compute_30); libdevice_length = simit_gpu_libdevice_compute_30_length; } else { libdevice = reinterpret_cast<const char*>(simit_gpu_libdevice_compute_20); libdevice_length = simit_gpu_libdevice_compute_20_length; } llvm::SMDiagnostic errReport; libdevice_length = alignBitreaderLength(libdevice_length); llvm::MemoryBufferRef libdeviceBuf( llvm::StringRef(libdevice, libdevice_length), "libdevice"); std::unique_ptr<llvm::Module> libdeviceModule = llvm::parseIR(libdeviceBuf, errReport, LLVM_CTX); iassert((bool)libdeviceModule) << "Failed to load libdevice: " << printToString(errReport); setNVVMModuleProps(libdeviceModule.get()); logModule(libdeviceModule.get(), "simit-libdevice.ll"); std::string libdevicePtx = generatePtx(libdeviceModule.get(), devMajor, devMinor); // Build intrinsics module const char *intrinsics = reinterpret_cast<const char*>(simit_gpu_intrinsics); int intrinsics_length = alignBitreaderLength(simit_gpu_intrinsics_length); llvm::MemoryBufferRef intrinsicsBuf( llvm::StringRef(intrinsics, intrinsics_length), "intrinsics"); std::unique_ptr<llvm::Module> intrinsicsModule = llvm::parseIR(intrinsicsBuf, errReport, LLVM_CTX); iassert((bool)intrinsicsModule) << "Failed to load intrinsics: " << printToString(errReport); setNVVMModuleProps(intrinsicsModule.get()); logModule(intrinsicsModule.get(), "simit-intrinsics.ll"); std::string intrinsicsPtx = generatePtx(intrinsicsModule.get(), devMajor, devMinor); // Cache the compiled libries libdevicePtxCache = libdevicePtx; intrinsicsPtxCache = intrinsicsPtx; return {libdevicePtx, intrinsicsPtx}; }
/** * puts() is used by printf() to display or send a character. This function * determines where printf prints to. For this case it sends a character * out over UART. **/ void putc(unsigned b) { if(toSer) sendByte(b); else printToString(b); }