std::string GetHeaderDomainStr(HTTPHeaderDomain domain){ static std::unordered_map<HTTPHeaderDomain,std::string> domainStrTable={ {HeaderDomainType::HOST,"HOST"}, {HeaderDomainType::ACCEPT,"ACCEPT"}, {HeaderDomainType::ACCEPT_CHARSET,"ACCEPT-CHARSET"}, {HeaderDomainType::ACCEPT_ENCODING,"ACCEPT-ENCODING"}, {HeaderDomainType::ACCEPT_LANGUAGE,"ACCEPT-LANGUAGE"}, {HeaderDomainType::ACCEPT_DATETIME,"ACCEPT-DATETIME"}, {HeaderDomainType::CONNECTION,"CONNECTION"}, {HeaderDomainType::COOKIE,"COOKIE"}, {HeaderDomainType::CONTENT_LENGTH,"CONTENT-LENGTH"}, {HeaderDomainType::CONTENT_TYPE,"CONTENT-TYPE"}, {HeaderDomainType::REFERER,"REFERER"}, {HeaderDomainType::USER_AGENT,"USER-AGENT"} }; return _GetTypeStr(domainStrTable,domain); }
//----------------------------------------------------------------------------// std::string CUDAImpl::BoilerplateCode(Kernel::Ptr kernel) const { std::stringstream ss; // Indent string ss << ",\n" << std::string(kernel->name.size() + 1, ' '); const std::string indent = ss.str(); ss.str(""); ss << "__global__ void\n" << kernel->name << "("; bool first = true; for(size_t i = 0; i < kernel->inBuffers.size(); ++i) { ss << (first ? "" : indent); first = false; const std::string & name = kernel->inBuffers[i].buffer->name; ss << "const " << _GetTypeStr(_buffers.find(name)->second) << " * " << kernel->inBuffers[i].name << (_buffers.find(name)->second->type == Buffer::HALF ? "_half" : ""); } for(size_t i = 0; i < kernel->outBuffers.size(); ++i) { ss << (first ? "" : indent); first = false; const std::string & name = kernel->outBuffers[i].buffer->name; ss << _GetTypeStr(_buffers.find(name)->second) << " * " << kernel->outBuffers[i].name << (_buffers.find(name)->second->type == Buffer::HALF ? "_half" : ""); } for(size_t i = 0; i < kernel->paramsInt.size(); ++i) { ss << (first ? "" : indent); first = false; ss << "const int " << kernel->paramsInt[i].name; } for(size_t i = 0; i < kernel->paramsFloat.size(); ++i) { ss << (first ? "" : indent); first = false; ss << "const float " << kernel->paramsFloat[i].name; } ss << indent << "const int width" << indent << "const int height)\n"; ss << "{\n"; ss << " const int x = blockIdx.x * blockDim.x + threadIdx.x;\n"; ss << " const int y = blockIdx.y * blockDim.y + threadIdx.y;\n\n"; ss << " // array index\n"; ss << " const int idx = x + width * y;\n\n"; ss << " // inside image bounds check\n"; ss << " if (x >= width || y >= height) {\n"; ss << " return;\n"; ss << " }\n\n"; // Do half to float conversions (if needed) for(size_t i = 0; i < kernel->inBuffers.size(); ++i) { const std::string & bname = kernel->inBuffers[i].buffer->name; Buffer::Ptr buf = _buffers.find(bname)->second; if (buf->type == Buffer::HALF) { if (!i) { ss << " // half to float conversion\n"; } if (buf->channels == 1) { ss << " const float " << kernel->inBuffers[i].name << " = " << "__half2float(" << kernel->inBuffers[i].name << "_half[idx]);\n"; continue; } std::stringstream subss; subss << " const float" << buf->channels << " " << kernel->inBuffers[i].name << " = make_float" << buf->channels << "("; const std::string preindent = subss.str(); subss.str(""); subss << ",\n" << std::string(preindent.size(), ' '); const std::string subindent = subss.str(); ss << preindent; bool subfirst = true; for (unsigned int j = 0; j < buf->channels; ++j) { ss << (subfirst ? "" : subindent); subfirst = false; ss << "__half2float(" << kernel->inBuffers[i].name << "_half[" << buf->channels << " * idx + " << j << "])"; } ss <<");\n"; if (i == kernel->inBuffers.size() - 1) { ss << "\n"; } } } ss << " // kernel code\n"; for (size_t i = 0; i < kernel->outBuffers.size(); ++i) { Buffer::Ptr b = _buffers.find( kernel->outBuffers[i].buffer->name)->second; ss << " "; if (b->type == Buffer::HALF) { ss << "float" << b->channels << " "; } ss << kernel->outBuffers[i].name; if (b->type != Buffer::HALF) { ss << "[idx]"; } ss << " = "; if (b->channels == 1) { ss << "0;\n"; } else { ss << "make_"; if (b->type != Buffer::HALF) { ss << _GetTypeStr(b); } else { ss << "float" << b->channels; } ss << "("; for (size_t j = 0; j < b->channels; ++j) { ss << (j ==0 ? "" : ", ") << "0"; } ss << ");\n"; } } // Do half to float conversions (if needed) for(size_t i = 0; i < kernel->outBuffers.size(); ++i) { const std::string & bname = kernel->outBuffers[i].buffer->name; Buffer::Ptr buf = _buffers.find(bname)->second; if (buf->type == Buffer::HALF) { if (!i) { ss << "\n // float to half conversion\n"; } for (unsigned int j = 0; j < buf->channels; ++j) { ss << " " << kernel->outBuffers[i].name << "_half["; if (buf->channels > 1) { ss << buf->channels << " * "; } ss << "idx + " << j << "] = __float2half_rn(" << kernel->outBuffers[i].name; switch(j) { case 0: ss << (buf->channels > 1 ? ".x" : ""); break; case 1: ss << ".y"; break; case 2: ss << ".z"; break; case 3: ss << ".w"; break; } ss << ");\n"; } } } ss << "}"; return ss.str(); }
std::string GetHTTPMethodStr(HTTPMethod method){ static std::unordered_map<HTTPMethod,std::string> methodStrTable={{HTTPMethodType::POST,"POST"},{HTTPMethodType::GET,"GET"},{HTTPMethodType::DELETE,"DELETE"},{HTTPMethodType::UPDATE,"UPDATE"}}; return _GetTypeStr(methodStrTable,method); }
std::string GetProtocolStr(Protocol protocol){ static std::unordered_map<Protocol,std::string> protocolStrTable={{ProtocolType::HTTP1_0,"HTTP1_0"},{ProtocolType::HTTP1_1,"HTTP1_1"}}; return _GetTypeStr(protocolStrTable,protocol); }
std::string GetURLSchemeStr(URLScheme scheme){ static std::unordered_map<URLScheme,std::string> schemeStrTable={{URLSchemeType::HTTP,"HTTP"},{URLSchemeType::HTTPS,"HTTPS"},{URLSchemeType::FTP,"FTP"},{URLSchemeType::MAILTO,"MAILTO"}}; return _GetTypeStr(schemeStrTable,scheme); }