id
int32
0
167k
repo
stringlengths
5
54
path
stringlengths
4
155
func_name
stringlengths
1
118
original_string
stringlengths
52
85.5k
language
stringclasses
1 value
code
stringlengths
52
85.5k
code_tokens
sequence
docstring
stringlengths
6
2.61k
docstring_tokens
sequence
sha
stringlengths
40
40
url
stringlengths
85
252
5,400
dinever/golf
app.go
Run
func (app *Application) Run(addr string) { err := http.ListenAndServe(addr, app) if err != nil { panic(err) } }
go
func (app *Application) Run(addr string) { err := http.ListenAndServe(addr, app) if err != nil { panic(err) } }
[ "func", "(", "app", "*", "Application", ")", "Run", "(", "addr", "string", ")", "{", "err", ":=", "http", ".", "ListenAndServe", "(", "addr", ",", "app", ")", "\n", "if", "err", "!=", "nil", "{", "panic", "(", "err", ")", "\n", "}", "\n", "}" ]
// Run the Golf Application.
[ "Run", "the", "Golf", "Application", "." ]
11abebbbb289ef6f35e518db394eaca39cee8732
https://github.com/dinever/golf/blob/11abebbbb289ef6f35e518db394eaca39cee8732/app.go#L113-L118
5,401
dinever/golf
app.go
RunTLS
func (app *Application) RunTLS(addr, certFile, keyFile string) { err := http.ListenAndServeTLS(addr, certFile, keyFile, app) if err != nil { panic(err) } }
go
func (app *Application) RunTLS(addr, certFile, keyFile string) { err := http.ListenAndServeTLS(addr, certFile, keyFile, app) if err != nil { panic(err) } }
[ "func", "(", "app", "*", "Application", ")", "RunTLS", "(", "addr", ",", "certFile", ",", "keyFile", "string", ")", "{", "err", ":=", "http", ".", "ListenAndServeTLS", "(", "addr", ",", "certFile", ",", "keyFile", ",", "app", ")", "\n", "if", "err", "!=", "nil", "{", "panic", "(", "err", ")", "\n", "}", "\n", "}" ]
// RunTLS runs the app with TLS support.
[ "RunTLS", "runs", "the", "app", "with", "TLS", "support", "." ]
11abebbbb289ef6f35e518db394eaca39cee8732
https://github.com/dinever/golf/blob/11abebbbb289ef6f35e518db394eaca39cee8732/app.go#L121-L126
5,402
dinever/golf
app.go
Static
func (app *Application) Static(url string, path string) { url = strings.TrimRight(url, "/") app.staticRouter[url] = append(app.staticRouter[url], path) }
go
func (app *Application) Static(url string, path string) { url = strings.TrimRight(url, "/") app.staticRouter[url] = append(app.staticRouter[url], path) }
[ "func", "(", "app", "*", "Application", ")", "Static", "(", "url", "string", ",", "path", "string", ")", "{", "url", "=", "strings", ".", "TrimRight", "(", "url", ",", "\"", "\"", ")", "\n", "app", ".", "staticRouter", "[", "url", "]", "=", "append", "(", "app", ".", "staticRouter", "[", "url", "]", ",", "path", ")", "\n", "}" ]
// Static is used for registering a static folder
[ "Static", "is", "used", "for", "registering", "a", "static", "folder" ]
11abebbbb289ef6f35e518db394eaca39cee8732
https://github.com/dinever/golf/blob/11abebbbb289ef6f35e518db394eaca39cee8732/app.go#L129-L132
5,403
dinever/golf
app.go
Get
func (app *Application) Get(pattern string, handler HandlerFunc) { app.router.AddRoute("GET", pattern, handler) }
go
func (app *Application) Get(pattern string, handler HandlerFunc) { app.router.AddRoute("GET", pattern, handler) }
[ "func", "(", "app", "*", "Application", ")", "Get", "(", "pattern", "string", ",", "handler", "HandlerFunc", ")", "{", "app", ".", "router", ".", "AddRoute", "(", "\"", "\"", ",", "pattern", ",", "handler", ")", "\n", "}" ]
// Get method is used for registering a Get method route
[ "Get", "method", "is", "used", "for", "registering", "a", "Get", "method", "route" ]
11abebbbb289ef6f35e518db394eaca39cee8732
https://github.com/dinever/golf/blob/11abebbbb289ef6f35e518db394eaca39cee8732/app.go#L135-L137
5,404
dinever/golf
app.go
Error
func (app *Application) Error(statusCode int, handler ErrorHandlerFunc) { app.errorHandler[statusCode] = handler }
go
func (app *Application) Error(statusCode int, handler ErrorHandlerFunc) { app.errorHandler[statusCode] = handler }
[ "func", "(", "app", "*", "Application", ")", "Error", "(", "statusCode", "int", ",", "handler", "ErrorHandlerFunc", ")", "{", "app", ".", "errorHandler", "[", "statusCode", "]", "=", "handler", "\n", "}" ]
// Error method is used for registering an handler for a specified HTTP error code.
[ "Error", "method", "is", "used", "for", "registering", "an", "handler", "for", "a", "specified", "HTTP", "error", "code", "." ]
11abebbbb289ef6f35e518db394eaca39cee8732
https://github.com/dinever/golf/blob/11abebbbb289ef6f35e518db394eaca39cee8732/app.go#L170-L172
5,405
dinever/golf
app.go
handleError
func (app *Application) handleError(ctx *Context, statusCode int, data ...map[string]interface{}) { ctx.SendStatus(statusCode) handler, ok := app.errorHandler[statusCode] if !ok { defaultErrorHandler(ctx, data...) return } handler(ctx) }
go
func (app *Application) handleError(ctx *Context, statusCode int, data ...map[string]interface{}) { ctx.SendStatus(statusCode) handler, ok := app.errorHandler[statusCode] if !ok { defaultErrorHandler(ctx, data...) return } handler(ctx) }
[ "func", "(", "app", "*", "Application", ")", "handleError", "(", "ctx", "*", "Context", ",", "statusCode", "int", ",", "data", "...", "map", "[", "string", "]", "interface", "{", "}", ")", "{", "ctx", ".", "SendStatus", "(", "statusCode", ")", "\n", "handler", ",", "ok", ":=", "app", ".", "errorHandler", "[", "statusCode", "]", "\n", "if", "!", "ok", "{", "defaultErrorHandler", "(", "ctx", ",", "data", "...", ")", "\n", "return", "\n", "}", "\n", "handler", "(", "ctx", ")", "\n", "}" ]
// Handles a HTTP Error, if there is a corresponding handler set in the map // `errorHandler`, then call it. Otherwise call the `defaultErrorHandler`.
[ "Handles", "a", "HTTP", "Error", "if", "there", "is", "a", "corresponding", "handler", "set", "in", "the", "map", "errorHandler", "then", "call", "it", ".", "Otherwise", "call", "the", "defaultErrorHandler", "." ]
11abebbbb289ef6f35e518db394eaca39cee8732
https://github.com/dinever/golf/blob/11abebbbb289ef6f35e518db394eaca39cee8732/app.go#L176-L184
5,406
dinever/golf
middleware.go
NewChain
func NewChain(handlerArray ...MiddlewareHandlerFunc) *Chain { c := new(Chain) c.middlewareHandlers = handlerArray return c }
go
func NewChain(handlerArray ...MiddlewareHandlerFunc) *Chain { c := new(Chain) c.middlewareHandlers = handlerArray return c }
[ "func", "NewChain", "(", "handlerArray", "...", "MiddlewareHandlerFunc", ")", "*", "Chain", "{", "c", ":=", "new", "(", "Chain", ")", "\n", "c", ".", "middlewareHandlers", "=", "handlerArray", "\n", "return", "c", "\n", "}" ]
// NewChain Creates a new middleware chain.
[ "NewChain", "Creates", "a", "new", "middleware", "chain", "." ]
11abebbbb289ef6f35e518db394eaca39cee8732
https://github.com/dinever/golf/blob/11abebbbb289ef6f35e518db394eaca39cee8732/middleware.go#L20-L24
5,407
dinever/golf
middleware.go
Final
func (c Chain) Final(fn HandlerFunc) HandlerFunc { for i := len(c.middlewareHandlers) - 1; i >= 0; i-- { fn = c.middlewareHandlers[i](fn) } return fn }
go
func (c Chain) Final(fn HandlerFunc) HandlerFunc { for i := len(c.middlewareHandlers) - 1; i >= 0; i-- { fn = c.middlewareHandlers[i](fn) } return fn }
[ "func", "(", "c", "Chain", ")", "Final", "(", "fn", "HandlerFunc", ")", "HandlerFunc", "{", "for", "i", ":=", "len", "(", "c", ".", "middlewareHandlers", ")", "-", "1", ";", "i", ">=", "0", ";", "i", "--", "{", "fn", "=", "c", ".", "middlewareHandlers", "[", "i", "]", "(", "fn", ")", "\n", "}", "\n", "return", "fn", "\n", "}" ]
// Final indicates a final Handler, chain the multiple middlewares together with the // handler, and return them together as a handler.
[ "Final", "indicates", "a", "final", "Handler", "chain", "the", "multiple", "middlewares", "together", "with", "the", "handler", "and", "return", "them", "together", "as", "a", "handler", "." ]
11abebbbb289ef6f35e518db394eaca39cee8732
https://github.com/dinever/golf/blob/11abebbbb289ef6f35e518db394eaca39cee8732/middleware.go#L28-L33
5,408
dinever/golf
middleware.go
Append
func (c *Chain) Append(fn MiddlewareHandlerFunc) { c.middlewareHandlers = append(c.middlewareHandlers, fn) }
go
func (c *Chain) Append(fn MiddlewareHandlerFunc) { c.middlewareHandlers = append(c.middlewareHandlers, fn) }
[ "func", "(", "c", "*", "Chain", ")", "Append", "(", "fn", "MiddlewareHandlerFunc", ")", "{", "c", ".", "middlewareHandlers", "=", "append", "(", "c", ".", "middlewareHandlers", ",", "fn", ")", "\n", "}" ]
// Append a middleware to the middleware chain
[ "Append", "a", "middleware", "to", "the", "middleware", "chain" ]
11abebbbb289ef6f35e518db394eaca39cee8732
https://github.com/dinever/golf/blob/11abebbbb289ef6f35e518db394eaca39cee8732/middleware.go#L36-L38
5,409
dinever/golf
middleware.go
XSRFProtectionMiddleware
func XSRFProtectionMiddleware(next HandlerFunc) HandlerFunc { fn := func(ctx *Context) { if ctx.Request.Method == "POST" || ctx.Request.Method == "PUT" || ctx.Request.Method == "DELETE" { if !ctx.checkXSRFToken() { ctx.Abort(403) return } } next(ctx) } return fn }
go
func XSRFProtectionMiddleware(next HandlerFunc) HandlerFunc { fn := func(ctx *Context) { if ctx.Request.Method == "POST" || ctx.Request.Method == "PUT" || ctx.Request.Method == "DELETE" { if !ctx.checkXSRFToken() { ctx.Abort(403) return } } next(ctx) } return fn }
[ "func", "XSRFProtectionMiddleware", "(", "next", "HandlerFunc", ")", "HandlerFunc", "{", "fn", ":=", "func", "(", "ctx", "*", "Context", ")", "{", "if", "ctx", ".", "Request", ".", "Method", "==", "\"", "\"", "||", "ctx", ".", "Request", ".", "Method", "==", "\"", "\"", "||", "ctx", ".", "Request", ".", "Method", "==", "\"", "\"", "{", "if", "!", "ctx", ".", "checkXSRFToken", "(", ")", "{", "ctx", ".", "Abort", "(", "403", ")", "\n", "return", "\n", "}", "\n", "}", "\n", "next", "(", "ctx", ")", "\n", "}", "\n", "return", "fn", "\n", "}" ]
// XSRFProtectionMiddleware is the built-in middleware for XSRF protection.
[ "XSRFProtectionMiddleware", "is", "the", "built", "-", "in", "middleware", "for", "XSRF", "protection", "." ]
11abebbbb289ef6f35e518db394eaca39cee8732
https://github.com/dinever/golf/blob/11abebbbb289ef6f35e518db394eaca39cee8732/middleware.go#L118-L129
5,410
dinever/golf
middleware.go
RecoverMiddleware
func RecoverMiddleware(next HandlerFunc) HandlerFunc { fn := func(ctx *Context) { defer func() { if err := recover(); err != nil { e := NewError(err) httpRequest, _ := httputil.DumpRequest(ctx.Request, true) log.Printf("[Recovery] panic recovered:\n%s\n%s\n%s", string(httpRequest), err, e.StackTraceString()) ctx.statusCode = 500 ctx.Abort(500, map[string]interface{}{ "Code": ctx.statusCode, "Title": "Internal Server Error", "HTTPRequest": string(httpRequest), "Message": e.Error(), "StackTrace": e.Stack, }) } }() next(ctx) } return fn }
go
func RecoverMiddleware(next HandlerFunc) HandlerFunc { fn := func(ctx *Context) { defer func() { if err := recover(); err != nil { e := NewError(err) httpRequest, _ := httputil.DumpRequest(ctx.Request, true) log.Printf("[Recovery] panic recovered:\n%s\n%s\n%s", string(httpRequest), err, e.StackTraceString()) ctx.statusCode = 500 ctx.Abort(500, map[string]interface{}{ "Code": ctx.statusCode, "Title": "Internal Server Error", "HTTPRequest": string(httpRequest), "Message": e.Error(), "StackTrace": e.Stack, }) } }() next(ctx) } return fn }
[ "func", "RecoverMiddleware", "(", "next", "HandlerFunc", ")", "HandlerFunc", "{", "fn", ":=", "func", "(", "ctx", "*", "Context", ")", "{", "defer", "func", "(", ")", "{", "if", "err", ":=", "recover", "(", ")", ";", "err", "!=", "nil", "{", "e", ":=", "NewError", "(", "err", ")", "\n", "httpRequest", ",", "_", ":=", "httputil", ".", "DumpRequest", "(", "ctx", ".", "Request", ",", "true", ")", "\n", "log", ".", "Printf", "(", "\"", "\\n", "\\n", "\\n", "\"", ",", "string", "(", "httpRequest", ")", ",", "err", ",", "e", ".", "StackTraceString", "(", ")", ")", "\n", "ctx", ".", "statusCode", "=", "500", "\n", "ctx", ".", "Abort", "(", "500", ",", "map", "[", "string", "]", "interface", "{", "}", "{", "\"", "\"", ":", "ctx", ".", "statusCode", ",", "\"", "\"", ":", "\"", "\"", ",", "\"", "\"", ":", "string", "(", "httpRequest", ")", ",", "\"", "\"", ":", "e", ".", "Error", "(", ")", ",", "\"", "\"", ":", "e", ".", "Stack", ",", "}", ")", "\n", "}", "\n", "}", "(", ")", "\n", "next", "(", "ctx", ")", "\n", "}", "\n", "return", "fn", "\n", "}" ]
// RecoverMiddleware is the built-in middleware for recovering from errors.
[ "RecoverMiddleware", "is", "the", "built", "-", "in", "middleware", "for", "recovering", "from", "errors", "." ]
11abebbbb289ef6f35e518db394eaca39cee8732
https://github.com/dinever/golf/blob/11abebbbb289ef6f35e518db394eaca39cee8732/middleware.go#L132-L152
5,411
dinever/golf
middleware.go
SessionMiddleware
func SessionMiddleware(next HandlerFunc) HandlerFunc { fn := func(ctx *Context) { if ctx.App.SessionManager != nil { ctx.retrieveSession() } next(ctx) } return fn }
go
func SessionMiddleware(next HandlerFunc) HandlerFunc { fn := func(ctx *Context) { if ctx.App.SessionManager != nil { ctx.retrieveSession() } next(ctx) } return fn }
[ "func", "SessionMiddleware", "(", "next", "HandlerFunc", ")", "HandlerFunc", "{", "fn", ":=", "func", "(", "ctx", "*", "Context", ")", "{", "if", "ctx", ".", "App", ".", "SessionManager", "!=", "nil", "{", "ctx", ".", "retrieveSession", "(", ")", "\n", "}", "\n", "next", "(", "ctx", ")", "\n", "}", "\n", "return", "fn", "\n", "}" ]
// SessionMiddleware handles session of the request
[ "SessionMiddleware", "handles", "session", "of", "the", "request" ]
11abebbbb289ef6f35e518db394eaca39cee8732
https://github.com/dinever/golf/blob/11abebbbb289ef6f35e518db394eaca39cee8732/middleware.go#L155-L163
5,412
dinever/golf
router.go
ByName
func (p *Parameter) ByName(name string) (string, error) { if i, has := p.names[name]; has { return p.findParam(i) } return "", fmt.Errorf("Parameter not found") }
go
func (p *Parameter) ByName(name string) (string, error) { if i, has := p.names[name]; has { return p.findParam(i) } return "", fmt.Errorf("Parameter not found") }
[ "func", "(", "p", "*", "Parameter", ")", "ByName", "(", "name", "string", ")", "(", "string", ",", "error", ")", "{", "if", "i", ",", "has", ":=", "p", ".", "names", "[", "name", "]", ";", "has", "{", "return", "p", ".", "findParam", "(", "i", ")", "\n", "}", "\n", "return", "\"", "\"", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}" ]
//ByName returns the url parameter by name
[ "ByName", "returns", "the", "url", "parameter", "by", "name" ]
11abebbbb289ef6f35e518db394eaca39cee8732
https://github.com/dinever/golf/blob/11abebbbb289ef6f35e518db394eaca39cee8732/router.go#L116-L121
5,413
dinever/golf
router.go
findParam
func (p *Parameter) findParam(idx int) (string, error) { index := len(p.names) - 1 urlPath := p.path pathLen := len(p.path) node := p.node for node != nil { if node.text[0] == ':' { ctn := lastIndexByte(urlPath, '/') if ctn == -1 { return "", fmt.Errorf("Parameter not found") } pathLen = ctn + 1 if index == idx { return urlPath[pathLen:], nil } index-- } else { pathLen -= len(node.text) } urlPath = urlPath[0:pathLen] node = node.parent } return "", fmt.Errorf("Parameter not found") }
go
func (p *Parameter) findParam(idx int) (string, error) { index := len(p.names) - 1 urlPath := p.path pathLen := len(p.path) node := p.node for node != nil { if node.text[0] == ':' { ctn := lastIndexByte(urlPath, '/') if ctn == -1 { return "", fmt.Errorf("Parameter not found") } pathLen = ctn + 1 if index == idx { return urlPath[pathLen:], nil } index-- } else { pathLen -= len(node.text) } urlPath = urlPath[0:pathLen] node = node.parent } return "", fmt.Errorf("Parameter not found") }
[ "func", "(", "p", "*", "Parameter", ")", "findParam", "(", "idx", "int", ")", "(", "string", ",", "error", ")", "{", "index", ":=", "len", "(", "p", ".", "names", ")", "-", "1", "\n", "urlPath", ":=", "p", ".", "path", "\n", "pathLen", ":=", "len", "(", "p", ".", "path", ")", "\n", "node", ":=", "p", ".", "node", "\n\n", "for", "node", "!=", "nil", "{", "if", "node", ".", "text", "[", "0", "]", "==", "':'", "{", "ctn", ":=", "lastIndexByte", "(", "urlPath", ",", "'/'", ")", "\n", "if", "ctn", "==", "-", "1", "{", "return", "\"", "\"", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n", "pathLen", "=", "ctn", "+", "1", "\n", "if", "index", "==", "idx", "{", "return", "urlPath", "[", "pathLen", ":", "]", ",", "nil", "\n", "}", "\n", "index", "--", "\n", "}", "else", "{", "pathLen", "-=", "len", "(", "node", ".", "text", ")", "\n", "}", "\n", "urlPath", "=", "urlPath", "[", "0", ":", "pathLen", "]", "\n", "node", "=", "node", ".", "parent", "\n", "}", "\n", "return", "\"", "\"", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}" ]
//findParam walks up the matched node looking for parameters returns the last parameter
[ "findParam", "walks", "up", "the", "matched", "node", "looking", "for", "parameters", "returns", "the", "last", "parameter" ]
11abebbbb289ef6f35e518db394eaca39cee8732
https://github.com/dinever/golf/blob/11abebbbb289ef6f35e518db394eaca39cee8732/router.go#L133-L157
5,414
dinever/golf
error.go
defaultErrorHandler
func defaultErrorHandler(ctx *Context, data ...map[string]interface{}) { var renderData map[string]interface{} if len(data) == 0 { renderData = make(map[string]interface{}) renderData["Code"] = ctx.statusCode renderData["Title"] = http.StatusText(ctx.statusCode) renderData["Message"] = http.StatusText(ctx.statusCode) } else { renderData = data[0] } if _, ok := renderData["Code"]; !ok { renderData["Code"] = ctx.statusCode } if _, ok := renderData["Title"]; !ok { renderData["Title"] = http.StatusText(ctx.statusCode) } if _, ok := renderData["Message"]; !ok { renderData["Message"] = http.StatusText(ctx.statusCode) } httpRequest, _ := httputil.DumpRequest(ctx.Request, true) renderData["HTTPRequest"] = string(httpRequest) var buf bytes.Buffer tmpl.Parse(errorTemplate) tmpl.Execute(&buf, renderData) ctx.Send(&buf) }
go
func defaultErrorHandler(ctx *Context, data ...map[string]interface{}) { var renderData map[string]interface{} if len(data) == 0 { renderData = make(map[string]interface{}) renderData["Code"] = ctx.statusCode renderData["Title"] = http.StatusText(ctx.statusCode) renderData["Message"] = http.StatusText(ctx.statusCode) } else { renderData = data[0] } if _, ok := renderData["Code"]; !ok { renderData["Code"] = ctx.statusCode } if _, ok := renderData["Title"]; !ok { renderData["Title"] = http.StatusText(ctx.statusCode) } if _, ok := renderData["Message"]; !ok { renderData["Message"] = http.StatusText(ctx.statusCode) } httpRequest, _ := httputil.DumpRequest(ctx.Request, true) renderData["HTTPRequest"] = string(httpRequest) var buf bytes.Buffer tmpl.Parse(errorTemplate) tmpl.Execute(&buf, renderData) ctx.Send(&buf) }
[ "func", "defaultErrorHandler", "(", "ctx", "*", "Context", ",", "data", "...", "map", "[", "string", "]", "interface", "{", "}", ")", "{", "var", "renderData", "map", "[", "string", "]", "interface", "{", "}", "\n", "if", "len", "(", "data", ")", "==", "0", "{", "renderData", "=", "make", "(", "map", "[", "string", "]", "interface", "{", "}", ")", "\n", "renderData", "[", "\"", "\"", "]", "=", "ctx", ".", "statusCode", "\n", "renderData", "[", "\"", "\"", "]", "=", "http", ".", "StatusText", "(", "ctx", ".", "statusCode", ")", "\n", "renderData", "[", "\"", "\"", "]", "=", "http", ".", "StatusText", "(", "ctx", ".", "statusCode", ")", "\n", "}", "else", "{", "renderData", "=", "data", "[", "0", "]", "\n", "}", "\n", "if", "_", ",", "ok", ":=", "renderData", "[", "\"", "\"", "]", ";", "!", "ok", "{", "renderData", "[", "\"", "\"", "]", "=", "ctx", ".", "statusCode", "\n", "}", "\n", "if", "_", ",", "ok", ":=", "renderData", "[", "\"", "\"", "]", ";", "!", "ok", "{", "renderData", "[", "\"", "\"", "]", "=", "http", ".", "StatusText", "(", "ctx", ".", "statusCode", ")", "\n", "}", "\n", "if", "_", ",", "ok", ":=", "renderData", "[", "\"", "\"", "]", ";", "!", "ok", "{", "renderData", "[", "\"", "\"", "]", "=", "http", ".", "StatusText", "(", "ctx", ".", "statusCode", ")", "\n", "}", "\n", "httpRequest", ",", "_", ":=", "httputil", ".", "DumpRequest", "(", "ctx", ".", "Request", ",", "true", ")", "\n", "renderData", "[", "\"", "\"", "]", "=", "string", "(", "httpRequest", ")", "\n", "var", "buf", "bytes", ".", "Buffer", "\n", "tmpl", ".", "Parse", "(", "errorTemplate", ")", "\n", "tmpl", ".", "Execute", "(", "&", "buf", ",", "renderData", ")", "\n", "ctx", ".", "Send", "(", "&", "buf", ")", "\n", "}" ]
// The default error handler
[ "The", "default", "error", "handler" ]
11abebbbb289ef6f35e518db394eaca39cee8732
https://github.com/dinever/golf/blob/11abebbbb289ef6f35e518db394eaca39cee8732/error.go#L104-L129
5,415
dinever/golf
error.go
StackTraceString
func (e Error) StackTraceString() string { buf := new(bytes.Buffer) for _, v := range e.Stack { fmt.Fprintf(buf, "%s: %s\n\t%s\n", v.File, v.Number, v.Method) } return string(buf.Bytes()) }
go
func (e Error) StackTraceString() string { buf := new(bytes.Buffer) for _, v := range e.Stack { fmt.Fprintf(buf, "%s: %s\n\t%s\n", v.File, v.Number, v.Method) } return string(buf.Bytes()) }
[ "func", "(", "e", "Error", ")", "StackTraceString", "(", ")", "string", "{", "buf", ":=", "new", "(", "bytes", ".", "Buffer", ")", "\n", "for", "_", ",", "v", ":=", "range", "e", ".", "Stack", "{", "fmt", ".", "Fprintf", "(", "buf", ",", "\"", "\\n", "\\t", "\\n", "\"", ",", "v", ".", "File", ",", "v", ".", "Number", ",", "v", ".", "Method", ")", "\n", "}", "\n", "return", "string", "(", "buf", ".", "Bytes", "(", ")", ")", "\n", "}" ]
// StackTraceString returns the stack trace in a string format.
[ "StackTraceString", "returns", "the", "stack", "trace", "in", "a", "string", "format", "." ]
11abebbbb289ef6f35e518db394eaca39cee8732
https://github.com/dinever/golf/blob/11abebbbb289ef6f35e518db394eaca39cee8732/error.go#L152-L158
5,416
dinever/golf
error.go
NewError
func NewError(msg interface{}) Error { var err error switch t := msg.(type) { case Error: return t case error: err = t default: err = fmt.Errorf("%v", t) } return Error{ err: err, Message: err.Error(), Class: reflect.TypeOf(err).String(), Stack: generateStack(3), } }
go
func NewError(msg interface{}) Error { var err error switch t := msg.(type) { case Error: return t case error: err = t default: err = fmt.Errorf("%v", t) } return Error{ err: err, Message: err.Error(), Class: reflect.TypeOf(err).String(), Stack: generateStack(3), } }
[ "func", "NewError", "(", "msg", "interface", "{", "}", ")", "Error", "{", "var", "err", "error", "\n\n", "switch", "t", ":=", "msg", ".", "(", "type", ")", "{", "case", "Error", ":", "return", "t", "\n", "case", "error", ":", "err", "=", "t", "\n", "default", ":", "err", "=", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "t", ")", "\n", "}", "\n\n", "return", "Error", "{", "err", ":", "err", ",", "Message", ":", "err", ".", "Error", "(", ")", ",", "Class", ":", "reflect", ".", "TypeOf", "(", "err", ")", ".", "String", "(", ")", ",", "Stack", ":", "generateStack", "(", "3", ")", ",", "}", "\n", "}" ]
// NewError creates a new error instance
[ "NewError", "creates", "a", "new", "error", "instance" ]
11abebbbb289ef6f35e518db394eaca39cee8732
https://github.com/dinever/golf/blob/11abebbbb289ef6f35e518db394eaca39cee8732/error.go#L166-L184
5,417
dinever/golf
session.go
NewMemorySessionManager
func NewMemorySessionManager() *MemorySessionManager { mgr := new(MemorySessionManager) mgr.sessions = make(map[string]*MemorySession) mgr.GarbageCollection() return mgr }
go
func NewMemorySessionManager() *MemorySessionManager { mgr := new(MemorySessionManager) mgr.sessions = make(map[string]*MemorySession) mgr.GarbageCollection() return mgr }
[ "func", "NewMemorySessionManager", "(", ")", "*", "MemorySessionManager", "{", "mgr", ":=", "new", "(", "MemorySessionManager", ")", "\n", "mgr", ".", "sessions", "=", "make", "(", "map", "[", "string", "]", "*", "MemorySession", ")", "\n", "mgr", ".", "GarbageCollection", "(", ")", "\n", "return", "mgr", "\n", "}" ]
// NewMemorySessionManager creates a new session manager.
[ "NewMemorySessionManager", "creates", "a", "new", "session", "manager", "." ]
11abebbbb289ef6f35e518db394eaca39cee8732
https://github.com/dinever/golf/blob/11abebbbb289ef6f35e518db394eaca39cee8732/session.go#L31-L36
5,418
dinever/golf
session.go
Session
func (mgr *MemorySessionManager) Session(sid string) (Session, error) { mgr.lock.RLock() if s, ok := mgr.sessions[sid]; ok { s.createdAt = time.Now() mgr.lock.RUnlock() return s, nil } mgr.lock.RUnlock() return nil, fmt.Errorf("Can not retrieve session with id %s", sid) }
go
func (mgr *MemorySessionManager) Session(sid string) (Session, error) { mgr.lock.RLock() if s, ok := mgr.sessions[sid]; ok { s.createdAt = time.Now() mgr.lock.RUnlock() return s, nil } mgr.lock.RUnlock() return nil, fmt.Errorf("Can not retrieve session with id %s", sid) }
[ "func", "(", "mgr", "*", "MemorySessionManager", ")", "Session", "(", "sid", "string", ")", "(", "Session", ",", "error", ")", "{", "mgr", ".", "lock", ".", "RLock", "(", ")", "\n", "if", "s", ",", "ok", ":=", "mgr", ".", "sessions", "[", "sid", "]", ";", "ok", "{", "s", ".", "createdAt", "=", "time", ".", "Now", "(", ")", "\n", "mgr", ".", "lock", ".", "RUnlock", "(", ")", "\n", "return", "s", ",", "nil", "\n", "}", "\n", "mgr", ".", "lock", ".", "RUnlock", "(", ")", "\n", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "sid", ")", "\n", "}" ]
// Session gets the session instance by indicating a session id.
[ "Session", "gets", "the", "session", "instance", "by", "indicating", "a", "session", "id", "." ]
11abebbbb289ef6f35e518db394eaca39cee8732
https://github.com/dinever/golf/blob/11abebbbb289ef6f35e518db394eaca39cee8732/session.go#L48-L57
5,419
dinever/golf
session.go
NewSession
func (mgr *MemorySessionManager) NewSession() (Session, error) { sid, err := mgr.sessionID() if err != nil { return nil, err } s := MemorySession{sid: sid, data: make(map[string]interface{}), createdAt: time.Now()} mgr.lock.Lock() mgr.sessions[sid] = &s mgr.lock.Unlock() return &s, nil }
go
func (mgr *MemorySessionManager) NewSession() (Session, error) { sid, err := mgr.sessionID() if err != nil { return nil, err } s := MemorySession{sid: sid, data: make(map[string]interface{}), createdAt: time.Now()} mgr.lock.Lock() mgr.sessions[sid] = &s mgr.lock.Unlock() return &s, nil }
[ "func", "(", "mgr", "*", "MemorySessionManager", ")", "NewSession", "(", ")", "(", "Session", ",", "error", ")", "{", "sid", ",", "err", ":=", "mgr", ".", "sessionID", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "s", ":=", "MemorySession", "{", "sid", ":", "sid", ",", "data", ":", "make", "(", "map", "[", "string", "]", "interface", "{", "}", ")", ",", "createdAt", ":", "time", ".", "Now", "(", ")", "}", "\n", "mgr", ".", "lock", ".", "Lock", "(", ")", "\n", "mgr", ".", "sessions", "[", "sid", "]", "=", "&", "s", "\n", "mgr", ".", "lock", ".", "Unlock", "(", ")", "\n", "return", "&", "s", ",", "nil", "\n", "}" ]
// NewSession creates and returns a new session.
[ "NewSession", "creates", "and", "returns", "a", "new", "session", "." ]
11abebbbb289ef6f35e518db394eaca39cee8732
https://github.com/dinever/golf/blob/11abebbbb289ef6f35e518db394eaca39cee8732/session.go#L60-L70
5,420
dinever/golf
session.go
GarbageCollection
func (mgr *MemorySessionManager) GarbageCollection() { for k, v := range mgr.sessions { if v.isExpired() { delete(mgr.sessions, k) } } time.AfterFunc(time.Duration(gcTimeInterval)*time.Second, mgr.GarbageCollection) }
go
func (mgr *MemorySessionManager) GarbageCollection() { for k, v := range mgr.sessions { if v.isExpired() { delete(mgr.sessions, k) } } time.AfterFunc(time.Duration(gcTimeInterval)*time.Second, mgr.GarbageCollection) }
[ "func", "(", "mgr", "*", "MemorySessionManager", ")", "GarbageCollection", "(", ")", "{", "for", "k", ",", "v", ":=", "range", "mgr", ".", "sessions", "{", "if", "v", ".", "isExpired", "(", ")", "{", "delete", "(", "mgr", ".", "sessions", ",", "k", ")", "\n", "}", "\n", "}", "\n", "time", ".", "AfterFunc", "(", "time", ".", "Duration", "(", "gcTimeInterval", ")", "*", "time", ".", "Second", ",", "mgr", ".", "GarbageCollection", ")", "\n", "}" ]
// GarbageCollection recycles expired sessions, delete them from the session manager.
[ "GarbageCollection", "recycles", "expired", "sessions", "delete", "them", "from", "the", "session", "manager", "." ]
11abebbbb289ef6f35e518db394eaca39cee8732
https://github.com/dinever/golf/blob/11abebbbb289ef6f35e518db394eaca39cee8732/session.go#L73-L80
5,421
dinever/golf
session.go
Set
func (s *MemorySession) Set(key string, value interface{}) error { s.data[key] = value return nil }
go
func (s *MemorySession) Set(key string, value interface{}) error { s.data[key] = value return nil }
[ "func", "(", "s", "*", "MemorySession", ")", "Set", "(", "key", "string", ",", "value", "interface", "{", "}", ")", "error", "{", "s", ".", "data", "[", "key", "]", "=", "value", "\n", "return", "nil", "\n", "}" ]
// Set method sets the key value pair in the session.
[ "Set", "method", "sets", "the", "key", "value", "pair", "in", "the", "session", "." ]
11abebbbb289ef6f35e518db394eaca39cee8732
https://github.com/dinever/golf/blob/11abebbbb289ef6f35e518db394eaca39cee8732/session.go#L109-L112
5,422
dinever/golf
session.go
Get
func (s *MemorySession) Get(key string) (interface{}, error) { if value, ok := s.data[key]; ok { return value, nil } return nil, fmt.Errorf("key %q in session (id %s) not found", key, s.sid) }
go
func (s *MemorySession) Get(key string) (interface{}, error) { if value, ok := s.data[key]; ok { return value, nil } return nil, fmt.Errorf("key %q in session (id %s) not found", key, s.sid) }
[ "func", "(", "s", "*", "MemorySession", ")", "Get", "(", "key", "string", ")", "(", "interface", "{", "}", ",", "error", ")", "{", "if", "value", ",", "ok", ":=", "s", ".", "data", "[", "key", "]", ";", "ok", "{", "return", "value", ",", "nil", "\n", "}", "\n", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "key", ",", "s", ".", "sid", ")", "\n", "}" ]
// Get method gets the value by given a key in the session.
[ "Get", "method", "gets", "the", "value", "by", "given", "a", "key", "in", "the", "session", "." ]
11abebbbb289ef6f35e518db394eaca39cee8732
https://github.com/dinever/golf/blob/11abebbbb289ef6f35e518db394eaca39cee8732/session.go#L115-L120
5,423
dinever/golf
session.go
Delete
func (s *MemorySession) Delete(key string) error { delete(s.data, key) return nil }
go
func (s *MemorySession) Delete(key string) error { delete(s.data, key) return nil }
[ "func", "(", "s", "*", "MemorySession", ")", "Delete", "(", "key", "string", ")", "error", "{", "delete", "(", "s", ".", "data", ",", "key", ")", "\n", "return", "nil", "\n", "}" ]
// Delete method deletes the value by given a key in the session.
[ "Delete", "method", "deletes", "the", "value", "by", "given", "a", "key", "in", "the", "session", "." ]
11abebbbb289ef6f35e518db394eaca39cee8732
https://github.com/dinever/golf/blob/11abebbbb289ef6f35e518db394eaca39cee8732/session.go#L123-L126
5,424
dinever/golf
template.go
LoadTemplate
func (loader *FileSystemLoader) LoadTemplate(name string) (string, error) { f, err := os.Open(path.Join(loader.BaseDir, name)) if err != nil { return "", err } b, err := ioutil.ReadAll(f) return string(b), err }
go
func (loader *FileSystemLoader) LoadTemplate(name string) (string, error) { f, err := os.Open(path.Join(loader.BaseDir, name)) if err != nil { return "", err } b, err := ioutil.ReadAll(f) return string(b), err }
[ "func", "(", "loader", "*", "FileSystemLoader", ")", "LoadTemplate", "(", "name", "string", ")", "(", "string", ",", "error", ")", "{", "f", ",", "err", ":=", "os", ".", "Open", "(", "path", ".", "Join", "(", "loader", ".", "BaseDir", ",", "name", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "err", "\n", "}", "\n", "b", ",", "err", ":=", "ioutil", ".", "ReadAll", "(", "f", ")", "\n", "return", "string", "(", "b", ")", ",", "err", "\n", "}" ]
// LoadTemplate loads a template from a file.
[ "LoadTemplate", "loads", "a", "template", "from", "a", "file", "." ]
11abebbbb289ef6f35e518db394eaca39cee8732
https://github.com/dinever/golf/blob/11abebbbb289ef6f35e518db394eaca39cee8732/template.go#L31-L38
5,425
dinever/golf
template.go
LoadTemplate
func (loader *MapLoader) LoadTemplate(name string) (string, error) { if src, ok := (*loader)[name]; ok { return src, nil } return "", Errorf("Could not find template " + name) }
go
func (loader *MapLoader) LoadTemplate(name string) (string, error) { if src, ok := (*loader)[name]; ok { return src, nil } return "", Errorf("Could not find template " + name) }
[ "func", "(", "loader", "*", "MapLoader", ")", "LoadTemplate", "(", "name", "string", ")", "(", "string", ",", "error", ")", "{", "if", "src", ",", "ok", ":=", "(", "*", "loader", ")", "[", "name", "]", ";", "ok", "{", "return", "src", ",", "nil", "\n", "}", "\n", "return", "\"", "\"", ",", "Errorf", "(", "\"", "\"", "+", "name", ")", "\n", "}" ]
// LoadTemplate loads a template from the map.
[ "LoadTemplate", "loads", "a", "template", "from", "the", "map", "." ]
11abebbbb289ef6f35e518db394eaca39cee8732
https://github.com/dinever/golf/blob/11abebbbb289ef6f35e518db394eaca39cee8732/template.go#L45-L50
5,426
dinever/golf
template.go
Render
func (t *TemplateManager) Render(w io.Writer, name string, data interface{}) error { stack := []*Template{} tplSrc, err := t.getSrc(name) if err != nil { return err } err = t.push(&stack, tplSrc, name) if err != nil { return err } tpl, err := t.assemble(stack) if err != nil { return err } if err != nil { return err } if tpl == nil { return Errorf("Nil template named %s", name) } err = tpl.Execute(w, data) if err != nil { return err } return nil }
go
func (t *TemplateManager) Render(w io.Writer, name string, data interface{}) error { stack := []*Template{} tplSrc, err := t.getSrc(name) if err != nil { return err } err = t.push(&stack, tplSrc, name) if err != nil { return err } tpl, err := t.assemble(stack) if err != nil { return err } if err != nil { return err } if tpl == nil { return Errorf("Nil template named %s", name) } err = tpl.Execute(w, data) if err != nil { return err } return nil }
[ "func", "(", "t", "*", "TemplateManager", ")", "Render", "(", "w", "io", ".", "Writer", ",", "name", "string", ",", "data", "interface", "{", "}", ")", "error", "{", "stack", ":=", "[", "]", "*", "Template", "{", "}", "\n", "tplSrc", ",", "err", ":=", "t", ".", "getSrc", "(", "name", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "err", "=", "t", ".", "push", "(", "&", "stack", ",", "tplSrc", ",", "name", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "tpl", ",", "err", ":=", "t", ".", "assemble", "(", "stack", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "if", "tpl", "==", "nil", "{", "return", "Errorf", "(", "\"", "\"", ",", "name", ")", "\n", "}", "\n\n", "err", "=", "tpl", ".", "Execute", "(", "w", ",", "data", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// Render renders a template and writes it to the io.Writer interface.
[ "Render", "renders", "a", "template", "and", "writes", "it", "to", "the", "io", ".", "Writer", "interface", "." ]
11abebbbb289ef6f35e518db394eaca39cee8732
https://github.com/dinever/golf/blob/11abebbbb289ef6f35e518db394eaca39cee8732/template.go#L65-L93
5,427
dinever/golf
template.go
RenderFromString
func (t *TemplateManager) RenderFromString(w io.Writer, tplSrc string, data interface{}) error { stack := []*Template{} t.push(&stack, tplSrc, "_fromString") tpl, err := t.assemble(stack) if err != nil { return err } err = tpl.Execute(w, data) if err != nil { return err } return nil }
go
func (t *TemplateManager) RenderFromString(w io.Writer, tplSrc string, data interface{}) error { stack := []*Template{} t.push(&stack, tplSrc, "_fromString") tpl, err := t.assemble(stack) if err != nil { return err } err = tpl.Execute(w, data) if err != nil { return err } return nil }
[ "func", "(", "t", "*", "TemplateManager", ")", "RenderFromString", "(", "w", "io", ".", "Writer", ",", "tplSrc", "string", ",", "data", "interface", "{", "}", ")", "error", "{", "stack", ":=", "[", "]", "*", "Template", "{", "}", "\n", "t", ".", "push", "(", "&", "stack", ",", "tplSrc", ",", "\"", "\"", ")", "\n", "tpl", ",", "err", ":=", "t", ".", "assemble", "(", "stack", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "err", "=", "tpl", ".", "Execute", "(", "w", ",", "data", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// RenderFromString renders a template from string.
[ "RenderFromString", "renders", "a", "template", "from", "string", "." ]
11abebbbb289ef6f35e518db394eaca39cee8732
https://github.com/dinever/golf/blob/11abebbbb289ef6f35e518db394eaca39cee8732/template.go#L96-L110
5,428
dinever/golf
view.go
NewView
func NewView() *View { view := new(View) view.templateLoader = make(map[string]*TemplateManager) view.FuncMap = make(template.FuncMap) view.FuncMap["Html"] = func(s string) template.HTML { return template.HTML(s) } return view }
go
func NewView() *View { view := new(View) view.templateLoader = make(map[string]*TemplateManager) view.FuncMap = make(template.FuncMap) view.FuncMap["Html"] = func(s string) template.HTML { return template.HTML(s) } return view }
[ "func", "NewView", "(", ")", "*", "View", "{", "view", ":=", "new", "(", "View", ")", "\n", "view", ".", "templateLoader", "=", "make", "(", "map", "[", "string", "]", "*", "TemplateManager", ")", "\n", "view", ".", "FuncMap", "=", "make", "(", "template", ".", "FuncMap", ")", "\n", "view", ".", "FuncMap", "[", "\"", "\"", "]", "=", "func", "(", "s", "string", ")", "template", ".", "HTML", "{", "return", "template", ".", "HTML", "(", "s", ")", "}", "\n", "return", "view", "\n", "}" ]
// NewView creates a new View instance.
[ "NewView", "creates", "a", "new", "View", "instance", "." ]
11abebbbb289ef6f35e518db394eaca39cee8732
https://github.com/dinever/golf/blob/11abebbbb289ef6f35e518db394eaca39cee8732/view.go#L19-L25
5,429
dinever/golf
view.go
Render
func (view *View) Render(loaderName string, filePath string, data map[string]interface{}) (string, error) { loader, ok := view.templateLoader[loaderName] if !ok { panic(errors.New("Template loader not found: " + loaderName)) } var buf bytes.Buffer err := loader.Render(&buf, filePath, data) if err != nil { return "", err } return buf.String(), nil }
go
func (view *View) Render(loaderName string, filePath string, data map[string]interface{}) (string, error) { loader, ok := view.templateLoader[loaderName] if !ok { panic(errors.New("Template loader not found: " + loaderName)) } var buf bytes.Buffer err := loader.Render(&buf, filePath, data) if err != nil { return "", err } return buf.String(), nil }
[ "func", "(", "view", "*", "View", ")", "Render", "(", "loaderName", "string", ",", "filePath", "string", ",", "data", "map", "[", "string", "]", "interface", "{", "}", ")", "(", "string", ",", "error", ")", "{", "loader", ",", "ok", ":=", "view", ".", "templateLoader", "[", "loaderName", "]", "\n", "if", "!", "ok", "{", "panic", "(", "errors", ".", "New", "(", "\"", "\"", "+", "loaderName", ")", ")", "\n", "}", "\n", "var", "buf", "bytes", ".", "Buffer", "\n", "err", ":=", "loader", ".", "Render", "(", "&", "buf", ",", "filePath", ",", "data", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "err", "\n", "}", "\n", "return", "buf", ".", "String", "(", ")", ",", "nil", "\n", "}" ]
// Render renders a template by indicating the file path and the name of the template loader.
[ "Render", "renders", "a", "template", "by", "indicating", "the", "file", "path", "and", "the", "name", "of", "the", "template", "loader", "." ]
11abebbbb289ef6f35e518db394eaca39cee8732
https://github.com/dinever/golf/blob/11abebbbb289ef6f35e518db394eaca39cee8732/view.go#L28-L39
5,430
dinever/golf
view.go
RenderFromString
func (view *View) RenderFromString(loaderName string, tplSrc string, data map[string]interface{}) (string, error) { var buf bytes.Buffer // If loaderName is not indicated, use the default template library of Go, no syntax like // `extends` or `include` will be supported. if loaderName == "" { tmpl := template.New("error") tmpl.Parse(tplSrc) e := tmpl.Execute(&buf, data) return buf.String(), e } loader, ok := view.templateLoader[loaderName] if !ok { panic(Errorf("Template loader not fount: %s", loaderName)) } e := loader.Render(&buf, tplSrc, data) if e != nil { return "", e } return buf.String(), nil }
go
func (view *View) RenderFromString(loaderName string, tplSrc string, data map[string]interface{}) (string, error) { var buf bytes.Buffer // If loaderName is not indicated, use the default template library of Go, no syntax like // `extends` or `include` will be supported. if loaderName == "" { tmpl := template.New("error") tmpl.Parse(tplSrc) e := tmpl.Execute(&buf, data) return buf.String(), e } loader, ok := view.templateLoader[loaderName] if !ok { panic(Errorf("Template loader not fount: %s", loaderName)) } e := loader.Render(&buf, tplSrc, data) if e != nil { return "", e } return buf.String(), nil }
[ "func", "(", "view", "*", "View", ")", "RenderFromString", "(", "loaderName", "string", ",", "tplSrc", "string", ",", "data", "map", "[", "string", "]", "interface", "{", "}", ")", "(", "string", ",", "error", ")", "{", "var", "buf", "bytes", ".", "Buffer", "\n", "// If loaderName is not indicated, use the default template library of Go, no syntax like", "// `extends` or `include` will be supported.", "if", "loaderName", "==", "\"", "\"", "{", "tmpl", ":=", "template", ".", "New", "(", "\"", "\"", ")", "\n", "tmpl", ".", "Parse", "(", "tplSrc", ")", "\n", "e", ":=", "tmpl", ".", "Execute", "(", "&", "buf", ",", "data", ")", "\n", "return", "buf", ".", "String", "(", ")", ",", "e", "\n", "}", "\n", "loader", ",", "ok", ":=", "view", ".", "templateLoader", "[", "loaderName", "]", "\n", "if", "!", "ok", "{", "panic", "(", "Errorf", "(", "\"", "\"", ",", "loaderName", ")", ")", "\n", "}", "\n", "e", ":=", "loader", ".", "Render", "(", "&", "buf", ",", "tplSrc", ",", "data", ")", "\n", "if", "e", "!=", "nil", "{", "return", "\"", "\"", ",", "e", "\n", "}", "\n", "return", "buf", ".", "String", "(", ")", ",", "nil", "\n", "}" ]
// RenderFromString does the same thing as render but renders a template by // indicating the template source from tplSrc.
[ "RenderFromString", "does", "the", "same", "thing", "as", "render", "but", "renders", "a", "template", "by", "indicating", "the", "template", "source", "from", "tplSrc", "." ]
11abebbbb289ef6f35e518db394eaca39cee8732
https://github.com/dinever/golf/blob/11abebbbb289ef6f35e518db394eaca39cee8732/view.go#L43-L62
5,431
dinever/golf
view.go
SetTemplateLoader
func (view *View) SetTemplateLoader(name string, path string) { loader := &TemplateManager{ Loader: &FileSystemLoader{ BaseDir: path, }, FuncMap: view.FuncMap, } view.templateLoader[name] = loader }
go
func (view *View) SetTemplateLoader(name string, path string) { loader := &TemplateManager{ Loader: &FileSystemLoader{ BaseDir: path, }, FuncMap: view.FuncMap, } view.templateLoader[name] = loader }
[ "func", "(", "view", "*", "View", ")", "SetTemplateLoader", "(", "name", "string", ",", "path", "string", ")", "{", "loader", ":=", "&", "TemplateManager", "{", "Loader", ":", "&", "FileSystemLoader", "{", "BaseDir", ":", "path", ",", "}", ",", "FuncMap", ":", "view", ".", "FuncMap", ",", "}", "\n", "view", ".", "templateLoader", "[", "name", "]", "=", "loader", "\n", "}" ]
// SetTemplateLoader sets the template loader by indicating the name and the path.
[ "SetTemplateLoader", "sets", "the", "template", "loader", "by", "indicating", "the", "name", "and", "the", "path", "." ]
11abebbbb289ef6f35e518db394eaca39cee8732
https://github.com/dinever/golf/blob/11abebbbb289ef6f35e518db394eaca39cee8732/view.go#L65-L73
5,432
gorgonia/cu
cmd/genlib/signature.go
flagType
func flagType(name string) string { switch name { case "cuCtxCreate", "cuDevicePrimaryCtxSetFlags": return "ContextFlags" case "cuLinkCreate": panic("Unhandled") case "cuStreamCreate", "cuStreamCreateWithPriority": return "StreamFlags" case "cuEventCreate": return "EventFlags" case "cuTexRefSetFlags": return "TexRefFlags" default: log.Printf("Unreachable flagtype %v", name) } panic("Unreachable") }
go
func flagType(name string) string { switch name { case "cuCtxCreate", "cuDevicePrimaryCtxSetFlags": return "ContextFlags" case "cuLinkCreate": panic("Unhandled") case "cuStreamCreate", "cuStreamCreateWithPriority": return "StreamFlags" case "cuEventCreate": return "EventFlags" case "cuTexRefSetFlags": return "TexRefFlags" default: log.Printf("Unreachable flagtype %v", name) } panic("Unreachable") }
[ "func", "flagType", "(", "name", "string", ")", "string", "{", "switch", "name", "{", "case", "\"", "\"", ",", "\"", "\"", ":", "return", "\"", "\"", "\n", "case", "\"", "\"", ":", "panic", "(", "\"", "\"", ")", "\n", "case", "\"", "\"", ",", "\"", "\"", ":", "return", "\"", "\"", "\n", "case", "\"", "\"", ":", "return", "\"", "\"", "\n", "case", "\"", "\"", ":", "return", "\"", "\"", "\n", "default", ":", "log", ".", "Printf", "(", "\"", "\"", ",", "name", ")", "\n", "}", "\n", "panic", "(", "\"", "\"", ")", "\n", "}" ]
// flag type returns the correct flag type for the Go signatures
[ "flag", "type", "returns", "the", "correct", "flag", "type", "for", "the", "Go", "signatures" ]
89152d7e441439045736bc7640ff607ec371c26c
https://github.com/gorgonia/cu/blob/89152d7e441439045736bc7640ff607ec371c26c/cmd/genlib/signature.go#L207-L223
5,433
gorgonia/cu
stream.go
MakeStream
func MakeStream(flags StreamFlags) (Stream, error) { var s Stream err := result(C.cuStreamCreate(&s.s, C.uint(flags))) return s, err }
go
func MakeStream(flags StreamFlags) (Stream, error) { var s Stream err := result(C.cuStreamCreate(&s.s, C.uint(flags))) return s, err }
[ "func", "MakeStream", "(", "flags", "StreamFlags", ")", "(", "Stream", ",", "error", ")", "{", "var", "s", "Stream", "\n", "err", ":=", "result", "(", "C", ".", "cuStreamCreate", "(", "&", "s", ".", "s", ",", "C", ".", "uint", "(", "flags", ")", ")", ")", "\n", "return", "s", ",", "err", "\n", "}" ]
// MakeStream creates a stream. The flags determines the behaviors of the stream.
[ "MakeStream", "creates", "a", "stream", ".", "The", "flags", "determines", "the", "behaviors", "of", "the", "stream", "." ]
89152d7e441439045736bc7640ff607ec371c26c
https://github.com/gorgonia/cu/blob/89152d7e441439045736bc7640ff607ec371c26c/stream.go#L23-L27
5,434
gorgonia/cu
stream.go
MakeStreamWithPriority
func MakeStreamWithPriority(priority int, flags StreamFlags) (Stream, error) { var s Stream err := result(C.cuStreamCreateWithPriority(&s.s, C.uint(flags), C.int(priority))) return s, err }
go
func MakeStreamWithPriority(priority int, flags StreamFlags) (Stream, error) { var s Stream err := result(C.cuStreamCreateWithPriority(&s.s, C.uint(flags), C.int(priority))) return s, err }
[ "func", "MakeStreamWithPriority", "(", "priority", "int", ",", "flags", "StreamFlags", ")", "(", "Stream", ",", "error", ")", "{", "var", "s", "Stream", "\n", "err", ":=", "result", "(", "C", ".", "cuStreamCreateWithPriority", "(", "&", "s", ".", "s", ",", "C", ".", "uint", "(", "flags", ")", ",", "C", ".", "int", "(", "priority", ")", ")", ")", "\n", "return", "s", ",", "err", "\n", "}" ]
// MakeStreamWithPriority creates a stream with the given priority. The flags determines the behaviors of the stream. // This API alters the scheduler priority of work in the stream. Work in a higher priority stream may preempt work already executing in a low priority stream. // // `priority` follows a convention where lower numbers represent higher priorities. '0' represents default priority. // // The range of meaningful numerical priorities can be queried using `StreamPriorityRange`. // If the specified priority is outside the numerical range returned by `StreamPriorityRange`, // it will automatically be clamped to the lowest or the highest number in the range.
[ "MakeStreamWithPriority", "creates", "a", "stream", "with", "the", "given", "priority", ".", "The", "flags", "determines", "the", "behaviors", "of", "the", "stream", ".", "This", "API", "alters", "the", "scheduler", "priority", "of", "work", "in", "the", "stream", ".", "Work", "in", "a", "higher", "priority", "stream", "may", "preempt", "work", "already", "executing", "in", "a", "low", "priority", "stream", ".", "priority", "follows", "a", "convention", "where", "lower", "numbers", "represent", "higher", "priorities", ".", "0", "represents", "default", "priority", ".", "The", "range", "of", "meaningful", "numerical", "priorities", "can", "be", "queried", "using", "StreamPriorityRange", ".", "If", "the", "specified", "priority", "is", "outside", "the", "numerical", "range", "returned", "by", "StreamPriorityRange", "it", "will", "automatically", "be", "clamped", "to", "the", "lowest", "or", "the", "highest", "number", "in", "the", "range", "." ]
89152d7e441439045736bc7640ff607ec371c26c
https://github.com/gorgonia/cu/blob/89152d7e441439045736bc7640ff607ec371c26c/stream.go#L37-L41
5,435
gorgonia/cu
cmd/gencudnn/generatethis.go
generateCRUD
func generateCRUD(buf io.Writer, t *cc.TranslationUnit, fnType string) { decls, err := bindgen.Get(t, functions) handleErr(err) var a = make(map[string][]string) switch fnType { case "create": fmt.Fprintf(buf, "creations = ") case "get": fmt.Fprintf(buf, "getFns = ") case "set": fmt.Fprintf(buf, "setFns = ") case "destroy": fmt.Fprintf(buf, "destructions = ") case "methods": fmt.Fprintf(buf, "methods = ") } var b map[string]struct{} for _, d := range decls { cs := d.(*bindgen.CSignature) params := cs.Parameters() if fnType != "methods" && !strings.Contains(strings.ToLower(cs.Name), fnType) { continue } if fnType == "methods" && len(params) == 0 { continue } switch fnType { case "create": for i := len(params) - 1; i >= 0; i-- { p := params[i] if !bindgen.IsConstType(p.Type()) && bindgen.IsPointer(p.Type()) { typ := nameOfType(p.Type()) a[typ] = append(a[typ], cs.Name) } } case "set", "destroy": p := params[0] typ := nameOfType(p.Type()) if typ == "cudnnHandle_t" && len(params) > 1 { p = params[1] typ = nameOfType(p.Type()) } a[typ] = append(a[typ], cs.Name) case "methods": // if strings.Contains(strings.ToLower(cs.Name), "get") { // continue // } if _, ok := ignored[cs.Name]; ok { continue } if alreadyGenIn(cs.Name, creations, setFns, destructions) { continue } p := params[0] typ := nameOfType(p.Type()) a[typ] = append(a[typ], cs.Name) } } fmt.Fprintf(buf, "%# v\n\n", pretty.Formatter(a)) // set the actual thing if not set // lisp users just shake their head in disappointment switch fnType { case "create": creations = a case "set": setFns = a case "destroy": destructions = a case "methods": methods = a if b != nil { fmt.Fprintf(buf, "orphaned = %# v\n\n", pretty.Formatter(b)) orphaned = b } } }
go
func generateCRUD(buf io.Writer, t *cc.TranslationUnit, fnType string) { decls, err := bindgen.Get(t, functions) handleErr(err) var a = make(map[string][]string) switch fnType { case "create": fmt.Fprintf(buf, "creations = ") case "get": fmt.Fprintf(buf, "getFns = ") case "set": fmt.Fprintf(buf, "setFns = ") case "destroy": fmt.Fprintf(buf, "destructions = ") case "methods": fmt.Fprintf(buf, "methods = ") } var b map[string]struct{} for _, d := range decls { cs := d.(*bindgen.CSignature) params := cs.Parameters() if fnType != "methods" && !strings.Contains(strings.ToLower(cs.Name), fnType) { continue } if fnType == "methods" && len(params) == 0 { continue } switch fnType { case "create": for i := len(params) - 1; i >= 0; i-- { p := params[i] if !bindgen.IsConstType(p.Type()) && bindgen.IsPointer(p.Type()) { typ := nameOfType(p.Type()) a[typ] = append(a[typ], cs.Name) } } case "set", "destroy": p := params[0] typ := nameOfType(p.Type()) if typ == "cudnnHandle_t" && len(params) > 1 { p = params[1] typ = nameOfType(p.Type()) } a[typ] = append(a[typ], cs.Name) case "methods": // if strings.Contains(strings.ToLower(cs.Name), "get") { // continue // } if _, ok := ignored[cs.Name]; ok { continue } if alreadyGenIn(cs.Name, creations, setFns, destructions) { continue } p := params[0] typ := nameOfType(p.Type()) a[typ] = append(a[typ], cs.Name) } } fmt.Fprintf(buf, "%# v\n\n", pretty.Formatter(a)) // set the actual thing if not set // lisp users just shake their head in disappointment switch fnType { case "create": creations = a case "set": setFns = a case "destroy": destructions = a case "methods": methods = a if b != nil { fmt.Fprintf(buf, "orphaned = %# v\n\n", pretty.Formatter(b)) orphaned = b } } }
[ "func", "generateCRUD", "(", "buf", "io", ".", "Writer", ",", "t", "*", "cc", ".", "TranslationUnit", ",", "fnType", "string", ")", "{", "decls", ",", "err", ":=", "bindgen", ".", "Get", "(", "t", ",", "functions", ")", "\n", "handleErr", "(", "err", ")", "\n\n", "var", "a", "=", "make", "(", "map", "[", "string", "]", "[", "]", "string", ")", "\n", "switch", "fnType", "{", "case", "\"", "\"", ":", "fmt", ".", "Fprintf", "(", "buf", ",", "\"", "\"", ")", "\n", "case", "\"", "\"", ":", "fmt", ".", "Fprintf", "(", "buf", ",", "\"", "\"", ")", "\n", "case", "\"", "\"", ":", "fmt", ".", "Fprintf", "(", "buf", ",", "\"", "\"", ")", "\n", "case", "\"", "\"", ":", "fmt", ".", "Fprintf", "(", "buf", ",", "\"", "\"", ")", "\n", "case", "\"", "\"", ":", "fmt", ".", "Fprintf", "(", "buf", ",", "\"", "\"", ")", "\n", "}", "\n\n", "var", "b", "map", "[", "string", "]", "struct", "{", "}", "\n\n", "for", "_", ",", "d", ":=", "range", "decls", "{", "cs", ":=", "d", ".", "(", "*", "bindgen", ".", "CSignature", ")", "\n", "params", ":=", "cs", ".", "Parameters", "(", ")", "\n\n", "if", "fnType", "!=", "\"", "\"", "&&", "!", "strings", ".", "Contains", "(", "strings", ".", "ToLower", "(", "cs", ".", "Name", ")", ",", "fnType", ")", "{", "continue", "\n", "}", "\n", "if", "fnType", "==", "\"", "\"", "&&", "len", "(", "params", ")", "==", "0", "{", "continue", "\n", "}", "\n\n", "switch", "fnType", "{", "case", "\"", "\"", ":", "for", "i", ":=", "len", "(", "params", ")", "-", "1", ";", "i", ">=", "0", ";", "i", "--", "{", "p", ":=", "params", "[", "i", "]", "\n", "if", "!", "bindgen", ".", "IsConstType", "(", "p", ".", "Type", "(", ")", ")", "&&", "bindgen", ".", "IsPointer", "(", "p", ".", "Type", "(", ")", ")", "{", "typ", ":=", "nameOfType", "(", "p", ".", "Type", "(", ")", ")", "\n", "a", "[", "typ", "]", "=", "append", "(", "a", "[", "typ", "]", ",", "cs", ".", "Name", ")", "\n", "}", "\n", "}", "\n\n", "case", "\"", "\"", ",", "\"", "\"", ":", "p", ":=", "params", "[", "0", "]", "\n", "typ", ":=", "nameOfType", "(", "p", ".", "Type", "(", ")", ")", "\n", "if", "typ", "==", "\"", "\"", "&&", "len", "(", "params", ")", ">", "1", "{", "p", "=", "params", "[", "1", "]", "\n", "typ", "=", "nameOfType", "(", "p", ".", "Type", "(", ")", ")", "\n", "}", "\n", "a", "[", "typ", "]", "=", "append", "(", "a", "[", "typ", "]", ",", "cs", ".", "Name", ")", "\n", "case", "\"", "\"", ":", "// if strings.Contains(strings.ToLower(cs.Name), \"get\") {", "// \tcontinue", "// }", "if", "_", ",", "ok", ":=", "ignored", "[", "cs", ".", "Name", "]", ";", "ok", "{", "continue", "\n", "}", "\n", "if", "alreadyGenIn", "(", "cs", ".", "Name", ",", "creations", ",", "setFns", ",", "destructions", ")", "{", "continue", "\n", "}", "\n\n", "p", ":=", "params", "[", "0", "]", "\n", "typ", ":=", "nameOfType", "(", "p", ".", "Type", "(", ")", ")", "\n", "a", "[", "typ", "]", "=", "append", "(", "a", "[", "typ", "]", ",", "cs", ".", "Name", ")", "\n", "}", "\n", "}", "\n", "fmt", ".", "Fprintf", "(", "buf", ",", "\"", "\\n", "\\n", "\"", ",", "pretty", ".", "Formatter", "(", "a", ")", ")", "\n\n", "// set the actual thing if not set", "// lisp users just shake their head in disappointment", "switch", "fnType", "{", "case", "\"", "\"", ":", "creations", "=", "a", "\n", "case", "\"", "\"", ":", "setFns", "=", "a", "\n", "case", "\"", "\"", ":", "destructions", "=", "a", "\n", "case", "\"", "\"", ":", "methods", "=", "a", "\n", "if", "b", "!=", "nil", "{", "fmt", ".", "Fprintf", "(", "buf", ",", "\"", "\\n", "\\n", "\"", ",", "pretty", ".", "Formatter", "(", "b", ")", ")", "\n", "orphaned", "=", "b", "\n", "}", "\n", "}", "\n", "}" ]
// generateCRUD creates lists of CRUD functions for the generateStubs function to consume
[ "generateCRUD", "creates", "lists", "of", "CRUD", "functions", "for", "the", "generateStubs", "function", "to", "consume" ]
89152d7e441439045736bc7640ff607ec371c26c
https://github.com/gorgonia/cu/blob/89152d7e441439045736bc7640ff607ec371c26c/cmd/gencudnn/generatethis.go#L56-L139
5,436
gorgonia/cu
ctx.go
Close
func (ctx *Ctx) Close() error { var empty C.CUcontext if ctx.CUContext.ctx == empty { return nil } if ctx.errChan != nil { close(ctx.errChan) ctx.errChan = nil } if ctx.work != nil { close(ctx.work) ctx.work = nil } err := result(C.cuCtxDestroy(C.CUcontext(unsafe.Pointer(ctx.CUContext.ctx)))) ctx.CUContext.ctx = empty return err }
go
func (ctx *Ctx) Close() error { var empty C.CUcontext if ctx.CUContext.ctx == empty { return nil } if ctx.errChan != nil { close(ctx.errChan) ctx.errChan = nil } if ctx.work != nil { close(ctx.work) ctx.work = nil } err := result(C.cuCtxDestroy(C.CUcontext(unsafe.Pointer(ctx.CUContext.ctx)))) ctx.CUContext.ctx = empty return err }
[ "func", "(", "ctx", "*", "Ctx", ")", "Close", "(", ")", "error", "{", "var", "empty", "C", ".", "CUcontext", "\n", "if", "ctx", ".", "CUContext", ".", "ctx", "==", "empty", "{", "return", "nil", "\n", "}", "\n\n", "if", "ctx", ".", "errChan", "!=", "nil", "{", "close", "(", "ctx", ".", "errChan", ")", "\n", "ctx", ".", "errChan", "=", "nil", "\n", "}", "\n\n", "if", "ctx", ".", "work", "!=", "nil", "{", "close", "(", "ctx", ".", "work", ")", "\n", "ctx", ".", "work", "=", "nil", "\n", "}", "\n\n", "err", ":=", "result", "(", "C", ".", "cuCtxDestroy", "(", "C", ".", "CUcontext", "(", "unsafe", ".", "Pointer", "(", "ctx", ".", "CUContext", ".", "ctx", ")", ")", ")", ")", "\n", "ctx", ".", "CUContext", ".", "ctx", "=", "empty", "\n", "return", "err", "\n", "}" ]
// Close destroys the CUDA context and associated resources that has been created. Additionally, all channels of communications will be closed.
[ "Close", "destroys", "the", "CUDA", "context", "and", "associated", "resources", "that", "has", "been", "created", ".", "Additionally", "all", "channels", "of", "communications", "will", "be", "closed", "." ]
89152d7e441439045736bc7640ff607ec371c26c
https://github.com/gorgonia/cu/blob/89152d7e441439045736bc7640ff607ec371c26c/ctx.go#L84-L103
5,437
gorgonia/cu
dnn/pooling.go
NewPooling
func NewPooling(mode PoolingMode, maxpoolingNanOpt NanPropagation, shape, strides, padding []int) (retVal *Pooling, err error) { var internal C.cudnnPoolingDescriptor_t if err = result(C.cudnnCreatePoolingDescriptor(&internal)); err != nil { return nil, err } // checks shapes and strides if len(shape) != len(strides) || len(strides) != len(padding) { return nil, errors.Errorf(shapeMismatch3, shape, strides, padding) } switch len(shape) { case 0: return nil, errors.Errorf("Cannot perform pooling with shape %v", shape) case 2: windowHeight, windowWidth := shape[0], shape[1] verticalPadding, horizontalPadding := padding[0], padding[1] verticalStride, horizontalStride := strides[0], strides[1] if err = result(C.cudnnSetPooling2dDescriptor(internal, mode.C(), maxpoolingNanOpt.C(), C.int(windowHeight), C.int(windowWidth), C.int(verticalPadding), C.int(horizontalPadding), C.int(verticalStride), C.int(horizontalStride))); err != nil { return nil, err } default: nbDims := len(shape) shapePtr, shapePtrManaged := ints2CIntPtr(shape) defer returnManaged(shapePtrManaged) paddingPtr, paddingPtrManaged := ints2CIntPtr(padding) defer returnManaged(paddingPtrManaged) stridePtr, stridePtrManaged := ints2CIntPtr(strides) defer returnManaged(stridePtrManaged) if err = result(C.cudnnSetPoolingNdDescriptor(internal, mode.C(), maxpoolingNanOpt.C(), C.int(nbDims), shapePtr, paddingPtr, stridePtr)); err != nil { return nil, err } } retVal = &Pooling{ internal: internal, mode: mode, maxpoolingNanNopt: maxpoolingNanOpt, shape: shape, padding: padding, strides: strides, } runtime.SetFinalizer(retVal, destroyPooling) return retVal, nil }
go
func NewPooling(mode PoolingMode, maxpoolingNanOpt NanPropagation, shape, strides, padding []int) (retVal *Pooling, err error) { var internal C.cudnnPoolingDescriptor_t if err = result(C.cudnnCreatePoolingDescriptor(&internal)); err != nil { return nil, err } // checks shapes and strides if len(shape) != len(strides) || len(strides) != len(padding) { return nil, errors.Errorf(shapeMismatch3, shape, strides, padding) } switch len(shape) { case 0: return nil, errors.Errorf("Cannot perform pooling with shape %v", shape) case 2: windowHeight, windowWidth := shape[0], shape[1] verticalPadding, horizontalPadding := padding[0], padding[1] verticalStride, horizontalStride := strides[0], strides[1] if err = result(C.cudnnSetPooling2dDescriptor(internal, mode.C(), maxpoolingNanOpt.C(), C.int(windowHeight), C.int(windowWidth), C.int(verticalPadding), C.int(horizontalPadding), C.int(verticalStride), C.int(horizontalStride))); err != nil { return nil, err } default: nbDims := len(shape) shapePtr, shapePtrManaged := ints2CIntPtr(shape) defer returnManaged(shapePtrManaged) paddingPtr, paddingPtrManaged := ints2CIntPtr(padding) defer returnManaged(paddingPtrManaged) stridePtr, stridePtrManaged := ints2CIntPtr(strides) defer returnManaged(stridePtrManaged) if err = result(C.cudnnSetPoolingNdDescriptor(internal, mode.C(), maxpoolingNanOpt.C(), C.int(nbDims), shapePtr, paddingPtr, stridePtr)); err != nil { return nil, err } } retVal = &Pooling{ internal: internal, mode: mode, maxpoolingNanNopt: maxpoolingNanOpt, shape: shape, padding: padding, strides: strides, } runtime.SetFinalizer(retVal, destroyPooling) return retVal, nil }
[ "func", "NewPooling", "(", "mode", "PoolingMode", ",", "maxpoolingNanOpt", "NanPropagation", ",", "shape", ",", "strides", ",", "padding", "[", "]", "int", ")", "(", "retVal", "*", "Pooling", ",", "err", "error", ")", "{", "var", "internal", "C", ".", "cudnnPoolingDescriptor_t", "\n", "if", "err", "=", "result", "(", "C", ".", "cudnnCreatePoolingDescriptor", "(", "&", "internal", ")", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "// checks shapes and strides", "if", "len", "(", "shape", ")", "!=", "len", "(", "strides", ")", "||", "len", "(", "strides", ")", "!=", "len", "(", "padding", ")", "{", "return", "nil", ",", "errors", ".", "Errorf", "(", "shapeMismatch3", ",", "shape", ",", "strides", ",", "padding", ")", "\n", "}", "\n\n", "switch", "len", "(", "shape", ")", "{", "case", "0", ":", "return", "nil", ",", "errors", ".", "Errorf", "(", "\"", "\"", ",", "shape", ")", "\n", "case", "2", ":", "windowHeight", ",", "windowWidth", ":=", "shape", "[", "0", "]", ",", "shape", "[", "1", "]", "\n", "verticalPadding", ",", "horizontalPadding", ":=", "padding", "[", "0", "]", ",", "padding", "[", "1", "]", "\n", "verticalStride", ",", "horizontalStride", ":=", "strides", "[", "0", "]", ",", "strides", "[", "1", "]", "\n", "if", "err", "=", "result", "(", "C", ".", "cudnnSetPooling2dDescriptor", "(", "internal", ",", "mode", ".", "C", "(", ")", ",", "maxpoolingNanOpt", ".", "C", "(", ")", ",", "C", ".", "int", "(", "windowHeight", ")", ",", "C", ".", "int", "(", "windowWidth", ")", ",", "C", ".", "int", "(", "verticalPadding", ")", ",", "C", ".", "int", "(", "horizontalPadding", ")", ",", "C", ".", "int", "(", "verticalStride", ")", ",", "C", ".", "int", "(", "horizontalStride", ")", ")", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "default", ":", "nbDims", ":=", "len", "(", "shape", ")", "\n", "shapePtr", ",", "shapePtrManaged", ":=", "ints2CIntPtr", "(", "shape", ")", "\n", "defer", "returnManaged", "(", "shapePtrManaged", ")", "\n", "paddingPtr", ",", "paddingPtrManaged", ":=", "ints2CIntPtr", "(", "padding", ")", "\n", "defer", "returnManaged", "(", "paddingPtrManaged", ")", "\n", "stridePtr", ",", "stridePtrManaged", ":=", "ints2CIntPtr", "(", "strides", ")", "\n", "defer", "returnManaged", "(", "stridePtrManaged", ")", "\n", "if", "err", "=", "result", "(", "C", ".", "cudnnSetPoolingNdDescriptor", "(", "internal", ",", "mode", ".", "C", "(", ")", ",", "maxpoolingNanOpt", ".", "C", "(", ")", ",", "C", ".", "int", "(", "nbDims", ")", ",", "shapePtr", ",", "paddingPtr", ",", "stridePtr", ")", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "}", "\n\n", "retVal", "=", "&", "Pooling", "{", "internal", ":", "internal", ",", "mode", ":", "mode", ",", "maxpoolingNanNopt", ":", "maxpoolingNanOpt", ",", "shape", ":", "shape", ",", "padding", ":", "padding", ",", "strides", ":", "strides", ",", "}", "\n", "runtime", ".", "SetFinalizer", "(", "retVal", ",", "destroyPooling", ")", "\n", "return", "retVal", ",", "nil", "\n", "}" ]
// NewPooling creates a new Pooling op.
[ "NewPooling", "creates", "a", "new", "Pooling", "op", "." ]
89152d7e441439045736bc7640ff607ec371c26c
https://github.com/gorgonia/cu/blob/89152d7e441439045736bc7640ff607ec371c26c/dnn/pooling.go#L31-L75
5,438
gorgonia/cu
dnn/pooling.go
OutputShape
func (p *Pooling) OutputShape(input *TensorDescriptor, dims int) (retVal []int, err error) { if dims == p.outDims && shapeEq(input.shape, p.inputTensor) { return cloneShape(p.outputShape), nil } return p.CalcOutputShape(input, dims) }
go
func (p *Pooling) OutputShape(input *TensorDescriptor, dims int) (retVal []int, err error) { if dims == p.outDims && shapeEq(input.shape, p.inputTensor) { return cloneShape(p.outputShape), nil } return p.CalcOutputShape(input, dims) }
[ "func", "(", "p", "*", "Pooling", ")", "OutputShape", "(", "input", "*", "TensorDescriptor", ",", "dims", "int", ")", "(", "retVal", "[", "]", "int", ",", "err", "error", ")", "{", "if", "dims", "==", "p", ".", "outDims", "&&", "shapeEq", "(", "input", ".", "shape", ",", "p", ".", "inputTensor", ")", "{", "return", "cloneShape", "(", "p", ".", "outputShape", ")", ",", "nil", "\n", "}", "\n", "return", "p", ".", "CalcOutputShape", "(", "input", ",", "dims", ")", "\n", "}" ]
// OutputShape computes the output shape given the input tensor. // // This method caches the outputShape. If a inputTensor is seen before, and the dims is exactly the same, then the cached output shape is used
[ "OutputShape", "computes", "the", "output", "shape", "given", "the", "input", "tensor", ".", "This", "method", "caches", "the", "outputShape", ".", "If", "a", "inputTensor", "is", "seen", "before", "and", "the", "dims", "is", "exactly", "the", "same", "then", "the", "cached", "output", "shape", "is", "used" ]
89152d7e441439045736bc7640ff607ec371c26c
https://github.com/gorgonia/cu/blob/89152d7e441439045736bc7640ff607ec371c26c/dnn/pooling.go#L95-L100
5,439
gorgonia/cu
dnn/pooling.go
CalcOutputShape
func (p *Pooling) CalcOutputShape(input *TensorDescriptor, dims int) (retVal []int, err error) { p.outDims = dims p.inputTensor = cloneShape(input.shape) switch dims { case 0: return nil, errors.Errorf("Cannot work on dims of 0") case 2: p.outputShape = make([]int, 4) n := (*C.int)(unsafe.Pointer(&p.outputShape[0])) c := (*C.int)(unsafe.Pointer(&p.outputShape[1])) h := (*C.int)(unsafe.Pointer(&p.outputShape[2])) w := (*C.int)(unsafe.Pointer(&p.outputShape[3])) if err = result(C.cudnnGetPooling2dForwardOutputDim(p.internal, input.internal, n, c, h, w)); err != nil { return nil, err } default: p.outputShape = make([]int, dims) ptr, ptrManaged := ints2CIntPtr(p.outputShape) defer returnManaged(ptrManaged) if err = result(C.cudnnGetPoolingNdForwardOutputDim(p.internal, input.internal, C.int(dims), ptr)); err != nil { return nil, err } } return cloneShape(p.outputShape), nil }
go
func (p *Pooling) CalcOutputShape(input *TensorDescriptor, dims int) (retVal []int, err error) { p.outDims = dims p.inputTensor = cloneShape(input.shape) switch dims { case 0: return nil, errors.Errorf("Cannot work on dims of 0") case 2: p.outputShape = make([]int, 4) n := (*C.int)(unsafe.Pointer(&p.outputShape[0])) c := (*C.int)(unsafe.Pointer(&p.outputShape[1])) h := (*C.int)(unsafe.Pointer(&p.outputShape[2])) w := (*C.int)(unsafe.Pointer(&p.outputShape[3])) if err = result(C.cudnnGetPooling2dForwardOutputDim(p.internal, input.internal, n, c, h, w)); err != nil { return nil, err } default: p.outputShape = make([]int, dims) ptr, ptrManaged := ints2CIntPtr(p.outputShape) defer returnManaged(ptrManaged) if err = result(C.cudnnGetPoolingNdForwardOutputDim(p.internal, input.internal, C.int(dims), ptr)); err != nil { return nil, err } } return cloneShape(p.outputShape), nil }
[ "func", "(", "p", "*", "Pooling", ")", "CalcOutputShape", "(", "input", "*", "TensorDescriptor", ",", "dims", "int", ")", "(", "retVal", "[", "]", "int", ",", "err", "error", ")", "{", "p", ".", "outDims", "=", "dims", "\n", "p", ".", "inputTensor", "=", "cloneShape", "(", "input", ".", "shape", ")", "\n\n", "switch", "dims", "{", "case", "0", ":", "return", "nil", ",", "errors", ".", "Errorf", "(", "\"", "\"", ")", "\n", "case", "2", ":", "p", ".", "outputShape", "=", "make", "(", "[", "]", "int", ",", "4", ")", "\n", "n", ":=", "(", "*", "C", ".", "int", ")", "(", "unsafe", ".", "Pointer", "(", "&", "p", ".", "outputShape", "[", "0", "]", ")", ")", "\n", "c", ":=", "(", "*", "C", ".", "int", ")", "(", "unsafe", ".", "Pointer", "(", "&", "p", ".", "outputShape", "[", "1", "]", ")", ")", "\n", "h", ":=", "(", "*", "C", ".", "int", ")", "(", "unsafe", ".", "Pointer", "(", "&", "p", ".", "outputShape", "[", "2", "]", ")", ")", "\n", "w", ":=", "(", "*", "C", ".", "int", ")", "(", "unsafe", ".", "Pointer", "(", "&", "p", ".", "outputShape", "[", "3", "]", ")", ")", "\n", "if", "err", "=", "result", "(", "C", ".", "cudnnGetPooling2dForwardOutputDim", "(", "p", ".", "internal", ",", "input", ".", "internal", ",", "n", ",", "c", ",", "h", ",", "w", ")", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "default", ":", "p", ".", "outputShape", "=", "make", "(", "[", "]", "int", ",", "dims", ")", "\n", "ptr", ",", "ptrManaged", ":=", "ints2CIntPtr", "(", "p", ".", "outputShape", ")", "\n", "defer", "returnManaged", "(", "ptrManaged", ")", "\n", "if", "err", "=", "result", "(", "C", ".", "cudnnGetPoolingNdForwardOutputDim", "(", "p", ".", "internal", ",", "input", ".", "internal", ",", "C", ".", "int", "(", "dims", ")", ",", "ptr", ")", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "}", "\n", "return", "cloneShape", "(", "p", ".", "outputShape", ")", ",", "nil", "\n", "}" ]
// CalcOutputShape is like OutputShape, but doesn't go through a check for the cached value.
[ "CalcOutputShape", "is", "like", "OutputShape", "but", "doesn", "t", "go", "through", "a", "check", "for", "the", "cached", "value", "." ]
89152d7e441439045736bc7640ff607ec371c26c
https://github.com/gorgonia/cu/blob/89152d7e441439045736bc7640ff607ec371c26c/dnn/pooling.go#L103-L129
5,440
gorgonia/cu
dnn/generated_activation.go
NewActivation
func NewActivation(mode ActivationMode, reluNanOpt NanPropagation, coef float64) (retVal *Activation, err error) { var internal C.cudnnActivationDescriptor_t if err := result(C.cudnnCreateActivationDescriptor(&internal)); err != nil { return nil, err } if err := result(C.cudnnSetActivationDescriptor(internal, mode.C(), reluNanOpt.C(), C.double(coef))); err != nil { return nil, err } retVal = &Activation{ internal: internal, mode: mode, reluNanOpt: reluNanOpt, coef: coef, } runtime.SetFinalizer(retVal, destroyActivation) return retVal, nil }
go
func NewActivation(mode ActivationMode, reluNanOpt NanPropagation, coef float64) (retVal *Activation, err error) { var internal C.cudnnActivationDescriptor_t if err := result(C.cudnnCreateActivationDescriptor(&internal)); err != nil { return nil, err } if err := result(C.cudnnSetActivationDescriptor(internal, mode.C(), reluNanOpt.C(), C.double(coef))); err != nil { return nil, err } retVal = &Activation{ internal: internal, mode: mode, reluNanOpt: reluNanOpt, coef: coef, } runtime.SetFinalizer(retVal, destroyActivation) return retVal, nil }
[ "func", "NewActivation", "(", "mode", "ActivationMode", ",", "reluNanOpt", "NanPropagation", ",", "coef", "float64", ")", "(", "retVal", "*", "Activation", ",", "err", "error", ")", "{", "var", "internal", "C", ".", "cudnnActivationDescriptor_t", "\n", "if", "err", ":=", "result", "(", "C", ".", "cudnnCreateActivationDescriptor", "(", "&", "internal", ")", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "if", "err", ":=", "result", "(", "C", ".", "cudnnSetActivationDescriptor", "(", "internal", ",", "mode", ".", "C", "(", ")", ",", "reluNanOpt", ".", "C", "(", ")", ",", "C", ".", "double", "(", "coef", ")", ")", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "retVal", "=", "&", "Activation", "{", "internal", ":", "internal", ",", "mode", ":", "mode", ",", "reluNanOpt", ":", "reluNanOpt", ",", "coef", ":", "coef", ",", "}", "\n", "runtime", ".", "SetFinalizer", "(", "retVal", ",", "destroyActivation", ")", "\n", "return", "retVal", ",", "nil", "\n", "}" ]
// NewActivation creates a new Activation.
[ "NewActivation", "creates", "a", "new", "Activation", "." ]
89152d7e441439045736bc7640ff607ec371c26c
https://github.com/gorgonia/cu/blob/89152d7e441439045736bc7640ff607ec371c26c/dnn/generated_activation.go#L19-L37
5,441
gorgonia/cu
cucontext.go
Unlock
func (ctx CUContext) Unlock() error { if err := Synchronize(); err != nil { return err } runtime.UnlockOSThread() return nil }
go
func (ctx CUContext) Unlock() error { if err := Synchronize(); err != nil { return err } runtime.UnlockOSThread() return nil }
[ "func", "(", "ctx", "CUContext", ")", "Unlock", "(", ")", "error", "{", "if", "err", ":=", "Synchronize", "(", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "runtime", ".", "UnlockOSThread", "(", ")", "\n", "return", "nil", "\n", "}" ]
// Unlock unlocks unbinds the goroutine from the OS thread
[ "Unlock", "unlocks", "unbinds", "the", "goroutine", "from", "the", "OS", "thread" ]
89152d7e441439045736bc7640ff607ec371c26c
https://github.com/gorgonia/cu/blob/89152d7e441439045736bc7640ff607ec371c26c/cucontext.go#L57-L63
5,442
gorgonia/cu
dnn/generated_reduction.go
NewReduction
func NewReduction(reduceTensorOp ReduceTensorOp, reduceTensorCompType DataType, reduceTensorNanOpt NanPropagation, reduceTensorIndices ReduceTensorIndices, reduceTensorIndicesType IndicesType) (retVal *Reduction, err error) { var internal C.cudnnReduceTensorDescriptor_t if err := result(C.cudnnCreateReduceTensorDescriptor(&internal)); err != nil { return nil, err } if err := result(C.cudnnSetReduceTensorDescriptor(internal, reduceTensorOp.C(), reduceTensorCompType.C(), reduceTensorNanOpt.C(), reduceTensorIndices.C(), reduceTensorIndicesType.C())); err != nil { return nil, err } retVal = &Reduction{ internal: internal, reduceTensorOp: reduceTensorOp, reduceTensorCompType: reduceTensorCompType, reduceTensorNanOpt: reduceTensorNanOpt, reduceTensorIndices: reduceTensorIndices, reduceTensorIndicesType: reduceTensorIndicesType, } runtime.SetFinalizer(retVal, destroyReduction) return retVal, nil }
go
func NewReduction(reduceTensorOp ReduceTensorOp, reduceTensorCompType DataType, reduceTensorNanOpt NanPropagation, reduceTensorIndices ReduceTensorIndices, reduceTensorIndicesType IndicesType) (retVal *Reduction, err error) { var internal C.cudnnReduceTensorDescriptor_t if err := result(C.cudnnCreateReduceTensorDescriptor(&internal)); err != nil { return nil, err } if err := result(C.cudnnSetReduceTensorDescriptor(internal, reduceTensorOp.C(), reduceTensorCompType.C(), reduceTensorNanOpt.C(), reduceTensorIndices.C(), reduceTensorIndicesType.C())); err != nil { return nil, err } retVal = &Reduction{ internal: internal, reduceTensorOp: reduceTensorOp, reduceTensorCompType: reduceTensorCompType, reduceTensorNanOpt: reduceTensorNanOpt, reduceTensorIndices: reduceTensorIndices, reduceTensorIndicesType: reduceTensorIndicesType, } runtime.SetFinalizer(retVal, destroyReduction) return retVal, nil }
[ "func", "NewReduction", "(", "reduceTensorOp", "ReduceTensorOp", ",", "reduceTensorCompType", "DataType", ",", "reduceTensorNanOpt", "NanPropagation", ",", "reduceTensorIndices", "ReduceTensorIndices", ",", "reduceTensorIndicesType", "IndicesType", ")", "(", "retVal", "*", "Reduction", ",", "err", "error", ")", "{", "var", "internal", "C", ".", "cudnnReduceTensorDescriptor_t", "\n", "if", "err", ":=", "result", "(", "C", ".", "cudnnCreateReduceTensorDescriptor", "(", "&", "internal", ")", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "if", "err", ":=", "result", "(", "C", ".", "cudnnSetReduceTensorDescriptor", "(", "internal", ",", "reduceTensorOp", ".", "C", "(", ")", ",", "reduceTensorCompType", ".", "C", "(", ")", ",", "reduceTensorNanOpt", ".", "C", "(", ")", ",", "reduceTensorIndices", ".", "C", "(", ")", ",", "reduceTensorIndicesType", ".", "C", "(", ")", ")", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "retVal", "=", "&", "Reduction", "{", "internal", ":", "internal", ",", "reduceTensorOp", ":", "reduceTensorOp", ",", "reduceTensorCompType", ":", "reduceTensorCompType", ",", "reduceTensorNanOpt", ":", "reduceTensorNanOpt", ",", "reduceTensorIndices", ":", "reduceTensorIndices", ",", "reduceTensorIndicesType", ":", "reduceTensorIndicesType", ",", "}", "\n", "runtime", ".", "SetFinalizer", "(", "retVal", ",", "destroyReduction", ")", "\n", "return", "retVal", ",", "nil", "\n", "}" ]
// NewReduction creates a new Reduction.
[ "NewReduction", "creates", "a", "new", "Reduction", "." ]
89152d7e441439045736bc7640ff607ec371c26c
https://github.com/gorgonia/cu/blob/89152d7e441439045736bc7640ff607ec371c26c/dnn/generated_reduction.go#L21-L41
5,443
gorgonia/cu
cmd/gencudnn/conversion.go
FirstTensor
func (s GoSignature) FirstTensor() string { for _, p := range s.Params { if strings.Contains(p.Type, ctypes2GoTypes["cudnnTensorDescriptor_t"]) { return p.Name } } panic(fmt.Sprintf("No tensors to check in %v", s)) }
go
func (s GoSignature) FirstTensor() string { for _, p := range s.Params { if strings.Contains(p.Type, ctypes2GoTypes["cudnnTensorDescriptor_t"]) { return p.Name } } panic(fmt.Sprintf("No tensors to check in %v", s)) }
[ "func", "(", "s", "GoSignature", ")", "FirstTensor", "(", ")", "string", "{", "for", "_", ",", "p", ":=", "range", "s", ".", "Params", "{", "if", "strings", ".", "Contains", "(", "p", ".", "Type", ",", "ctypes2GoTypes", "[", "\"", "\"", "]", ")", "{", "return", "p", ".", "Name", "\n", "}", "\n", "}", "\n", "panic", "(", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "s", ")", ")", "\n", "}" ]
// FirstTensor finds the first tensor parameter of the function and returns the name
[ "FirstTensor", "finds", "the", "first", "tensor", "parameter", "of", "the", "function", "and", "returns", "the", "name" ]
89152d7e441439045736bc7640ff607ec371c26c
https://github.com/gorgonia/cu/blob/89152d7e441439045736bc7640ff607ec371c26c/cmd/gencudnn/conversion.go#L79-L86
5,444
gorgonia/cu
blas/blas.go
Isamax
func (impl *Standard) Isamax(n int, x []float32, incX int) (retVal int) { // declared at cublasgen.h:384:17 enum CUBLAS_STATUS { ... } cublasIsamax ... if impl.e != nil { return } if n < 0 { panic("blas: n < 0") } if incX == 0 { panic("blas: zero x index increment") } if n == 0 || incX < 0 { return -1 } if incX > 0 && (n-1)*incX >= len(x) { panic("blas: x index out of range") } if n == 0 { return } var ret C.int impl.e = status(C.cublasIsamax(C.cublasHandle_t(impl.h), C.int(n), (*C.float)(&x[0]), C.int(incX), &ret)) return int(ret) }
go
func (impl *Standard) Isamax(n int, x []float32, incX int) (retVal int) { // declared at cublasgen.h:384:17 enum CUBLAS_STATUS { ... } cublasIsamax ... if impl.e != nil { return } if n < 0 { panic("blas: n < 0") } if incX == 0 { panic("blas: zero x index increment") } if n == 0 || incX < 0 { return -1 } if incX > 0 && (n-1)*incX >= len(x) { panic("blas: x index out of range") } if n == 0 { return } var ret C.int impl.e = status(C.cublasIsamax(C.cublasHandle_t(impl.h), C.int(n), (*C.float)(&x[0]), C.int(incX), &ret)) return int(ret) }
[ "func", "(", "impl", "*", "Standard", ")", "Isamax", "(", "n", "int", ",", "x", "[", "]", "float32", ",", "incX", "int", ")", "(", "retVal", "int", ")", "{", "// declared at cublasgen.h:384:17 enum CUBLAS_STATUS { ... } cublasIsamax ...", "if", "impl", ".", "e", "!=", "nil", "{", "return", "\n", "}", "\n\n", "if", "n", "<", "0", "{", "panic", "(", "\"", "\"", ")", "\n", "}", "\n", "if", "incX", "==", "0", "{", "panic", "(", "\"", "\"", ")", "\n", "}", "\n", "if", "n", "==", "0", "||", "incX", "<", "0", "{", "return", "-", "1", "\n", "}", "\n", "if", "incX", ">", "0", "&&", "(", "n", "-", "1", ")", "*", "incX", ">=", "len", "(", "x", ")", "{", "panic", "(", "\"", "\"", ")", "\n", "}", "\n", "if", "n", "==", "0", "{", "return", "\n", "}", "\n", "var", "ret", "C", ".", "int", "\n", "impl", ".", "e", "=", "status", "(", "C", ".", "cublasIsamax", "(", "C", ".", "cublasHandle_t", "(", "impl", ".", "h", ")", ",", "C", ".", "int", "(", "n", ")", ",", "(", "*", "C", ".", "float", ")", "(", "&", "x", "[", "0", "]", ")", ",", "C", ".", "int", "(", "incX", ")", ",", "&", "ret", ")", ")", "\n", "return", "int", "(", "ret", ")", "\n", "}" ]
// Isamax returns the index of an element of x with the largest absolute value. // If there are multiple such indices the earliest is returned. // Isamax returns -1 if n == 0.
[ "Isamax", "returns", "the", "index", "of", "an", "element", "of", "x", "with", "the", "largest", "absolute", "value", ".", "If", "there", "are", "multiple", "such", "indices", "the", "earliest", "is", "returned", ".", "Isamax", "returns", "-", "1", "if", "n", "==", "0", "." ]
89152d7e441439045736bc7640ff607ec371c26c
https://github.com/gorgonia/cu/blob/89152d7e441439045736bc7640ff607ec371c26c/blas/blas.go#L911-L935
5,445
gorgonia/cu
blas/blas.go
Idamax
func (impl *Standard) Idamax(n int, x []float64, incX int) (retVal int) { // declared at cublasgen.h:390:17 enum CUBLAS_STATUS { ... } cublasIdamax ... if impl.e != nil { return } if n < 0 { panic("blas: n < 0") } if incX == 0 { panic("blas: zero x index increment") } if n == 0 || incX < 0 { return -1 } if incX > 0 && (n-1)*incX >= len(x) { panic("blas: x index out of range") } if n == 0 { return } var ret C.int impl.e = status(C.cublasIdamax(C.cublasHandle_t(impl.h), C.int(n), (*C.double)(&x[0]), C.int(incX), &ret)) return int(ret) }
go
func (impl *Standard) Idamax(n int, x []float64, incX int) (retVal int) { // declared at cublasgen.h:390:17 enum CUBLAS_STATUS { ... } cublasIdamax ... if impl.e != nil { return } if n < 0 { panic("blas: n < 0") } if incX == 0 { panic("blas: zero x index increment") } if n == 0 || incX < 0 { return -1 } if incX > 0 && (n-1)*incX >= len(x) { panic("blas: x index out of range") } if n == 0 { return } var ret C.int impl.e = status(C.cublasIdamax(C.cublasHandle_t(impl.h), C.int(n), (*C.double)(&x[0]), C.int(incX), &ret)) return int(ret) }
[ "func", "(", "impl", "*", "Standard", ")", "Idamax", "(", "n", "int", ",", "x", "[", "]", "float64", ",", "incX", "int", ")", "(", "retVal", "int", ")", "{", "// declared at cublasgen.h:390:17 enum CUBLAS_STATUS { ... } cublasIdamax ...", "if", "impl", ".", "e", "!=", "nil", "{", "return", "\n", "}", "\n\n", "if", "n", "<", "0", "{", "panic", "(", "\"", "\"", ")", "\n", "}", "\n", "if", "incX", "==", "0", "{", "panic", "(", "\"", "\"", ")", "\n", "}", "\n", "if", "n", "==", "0", "||", "incX", "<", "0", "{", "return", "-", "1", "\n", "}", "\n", "if", "incX", ">", "0", "&&", "(", "n", "-", "1", ")", "*", "incX", ">=", "len", "(", "x", ")", "{", "panic", "(", "\"", "\"", ")", "\n", "}", "\n", "if", "n", "==", "0", "{", "return", "\n", "}", "\n", "var", "ret", "C", ".", "int", "\n", "impl", ".", "e", "=", "status", "(", "C", ".", "cublasIdamax", "(", "C", ".", "cublasHandle_t", "(", "impl", ".", "h", ")", ",", "C", ".", "int", "(", "n", ")", ",", "(", "*", "C", ".", "double", ")", "(", "&", "x", "[", "0", "]", ")", ",", "C", ".", "int", "(", "incX", ")", ",", "&", "ret", ")", ")", "\n", "return", "int", "(", "ret", ")", "\n", "}" ]
// Idamax returns the index of an element of x with the largest absolute value. // If there are multiple such indices the earliest is returned. // Idamax returns -1 if n == 0.
[ "Idamax", "returns", "the", "index", "of", "an", "element", "of", "x", "with", "the", "largest", "absolute", "value", ".", "If", "there", "are", "multiple", "such", "indices", "the", "earliest", "is", "returned", ".", "Idamax", "returns", "-", "1", "if", "n", "==", "0", "." ]
89152d7e441439045736bc7640ff607ec371c26c
https://github.com/gorgonia/cu/blob/89152d7e441439045736bc7640ff607ec371c26c/blas/blas.go#L940-L964
5,446
gorgonia/cu
dnn/handle.go
NewContext
func NewContext() (retVal *Context) { var internal C.cudnnHandle_t if err := result(C.cudnnCreate(&internal)); err != nil { panic(err) } retVal = &Context{internal} return retVal }
go
func NewContext() (retVal *Context) { var internal C.cudnnHandle_t if err := result(C.cudnnCreate(&internal)); err != nil { panic(err) } retVal = &Context{internal} return retVal }
[ "func", "NewContext", "(", ")", "(", "retVal", "*", "Context", ")", "{", "var", "internal", "C", ".", "cudnnHandle_t", "\n", "if", "err", ":=", "result", "(", "C", ".", "cudnnCreate", "(", "&", "internal", ")", ")", ";", "err", "!=", "nil", "{", "panic", "(", "err", ")", "\n", "}", "\n", "retVal", "=", "&", "Context", "{", "internal", "}", "\n", "return", "retVal", "\n", "}" ]
// NewContext creates a new Context. This is the only function that will panic if it is unable to create the context.
[ "NewContext", "creates", "a", "new", "Context", ".", "This", "is", "the", "only", "function", "that", "will", "panic", "if", "it", "is", "unable", "to", "create", "the", "context", "." ]
89152d7e441439045736bc7640ff607ec371c26c
https://github.com/gorgonia/cu/blob/89152d7e441439045736bc7640ff607ec371c26c/dnn/handle.go#L27-L34
5,447
gorgonia/cu
dnn/handle.go
Close
func (ctx *Context) Close() error { var empty C.cudnnHandle_t if ctx.internal == empty { return nil } if err := result(C.cudnnDestroy(ctx.internal)); err != nil { return err } ctx.internal = empty return nil }
go
func (ctx *Context) Close() error { var empty C.cudnnHandle_t if ctx.internal == empty { return nil } if err := result(C.cudnnDestroy(ctx.internal)); err != nil { return err } ctx.internal = empty return nil }
[ "func", "(", "ctx", "*", "Context", ")", "Close", "(", ")", "error", "{", "var", "empty", "C", ".", "cudnnHandle_t", "\n", "if", "ctx", ".", "internal", "==", "empty", "{", "return", "nil", "\n", "}", "\n\n", "if", "err", ":=", "result", "(", "C", ".", "cudnnDestroy", "(", "ctx", ".", "internal", ")", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "ctx", ".", "internal", "=", "empty", "\n", "return", "nil", "\n", "}" ]
// Close destroys the underlying context.
[ "Close", "destroys", "the", "underlying", "context", "." ]
89152d7e441439045736bc7640ff607ec371c26c
https://github.com/gorgonia/cu/blob/89152d7e441439045736bc7640ff607ec371c26c/dnn/handle.go#L37-L48
5,448
gorgonia/cu
dnn/generated_API.go
RestoreDropoutDescriptor
func (dr *Dropout) RestoreDropoutDescriptor(handle *Context, dropout float32, states Memory, stateSizeInBytes uintptr, seed uint64) error { // call cudnnRestoreDropoutDescriptor return result(C.cudnnRestoreDropoutDescriptor(dr.internal, handle.internal, C.float(dropout), states.Pointer(), C.size_t(stateSizeInBytes), C.ulonglong(seed))) }
go
func (dr *Dropout) RestoreDropoutDescriptor(handle *Context, dropout float32, states Memory, stateSizeInBytes uintptr, seed uint64) error { // call cudnnRestoreDropoutDescriptor return result(C.cudnnRestoreDropoutDescriptor(dr.internal, handle.internal, C.float(dropout), states.Pointer(), C.size_t(stateSizeInBytes), C.ulonglong(seed))) }
[ "func", "(", "dr", "*", "Dropout", ")", "RestoreDropoutDescriptor", "(", "handle", "*", "Context", ",", "dropout", "float32", ",", "states", "Memory", ",", "stateSizeInBytes", "uintptr", ",", "seed", "uint64", ")", "error", "{", "// call cudnnRestoreDropoutDescriptor", "return", "result", "(", "C", ".", "cudnnRestoreDropoutDescriptor", "(", "dr", ".", "internal", ",", "handle", ".", "internal", ",", "C", ".", "float", "(", "dropout", ")", ",", "states", ".", "Pointer", "(", ")", ",", "C", ".", "size_t", "(", "stateSizeInBytes", ")", ",", "C", ".", "ulonglong", "(", "seed", ")", ")", ")", "\n", "}" ]
// RestoreDropoutDescriptor restores a dropout descriptor to a previously saved-off state.
[ "RestoreDropoutDescriptor", "restores", "a", "dropout", "descriptor", "to", "a", "previously", "saved", "-", "off", "state", "." ]
89152d7e441439045736bc7640ff607ec371c26c
https://github.com/gorgonia/cu/blob/89152d7e441439045736bc7640ff607ec371c26c/dnn/generated_API.go#L14-L17
5,449
gorgonia/cu
dnn/generated_API.go
AddTensor
func (co *Context) AddTensor(alpha float64, aDesc *TensorDescriptor, A Memory, beta float64, cDesc *TensorDescriptor, C_ Memory) error { var alphaC, betaC unsafe.Pointer switch aDesc.dataType { case Float, Half: var alphaF, betaF C.float alphaF = C.float(float32(alpha)) betaF = C.float(float32(beta)) alphaC = unsafe.Pointer(&alphaF) betaC = unsafe.Pointer(&betaF) case Double: var alphaF, betaF C.double alphaF = C.double(alpha) betaF = C.double(beta) alphaC = unsafe.Pointer(&alphaF) betaC = unsafe.Pointer(&betaF) default: return errors.Errorf("Unsupported data type: %v", aDesc.dataType) } // call cudnnAddTensor return result(C.cudnnAddTensor(co.internal, alphaC, aDesc.internal, A.Pointer(), betaC, cDesc.internal, C_.Pointer())) }
go
func (co *Context) AddTensor(alpha float64, aDesc *TensorDescriptor, A Memory, beta float64, cDesc *TensorDescriptor, C_ Memory) error { var alphaC, betaC unsafe.Pointer switch aDesc.dataType { case Float, Half: var alphaF, betaF C.float alphaF = C.float(float32(alpha)) betaF = C.float(float32(beta)) alphaC = unsafe.Pointer(&alphaF) betaC = unsafe.Pointer(&betaF) case Double: var alphaF, betaF C.double alphaF = C.double(alpha) betaF = C.double(beta) alphaC = unsafe.Pointer(&alphaF) betaC = unsafe.Pointer(&betaF) default: return errors.Errorf("Unsupported data type: %v", aDesc.dataType) } // call cudnnAddTensor return result(C.cudnnAddTensor(co.internal, alphaC, aDesc.internal, A.Pointer(), betaC, cDesc.internal, C_.Pointer())) }
[ "func", "(", "co", "*", "Context", ")", "AddTensor", "(", "alpha", "float64", ",", "aDesc", "*", "TensorDescriptor", ",", "A", "Memory", ",", "beta", "float64", ",", "cDesc", "*", "TensorDescriptor", ",", "C_", "Memory", ")", "error", "{", "var", "alphaC", ",", "betaC", "unsafe", ".", "Pointer", "\n", "switch", "aDesc", ".", "dataType", "{", "case", "Float", ",", "Half", ":", "var", "alphaF", ",", "betaF", "C", ".", "float", "\n", "alphaF", "=", "C", ".", "float", "(", "float32", "(", "alpha", ")", ")", "\n", "betaF", "=", "C", ".", "float", "(", "float32", "(", "beta", ")", ")", "\n", "alphaC", "=", "unsafe", ".", "Pointer", "(", "&", "alphaF", ")", "\n", "betaC", "=", "unsafe", ".", "Pointer", "(", "&", "betaF", ")", "\n", "case", "Double", ":", "var", "alphaF", ",", "betaF", "C", ".", "double", "\n", "alphaF", "=", "C", ".", "double", "(", "alpha", ")", "\n", "betaF", "=", "C", ".", "double", "(", "beta", ")", "\n", "alphaC", "=", "unsafe", ".", "Pointer", "(", "&", "alphaF", ")", "\n", "betaC", "=", "unsafe", ".", "Pointer", "(", "&", "betaF", ")", "\n", "default", ":", "return", "errors", ".", "Errorf", "(", "\"", "\"", ",", "aDesc", ".", "dataType", ")", "\n", "}", "\n", "// call cudnnAddTensor", "return", "result", "(", "C", ".", "cudnnAddTensor", "(", "co", ".", "internal", ",", "alphaC", ",", "aDesc", ".", "internal", ",", "A", ".", "Pointer", "(", ")", ",", "betaC", ",", "cDesc", ".", "internal", ",", "C_", ".", "Pointer", "(", ")", ")", ")", "\n", "}" ]
// AddTensor adds the scaled values of a bias tensor to another tensor. Each dimension of the bias tensor A must match the corresponding dimension of the destination tensor C or must be equal to 1. In the latter case, the same value from the bias tensor for those dimensions will be used to blend into the C tensor. // C_ is both an input and output
[ "AddTensor", "adds", "the", "scaled", "values", "of", "a", "bias", "tensor", "to", "another", "tensor", ".", "Each", "dimension", "of", "the", "bias", "tensor", "A", "must", "match", "the", "corresponding", "dimension", "of", "the", "destination", "tensor", "C", "or", "must", "be", "equal", "to", "1", ".", "In", "the", "latter", "case", "the", "same", "value", "from", "the", "bias", "tensor", "for", "those", "dimensions", "will", "be", "used", "to", "blend", "into", "the", "C", "tensor", ".", "C_", "is", "both", "an", "input", "and", "output" ]
89152d7e441439045736bc7640ff607ec371c26c
https://github.com/gorgonia/cu/blob/89152d7e441439045736bc7640ff607ec371c26c/dnn/generated_API.go#L53-L73
5,450
gorgonia/cu
dnn/generated_API.go
GetReductionIndicesSize
func (co *Context) GetReductionIndicesSize(reduceTensorDesc *Reduction, aDesc *TensorDescriptor, cDesc *TensorDescriptor) (sizeInBytes uintptr, err error) { var sizeInBytesC C.size_t // call cudnnGetReductionIndicesSize err = result(C.cudnnGetReductionIndicesSize(co.internal, reduceTensorDesc.internal, aDesc.internal, cDesc.internal, &sizeInBytesC)) sizeInBytes = uintptr(sizeInBytesC) return }
go
func (co *Context) GetReductionIndicesSize(reduceTensorDesc *Reduction, aDesc *TensorDescriptor, cDesc *TensorDescriptor) (sizeInBytes uintptr, err error) { var sizeInBytesC C.size_t // call cudnnGetReductionIndicesSize err = result(C.cudnnGetReductionIndicesSize(co.internal, reduceTensorDesc.internal, aDesc.internal, cDesc.internal, &sizeInBytesC)) sizeInBytes = uintptr(sizeInBytesC) return }
[ "func", "(", "co", "*", "Context", ")", "GetReductionIndicesSize", "(", "reduceTensorDesc", "*", "Reduction", ",", "aDesc", "*", "TensorDescriptor", ",", "cDesc", "*", "TensorDescriptor", ")", "(", "sizeInBytes", "uintptr", ",", "err", "error", ")", "{", "var", "sizeInBytesC", "C", ".", "size_t", "\n", "// call cudnnGetReductionIndicesSize", "err", "=", "result", "(", "C", ".", "cudnnGetReductionIndicesSize", "(", "co", ".", "internal", ",", "reduceTensorDesc", ".", "internal", ",", "aDesc", ".", "internal", ",", "cDesc", ".", "internal", ",", "&", "sizeInBytesC", ")", ")", "\n", "sizeInBytes", "=", "uintptr", "(", "sizeInBytesC", ")", "\n", "return", "\n", "}" ]
// GetReductionIndicesSize is a helper function to return the minimum size of the index space to be passed to the reduction given the input and output tensors.
[ "GetReductionIndicesSize", "is", "a", "helper", "function", "to", "return", "the", "minimum", "size", "of", "the", "index", "space", "to", "be", "passed", "to", "the", "reduction", "given", "the", "input", "and", "output", "tensors", "." ]
89152d7e441439045736bc7640ff607ec371c26c
https://github.com/gorgonia/cu/blob/89152d7e441439045736bc7640ff607ec371c26c/dnn/generated_API.go#L104-L110
5,451
gorgonia/cu
dnn/generated_API.go
ScaleTensor
func (co *Context) ScaleTensor(yDesc *TensorDescriptor, y Memory, alpha float64) error { var alphaC unsafe.Pointer switch yDesc.dataType { case Float, Half: var alphaF C.float alphaF = C.float(float32(alpha)) alphaC = unsafe.Pointer(&alphaF) case Double: var alphaF C.double alphaF = C.double(alpha) alphaC = unsafe.Pointer(&alphaF) default: return errors.Errorf("Unsupported data type: %v", yDesc.dataType) } // call cudnnScaleTensor return result(C.cudnnScaleTensor(co.internal, yDesc.internal, y.Pointer(), alphaC)) }
go
func (co *Context) ScaleTensor(yDesc *TensorDescriptor, y Memory, alpha float64) error { var alphaC unsafe.Pointer switch yDesc.dataType { case Float, Half: var alphaF C.float alphaF = C.float(float32(alpha)) alphaC = unsafe.Pointer(&alphaF) case Double: var alphaF C.double alphaF = C.double(alpha) alphaC = unsafe.Pointer(&alphaF) default: return errors.Errorf("Unsupported data type: %v", yDesc.dataType) } // call cudnnScaleTensor return result(C.cudnnScaleTensor(co.internal, yDesc.internal, y.Pointer(), alphaC)) }
[ "func", "(", "co", "*", "Context", ")", "ScaleTensor", "(", "yDesc", "*", "TensorDescriptor", ",", "y", "Memory", ",", "alpha", "float64", ")", "error", "{", "var", "alphaC", "unsafe", ".", "Pointer", "\n", "switch", "yDesc", ".", "dataType", "{", "case", "Float", ",", "Half", ":", "var", "alphaF", "C", ".", "float", "\n", "alphaF", "=", "C", ".", "float", "(", "float32", "(", "alpha", ")", ")", "\n", "alphaC", "=", "unsafe", ".", "Pointer", "(", "&", "alphaF", ")", "\n", "case", "Double", ":", "var", "alphaF", "C", ".", "double", "\n", "alphaF", "=", "C", ".", "double", "(", "alpha", ")", "\n", "alphaC", "=", "unsafe", ".", "Pointer", "(", "&", "alphaF", ")", "\n", "default", ":", "return", "errors", ".", "Errorf", "(", "\"", "\"", ",", "yDesc", ".", "dataType", ")", "\n", "}", "\n", "// call cudnnScaleTensor", "return", "result", "(", "C", ".", "cudnnScaleTensor", "(", "co", ".", "internal", ",", "yDesc", ".", "internal", ",", "y", ".", "Pointer", "(", ")", ",", "alphaC", ")", ")", "\n", "}" ]
// ScaleTensor scale all the elements of a tensor by a given factor. // y is both an input and output
[ "ScaleTensor", "scale", "all", "the", "elements", "of", "a", "tensor", "by", "a", "given", "factor", ".", "y", "is", "both", "an", "input", "and", "output" ]
89152d7e441439045736bc7640ff607ec371c26c
https://github.com/gorgonia/cu/blob/89152d7e441439045736bc7640ff607ec371c26c/dnn/generated_API.go#L148-L164
5,452
gorgonia/cu
dnn/generated_API.go
ConvolutionBackwardBias
func (co *Context) ConvolutionBackwardBias(alpha float64, dyDesc *TensorDescriptor, dy Memory, beta float64, dbDesc *TensorDescriptor, db Memory) error { // DOUBLECHECK: "cudnnConvolutionBackwardBias" returns Memory type in Parameter 6 var alphaC, betaC unsafe.Pointer switch dyDesc.dataType { case Float, Half: var alphaF, betaF C.float alphaF = C.float(float32(alpha)) betaF = C.float(float32(beta)) alphaC = unsafe.Pointer(&alphaF) betaC = unsafe.Pointer(&betaF) case Double: var alphaF, betaF C.double alphaF = C.double(alpha) betaF = C.double(beta) alphaC = unsafe.Pointer(&alphaF) betaC = unsafe.Pointer(&betaF) default: return errors.Errorf("Unsupported data type: %v", dyDesc.dataType) } // call cudnnConvolutionBackwardBias return result(C.cudnnConvolutionBackwardBias(co.internal, alphaC, dyDesc.internal, dy.Pointer(), betaC, dbDesc.internal, db.Pointer())) }
go
func (co *Context) ConvolutionBackwardBias(alpha float64, dyDesc *TensorDescriptor, dy Memory, beta float64, dbDesc *TensorDescriptor, db Memory) error { // DOUBLECHECK: "cudnnConvolutionBackwardBias" returns Memory type in Parameter 6 var alphaC, betaC unsafe.Pointer switch dyDesc.dataType { case Float, Half: var alphaF, betaF C.float alphaF = C.float(float32(alpha)) betaF = C.float(float32(beta)) alphaC = unsafe.Pointer(&alphaF) betaC = unsafe.Pointer(&betaF) case Double: var alphaF, betaF C.double alphaF = C.double(alpha) betaF = C.double(beta) alphaC = unsafe.Pointer(&alphaF) betaC = unsafe.Pointer(&betaF) default: return errors.Errorf("Unsupported data type: %v", dyDesc.dataType) } // call cudnnConvolutionBackwardBias return result(C.cudnnConvolutionBackwardBias(co.internal, alphaC, dyDesc.internal, dy.Pointer(), betaC, dbDesc.internal, db.Pointer())) }
[ "func", "(", "co", "*", "Context", ")", "ConvolutionBackwardBias", "(", "alpha", "float64", ",", "dyDesc", "*", "TensorDescriptor", ",", "dy", "Memory", ",", "beta", "float64", ",", "dbDesc", "*", "TensorDescriptor", ",", "db", "Memory", ")", "error", "{", "// DOUBLECHECK: \"cudnnConvolutionBackwardBias\" returns Memory type in Parameter 6", "var", "alphaC", ",", "betaC", "unsafe", ".", "Pointer", "\n", "switch", "dyDesc", ".", "dataType", "{", "case", "Float", ",", "Half", ":", "var", "alphaF", ",", "betaF", "C", ".", "float", "\n", "alphaF", "=", "C", ".", "float", "(", "float32", "(", "alpha", ")", ")", "\n", "betaF", "=", "C", ".", "float", "(", "float32", "(", "beta", ")", ")", "\n", "alphaC", "=", "unsafe", ".", "Pointer", "(", "&", "alphaF", ")", "\n", "betaC", "=", "unsafe", ".", "Pointer", "(", "&", "betaF", ")", "\n", "case", "Double", ":", "var", "alphaF", ",", "betaF", "C", ".", "double", "\n", "alphaF", "=", "C", ".", "double", "(", "alpha", ")", "\n", "betaF", "=", "C", ".", "double", "(", "beta", ")", "\n", "alphaC", "=", "unsafe", ".", "Pointer", "(", "&", "alphaF", ")", "\n", "betaC", "=", "unsafe", ".", "Pointer", "(", "&", "betaF", ")", "\n", "default", ":", "return", "errors", ".", "Errorf", "(", "\"", "\"", ",", "dyDesc", ".", "dataType", ")", "\n", "}", "\n", "// call cudnnConvolutionBackwardBias", "return", "result", "(", "C", ".", "cudnnConvolutionBackwardBias", "(", "co", ".", "internal", ",", "alphaC", ",", "dyDesc", ".", "internal", ",", "dy", ".", "Pointer", "(", ")", ",", "betaC", ",", "dbDesc", ".", "internal", ",", "db", ".", "Pointer", "(", ")", ")", ")", "\n", "}" ]
// ConvolutionBackwardBias computes the convolution function gradient with respect to the bias, which is the sum of every element belonging to the same feature map across all of the images of the input tensor. Therefore, the number of elements produced is equal to the number of features maps of the input tensor.
[ "ConvolutionBackwardBias", "computes", "the", "convolution", "function", "gradient", "with", "respect", "to", "the", "bias", "which", "is", "the", "sum", "of", "every", "element", "belonging", "to", "the", "same", "feature", "map", "across", "all", "of", "the", "images", "of", "the", "input", "tensor", ".", "Therefore", "the", "number", "of", "elements", "produced", "is", "equal", "to", "the", "number", "of", "features", "maps", "of", "the", "input", "tensor", "." ]
89152d7e441439045736bc7640ff607ec371c26c
https://github.com/gorgonia/cu/blob/89152d7e441439045736bc7640ff607ec371c26c/dnn/generated_API.go#L237-L258
5,453
gorgonia/cu
dnn/generated_API.go
SoftmaxForward
func (co *Context) SoftmaxForward(algo SoftmaxAlgorithm, mode SoftmaxMode, alpha float64, xDesc *TensorDescriptor, x Memory, beta float64, yDesc *TensorDescriptor, y Memory) error { // DOUBLECHECK: "cudnnSoftmaxForward" returns Memory type in Parameter 8 var alphaC, betaC unsafe.Pointer switch xDesc.dataType { case Float, Half: var alphaF, betaF C.float alphaF = C.float(float32(alpha)) betaF = C.float(float32(beta)) alphaC = unsafe.Pointer(&alphaF) betaC = unsafe.Pointer(&betaF) case Double: var alphaF, betaF C.double alphaF = C.double(alpha) betaF = C.double(beta) alphaC = unsafe.Pointer(&alphaF) betaC = unsafe.Pointer(&betaF) default: return errors.Errorf("Unsupported data type: %v", xDesc.dataType) } // call cudnnSoftmaxForward return result(C.cudnnSoftmaxForward(co.internal, algo.C(), mode.C(), alphaC, xDesc.internal, x.Pointer(), betaC, yDesc.internal, y.Pointer())) }
go
func (co *Context) SoftmaxForward(algo SoftmaxAlgorithm, mode SoftmaxMode, alpha float64, xDesc *TensorDescriptor, x Memory, beta float64, yDesc *TensorDescriptor, y Memory) error { // DOUBLECHECK: "cudnnSoftmaxForward" returns Memory type in Parameter 8 var alphaC, betaC unsafe.Pointer switch xDesc.dataType { case Float, Half: var alphaF, betaF C.float alphaF = C.float(float32(alpha)) betaF = C.float(float32(beta)) alphaC = unsafe.Pointer(&alphaF) betaC = unsafe.Pointer(&betaF) case Double: var alphaF, betaF C.double alphaF = C.double(alpha) betaF = C.double(beta) alphaC = unsafe.Pointer(&alphaF) betaC = unsafe.Pointer(&betaF) default: return errors.Errorf("Unsupported data type: %v", xDesc.dataType) } // call cudnnSoftmaxForward return result(C.cudnnSoftmaxForward(co.internal, algo.C(), mode.C(), alphaC, xDesc.internal, x.Pointer(), betaC, yDesc.internal, y.Pointer())) }
[ "func", "(", "co", "*", "Context", ")", "SoftmaxForward", "(", "algo", "SoftmaxAlgorithm", ",", "mode", "SoftmaxMode", ",", "alpha", "float64", ",", "xDesc", "*", "TensorDescriptor", ",", "x", "Memory", ",", "beta", "float64", ",", "yDesc", "*", "TensorDescriptor", ",", "y", "Memory", ")", "error", "{", "// DOUBLECHECK: \"cudnnSoftmaxForward\" returns Memory type in Parameter 8", "var", "alphaC", ",", "betaC", "unsafe", ".", "Pointer", "\n", "switch", "xDesc", ".", "dataType", "{", "case", "Float", ",", "Half", ":", "var", "alphaF", ",", "betaF", "C", ".", "float", "\n", "alphaF", "=", "C", ".", "float", "(", "float32", "(", "alpha", ")", ")", "\n", "betaF", "=", "C", ".", "float", "(", "float32", "(", "beta", ")", ")", "\n", "alphaC", "=", "unsafe", ".", "Pointer", "(", "&", "alphaF", ")", "\n", "betaC", "=", "unsafe", ".", "Pointer", "(", "&", "betaF", ")", "\n", "case", "Double", ":", "var", "alphaF", ",", "betaF", "C", ".", "double", "\n", "alphaF", "=", "C", ".", "double", "(", "alpha", ")", "\n", "betaF", "=", "C", ".", "double", "(", "beta", ")", "\n", "alphaC", "=", "unsafe", ".", "Pointer", "(", "&", "alphaF", ")", "\n", "betaC", "=", "unsafe", ".", "Pointer", "(", "&", "betaF", ")", "\n", "default", ":", "return", "errors", ".", "Errorf", "(", "\"", "\"", ",", "xDesc", ".", "dataType", ")", "\n", "}", "\n", "// call cudnnSoftmaxForward", "return", "result", "(", "C", ".", "cudnnSoftmaxForward", "(", "co", ".", "internal", ",", "algo", ".", "C", "(", ")", ",", "mode", ".", "C", "(", ")", ",", "alphaC", ",", "xDesc", ".", "internal", ",", "x", ".", "Pointer", "(", ")", ",", "betaC", ",", "yDesc", ".", "internal", ",", "y", ".", "Pointer", "(", ")", ")", ")", "\n", "}" ]
// SoftmaxForward computes the softmax function.
[ "SoftmaxForward", "computes", "the", "softmax", "function", "." ]
89152d7e441439045736bc7640ff607ec371c26c
https://github.com/gorgonia/cu/blob/89152d7e441439045736bc7640ff607ec371c26c/dnn/generated_API.go#L358-L379
5,454
gorgonia/cu
dnn/generated_API.go
SoftmaxBackward
func (co *Context) SoftmaxBackward(algo SoftmaxAlgorithm, mode SoftmaxMode, alpha float64, yDesc *TensorDescriptor, y Memory, dyDesc *TensorDescriptor, dy Memory, beta float64, dxDesc *TensorDescriptor, dx Memory) error { // DOUBLECHECK: "cudnnSoftmaxBackward" returns Memory type in Parameter 10 var alphaC, betaC unsafe.Pointer switch yDesc.dataType { case Float, Half: var alphaF, betaF C.float alphaF = C.float(float32(alpha)) betaF = C.float(float32(beta)) alphaC = unsafe.Pointer(&alphaF) betaC = unsafe.Pointer(&betaF) case Double: var alphaF, betaF C.double alphaF = C.double(alpha) betaF = C.double(beta) alphaC = unsafe.Pointer(&alphaF) betaC = unsafe.Pointer(&betaF) default: return errors.Errorf("Unsupported data type: %v", yDesc.dataType) } // call cudnnSoftmaxBackward return result(C.cudnnSoftmaxBackward(co.internal, algo.C(), mode.C(), alphaC, yDesc.internal, y.Pointer(), dyDesc.internal, dy.Pointer(), betaC, dxDesc.internal, dx.Pointer())) }
go
func (co *Context) SoftmaxBackward(algo SoftmaxAlgorithm, mode SoftmaxMode, alpha float64, yDesc *TensorDescriptor, y Memory, dyDesc *TensorDescriptor, dy Memory, beta float64, dxDesc *TensorDescriptor, dx Memory) error { // DOUBLECHECK: "cudnnSoftmaxBackward" returns Memory type in Parameter 10 var alphaC, betaC unsafe.Pointer switch yDesc.dataType { case Float, Half: var alphaF, betaF C.float alphaF = C.float(float32(alpha)) betaF = C.float(float32(beta)) alphaC = unsafe.Pointer(&alphaF) betaC = unsafe.Pointer(&betaF) case Double: var alphaF, betaF C.double alphaF = C.double(alpha) betaF = C.double(beta) alphaC = unsafe.Pointer(&alphaF) betaC = unsafe.Pointer(&betaF) default: return errors.Errorf("Unsupported data type: %v", yDesc.dataType) } // call cudnnSoftmaxBackward return result(C.cudnnSoftmaxBackward(co.internal, algo.C(), mode.C(), alphaC, yDesc.internal, y.Pointer(), dyDesc.internal, dy.Pointer(), betaC, dxDesc.internal, dx.Pointer())) }
[ "func", "(", "co", "*", "Context", ")", "SoftmaxBackward", "(", "algo", "SoftmaxAlgorithm", ",", "mode", "SoftmaxMode", ",", "alpha", "float64", ",", "yDesc", "*", "TensorDescriptor", ",", "y", "Memory", ",", "dyDesc", "*", "TensorDescriptor", ",", "dy", "Memory", ",", "beta", "float64", ",", "dxDesc", "*", "TensorDescriptor", ",", "dx", "Memory", ")", "error", "{", "// DOUBLECHECK: \"cudnnSoftmaxBackward\" returns Memory type in Parameter 10", "var", "alphaC", ",", "betaC", "unsafe", ".", "Pointer", "\n", "switch", "yDesc", ".", "dataType", "{", "case", "Float", ",", "Half", ":", "var", "alphaF", ",", "betaF", "C", ".", "float", "\n", "alphaF", "=", "C", ".", "float", "(", "float32", "(", "alpha", ")", ")", "\n", "betaF", "=", "C", ".", "float", "(", "float32", "(", "beta", ")", ")", "\n", "alphaC", "=", "unsafe", ".", "Pointer", "(", "&", "alphaF", ")", "\n", "betaC", "=", "unsafe", ".", "Pointer", "(", "&", "betaF", ")", "\n", "case", "Double", ":", "var", "alphaF", ",", "betaF", "C", ".", "double", "\n", "alphaF", "=", "C", ".", "double", "(", "alpha", ")", "\n", "betaF", "=", "C", ".", "double", "(", "beta", ")", "\n", "alphaC", "=", "unsafe", ".", "Pointer", "(", "&", "alphaF", ")", "\n", "betaC", "=", "unsafe", ".", "Pointer", "(", "&", "betaF", ")", "\n", "default", ":", "return", "errors", ".", "Errorf", "(", "\"", "\"", ",", "yDesc", ".", "dataType", ")", "\n", "}", "\n", "// call cudnnSoftmaxBackward", "return", "result", "(", "C", ".", "cudnnSoftmaxBackward", "(", "co", ".", "internal", ",", "algo", ".", "C", "(", ")", ",", "mode", ".", "C", "(", ")", ",", "alphaC", ",", "yDesc", ".", "internal", ",", "y", ".", "Pointer", "(", ")", ",", "dyDesc", ".", "internal", ",", "dy", ".", "Pointer", "(", ")", ",", "betaC", ",", "dxDesc", ".", "internal", ",", "dx", ".", "Pointer", "(", ")", ")", ")", "\n", "}" ]
// SoftmaxBackward computes the gradient of the softmax function.
[ "SoftmaxBackward", "computes", "the", "gradient", "of", "the", "softmax", "function", "." ]
89152d7e441439045736bc7640ff607ec371c26c
https://github.com/gorgonia/cu/blob/89152d7e441439045736bc7640ff607ec371c26c/dnn/generated_API.go#L382-L403
5,455
gorgonia/cu
dnn/generated_API.go
LRNCrossChannelForward
func (co *Context) LRNCrossChannelForward(normDesc *LRN, lrnMode LRNMode, alpha float64, xDesc *TensorDescriptor, x Memory, beta float64, yDesc *TensorDescriptor, y Memory) error { // DOUBLECHECK: "cudnnLRNCrossChannelForward" returns Memory type in Parameter 8 var alphaC, betaC unsafe.Pointer switch xDesc.dataType { case Float, Half: var alphaF, betaF C.float alphaF = C.float(float32(alpha)) betaF = C.float(float32(beta)) alphaC = unsafe.Pointer(&alphaF) betaC = unsafe.Pointer(&betaF) case Double: var alphaF, betaF C.double alphaF = C.double(alpha) betaF = C.double(beta) alphaC = unsafe.Pointer(&alphaF) betaC = unsafe.Pointer(&betaF) default: return errors.Errorf("Unsupported data type: %v", xDesc.dataType) } // call cudnnLRNCrossChannelForward return result(C.cudnnLRNCrossChannelForward(co.internal, normDesc.internal, lrnMode.C(), alphaC, xDesc.internal, x.Pointer(), betaC, yDesc.internal, y.Pointer())) }
go
func (co *Context) LRNCrossChannelForward(normDesc *LRN, lrnMode LRNMode, alpha float64, xDesc *TensorDescriptor, x Memory, beta float64, yDesc *TensorDescriptor, y Memory) error { // DOUBLECHECK: "cudnnLRNCrossChannelForward" returns Memory type in Parameter 8 var alphaC, betaC unsafe.Pointer switch xDesc.dataType { case Float, Half: var alphaF, betaF C.float alphaF = C.float(float32(alpha)) betaF = C.float(float32(beta)) alphaC = unsafe.Pointer(&alphaF) betaC = unsafe.Pointer(&betaF) case Double: var alphaF, betaF C.double alphaF = C.double(alpha) betaF = C.double(beta) alphaC = unsafe.Pointer(&alphaF) betaC = unsafe.Pointer(&betaF) default: return errors.Errorf("Unsupported data type: %v", xDesc.dataType) } // call cudnnLRNCrossChannelForward return result(C.cudnnLRNCrossChannelForward(co.internal, normDesc.internal, lrnMode.C(), alphaC, xDesc.internal, x.Pointer(), betaC, yDesc.internal, y.Pointer())) }
[ "func", "(", "co", "*", "Context", ")", "LRNCrossChannelForward", "(", "normDesc", "*", "LRN", ",", "lrnMode", "LRNMode", ",", "alpha", "float64", ",", "xDesc", "*", "TensorDescriptor", ",", "x", "Memory", ",", "beta", "float64", ",", "yDesc", "*", "TensorDescriptor", ",", "y", "Memory", ")", "error", "{", "// DOUBLECHECK: \"cudnnLRNCrossChannelForward\" returns Memory type in Parameter 8", "var", "alphaC", ",", "betaC", "unsafe", ".", "Pointer", "\n", "switch", "xDesc", ".", "dataType", "{", "case", "Float", ",", "Half", ":", "var", "alphaF", ",", "betaF", "C", ".", "float", "\n", "alphaF", "=", "C", ".", "float", "(", "float32", "(", "alpha", ")", ")", "\n", "betaF", "=", "C", ".", "float", "(", "float32", "(", "beta", ")", ")", "\n", "alphaC", "=", "unsafe", ".", "Pointer", "(", "&", "alphaF", ")", "\n", "betaC", "=", "unsafe", ".", "Pointer", "(", "&", "betaF", ")", "\n", "case", "Double", ":", "var", "alphaF", ",", "betaF", "C", ".", "double", "\n", "alphaF", "=", "C", ".", "double", "(", "alpha", ")", "\n", "betaF", "=", "C", ".", "double", "(", "beta", ")", "\n", "alphaC", "=", "unsafe", ".", "Pointer", "(", "&", "alphaF", ")", "\n", "betaC", "=", "unsafe", ".", "Pointer", "(", "&", "betaF", ")", "\n", "default", ":", "return", "errors", ".", "Errorf", "(", "\"", "\"", ",", "xDesc", ".", "dataType", ")", "\n", "}", "\n", "// call cudnnLRNCrossChannelForward", "return", "result", "(", "C", ".", "cudnnLRNCrossChannelForward", "(", "co", ".", "internal", ",", "normDesc", ".", "internal", ",", "lrnMode", ".", "C", "(", ")", ",", "alphaC", ",", "xDesc", ".", "internal", ",", "x", ".", "Pointer", "(", ")", ",", "betaC", ",", "yDesc", ".", "internal", ",", "y", ".", "Pointer", "(", ")", ")", ")", "\n", "}" ]
// LRNCrossChannelForward performs the forward LRN layer computation.
[ "LRNCrossChannelForward", "performs", "the", "forward", "LRN", "layer", "computation", "." ]
89152d7e441439045736bc7640ff607ec371c26c
https://github.com/gorgonia/cu/blob/89152d7e441439045736bc7640ff607ec371c26c/dnn/generated_API.go#L502-L523
5,456
gorgonia/cu
dnn/generated_API.go
DivisiveNormalizationBackward
func (co *Context) DivisiveNormalizationBackward(normDesc *LRN, mode DivNormMode, alpha float64, xDesc *TensorDescriptor, x Memory, means Memory, dy Memory, temp Memory, temp2 Memory, beta float64, dXdMeansDesc *TensorDescriptor, dx Memory, dMeans Memory) error { // DOUBLECHECK: "cudnnDivisiveNormalizationBackward" returns Memory type in Parameter 13 var alphaC, betaC unsafe.Pointer switch xDesc.dataType { case Float, Half: var alphaF, betaF C.float alphaF = C.float(float32(alpha)) betaF = C.float(float32(beta)) alphaC = unsafe.Pointer(&alphaF) betaC = unsafe.Pointer(&betaF) case Double: var alphaF, betaF C.double alphaF = C.double(alpha) betaF = C.double(beta) alphaC = unsafe.Pointer(&alphaF) betaC = unsafe.Pointer(&betaF) default: return errors.Errorf("Unsupported data type: %v", xDesc.dataType) } // call cudnnDivisiveNormalizationBackward return result(C.cudnnDivisiveNormalizationBackward(co.internal, normDesc.internal, mode.C(), alphaC, xDesc.internal, x.Pointer(), means.Pointer(), dy.Pointer(), temp.Pointer(), temp2.Pointer(), betaC, dXdMeansDesc.internal, dx.Pointer(), dMeans.Pointer())) }
go
func (co *Context) DivisiveNormalizationBackward(normDesc *LRN, mode DivNormMode, alpha float64, xDesc *TensorDescriptor, x Memory, means Memory, dy Memory, temp Memory, temp2 Memory, beta float64, dXdMeansDesc *TensorDescriptor, dx Memory, dMeans Memory) error { // DOUBLECHECK: "cudnnDivisiveNormalizationBackward" returns Memory type in Parameter 13 var alphaC, betaC unsafe.Pointer switch xDesc.dataType { case Float, Half: var alphaF, betaF C.float alphaF = C.float(float32(alpha)) betaF = C.float(float32(beta)) alphaC = unsafe.Pointer(&alphaF) betaC = unsafe.Pointer(&betaF) case Double: var alphaF, betaF C.double alphaF = C.double(alpha) betaF = C.double(beta) alphaC = unsafe.Pointer(&alphaF) betaC = unsafe.Pointer(&betaF) default: return errors.Errorf("Unsupported data type: %v", xDesc.dataType) } // call cudnnDivisiveNormalizationBackward return result(C.cudnnDivisiveNormalizationBackward(co.internal, normDesc.internal, mode.C(), alphaC, xDesc.internal, x.Pointer(), means.Pointer(), dy.Pointer(), temp.Pointer(), temp2.Pointer(), betaC, dXdMeansDesc.internal, dx.Pointer(), dMeans.Pointer())) }
[ "func", "(", "co", "*", "Context", ")", "DivisiveNormalizationBackward", "(", "normDesc", "*", "LRN", ",", "mode", "DivNormMode", ",", "alpha", "float64", ",", "xDesc", "*", "TensorDescriptor", ",", "x", "Memory", ",", "means", "Memory", ",", "dy", "Memory", ",", "temp", "Memory", ",", "temp2", "Memory", ",", "beta", "float64", ",", "dXdMeansDesc", "*", "TensorDescriptor", ",", "dx", "Memory", ",", "dMeans", "Memory", ")", "error", "{", "// DOUBLECHECK: \"cudnnDivisiveNormalizationBackward\" returns Memory type in Parameter 13", "var", "alphaC", ",", "betaC", "unsafe", ".", "Pointer", "\n", "switch", "xDesc", ".", "dataType", "{", "case", "Float", ",", "Half", ":", "var", "alphaF", ",", "betaF", "C", ".", "float", "\n", "alphaF", "=", "C", ".", "float", "(", "float32", "(", "alpha", ")", ")", "\n", "betaF", "=", "C", ".", "float", "(", "float32", "(", "beta", ")", ")", "\n", "alphaC", "=", "unsafe", ".", "Pointer", "(", "&", "alphaF", ")", "\n", "betaC", "=", "unsafe", ".", "Pointer", "(", "&", "betaF", ")", "\n", "case", "Double", ":", "var", "alphaF", ",", "betaF", "C", ".", "double", "\n", "alphaF", "=", "C", ".", "double", "(", "alpha", ")", "\n", "betaF", "=", "C", ".", "double", "(", "beta", ")", "\n", "alphaC", "=", "unsafe", ".", "Pointer", "(", "&", "alphaF", ")", "\n", "betaC", "=", "unsafe", ".", "Pointer", "(", "&", "betaF", ")", "\n", "default", ":", "return", "errors", ".", "Errorf", "(", "\"", "\"", ",", "xDesc", ".", "dataType", ")", "\n", "}", "\n", "// call cudnnDivisiveNormalizationBackward", "return", "result", "(", "C", ".", "cudnnDivisiveNormalizationBackward", "(", "co", ".", "internal", ",", "normDesc", ".", "internal", ",", "mode", ".", "C", "(", ")", ",", "alphaC", ",", "xDesc", ".", "internal", ",", "x", ".", "Pointer", "(", ")", ",", "means", ".", "Pointer", "(", ")", ",", "dy", ".", "Pointer", "(", ")", ",", "temp", ".", "Pointer", "(", ")", ",", "temp2", ".", "Pointer", "(", ")", ",", "betaC", ",", "dXdMeansDesc", ".", "internal", ",", "dx", ".", "Pointer", "(", ")", ",", "dMeans", ".", "Pointer", "(", ")", ")", ")", "\n", "}" ]
// DivisiveNormalizationBackward performs the backward DivisiveNormalization layer computation.
[ "DivisiveNormalizationBackward", "performs", "the", "backward", "DivisiveNormalization", "layer", "computation", "." ]
89152d7e441439045736bc7640ff607ec371c26c
https://github.com/gorgonia/cu/blob/89152d7e441439045736bc7640ff607ec371c26c/dnn/generated_API.go#L575-L596
5,457
gorgonia/cu
dnn/generated_API.go
BatchNormalizationForwardTraining
func (co *Context) BatchNormalizationForwardTraining(mode BatchNormMode, alpha float64, beta float64, xDesc *TensorDescriptor, x Memory, yDesc *TensorDescriptor, y Memory, bnScaleBiasMeanVarDesc *TensorDescriptor, bnScale Memory, bnBias Memory, exponentialAverageFactor float64, resultRunningMean Memory, resultRunningVariance Memory, epsilon float64, resultSaveMean Memory, resultSaveInvVariance Memory) error { // DOUBLECHECK: "cudnnBatchNormalizationForwardTraining" returns Memory type in Parameter 16 var alphaC, betaC unsafe.Pointer switch xDesc.dataType { case Float, Half: var alphaF, betaF C.float alphaF = C.float(float32(alpha)) betaF = C.float(float32(beta)) alphaC = unsafe.Pointer(&alphaF) betaC = unsafe.Pointer(&betaF) case Double: var alphaF, betaF C.double alphaF = C.double(alpha) betaF = C.double(beta) alphaC = unsafe.Pointer(&alphaF) betaC = unsafe.Pointer(&betaF) default: return errors.Errorf("Unsupported data type: %v", xDesc.dataType) } // call cudnnBatchNormalizationForwardTraining return result(C.cudnnBatchNormalizationForwardTraining(co.internal, mode.C(), alphaC, betaC, xDesc.internal, x.Pointer(), yDesc.internal, y.Pointer(), bnScaleBiasMeanVarDesc.internal, bnScale.Pointer(), bnBias.Pointer(), C.double(exponentialAverageFactor), resultRunningMean.Pointer(), resultRunningVariance.Pointer(), C.double(epsilon), resultSaveMean.Pointer(), resultSaveInvVariance.Pointer())) }
go
func (co *Context) BatchNormalizationForwardTraining(mode BatchNormMode, alpha float64, beta float64, xDesc *TensorDescriptor, x Memory, yDesc *TensorDescriptor, y Memory, bnScaleBiasMeanVarDesc *TensorDescriptor, bnScale Memory, bnBias Memory, exponentialAverageFactor float64, resultRunningMean Memory, resultRunningVariance Memory, epsilon float64, resultSaveMean Memory, resultSaveInvVariance Memory) error { // DOUBLECHECK: "cudnnBatchNormalizationForwardTraining" returns Memory type in Parameter 16 var alphaC, betaC unsafe.Pointer switch xDesc.dataType { case Float, Half: var alphaF, betaF C.float alphaF = C.float(float32(alpha)) betaF = C.float(float32(beta)) alphaC = unsafe.Pointer(&alphaF) betaC = unsafe.Pointer(&betaF) case Double: var alphaF, betaF C.double alphaF = C.double(alpha) betaF = C.double(beta) alphaC = unsafe.Pointer(&alphaF) betaC = unsafe.Pointer(&betaF) default: return errors.Errorf("Unsupported data type: %v", xDesc.dataType) } // call cudnnBatchNormalizationForwardTraining return result(C.cudnnBatchNormalizationForwardTraining(co.internal, mode.C(), alphaC, betaC, xDesc.internal, x.Pointer(), yDesc.internal, y.Pointer(), bnScaleBiasMeanVarDesc.internal, bnScale.Pointer(), bnBias.Pointer(), C.double(exponentialAverageFactor), resultRunningMean.Pointer(), resultRunningVariance.Pointer(), C.double(epsilon), resultSaveMean.Pointer(), resultSaveInvVariance.Pointer())) }
[ "func", "(", "co", "*", "Context", ")", "BatchNormalizationForwardTraining", "(", "mode", "BatchNormMode", ",", "alpha", "float64", ",", "beta", "float64", ",", "xDesc", "*", "TensorDescriptor", ",", "x", "Memory", ",", "yDesc", "*", "TensorDescriptor", ",", "y", "Memory", ",", "bnScaleBiasMeanVarDesc", "*", "TensorDescriptor", ",", "bnScale", "Memory", ",", "bnBias", "Memory", ",", "exponentialAverageFactor", "float64", ",", "resultRunningMean", "Memory", ",", "resultRunningVariance", "Memory", ",", "epsilon", "float64", ",", "resultSaveMean", "Memory", ",", "resultSaveInvVariance", "Memory", ")", "error", "{", "// DOUBLECHECK: \"cudnnBatchNormalizationForwardTraining\" returns Memory type in Parameter 16", "var", "alphaC", ",", "betaC", "unsafe", ".", "Pointer", "\n", "switch", "xDesc", ".", "dataType", "{", "case", "Float", ",", "Half", ":", "var", "alphaF", ",", "betaF", "C", ".", "float", "\n", "alphaF", "=", "C", ".", "float", "(", "float32", "(", "alpha", ")", ")", "\n", "betaF", "=", "C", ".", "float", "(", "float32", "(", "beta", ")", ")", "\n", "alphaC", "=", "unsafe", ".", "Pointer", "(", "&", "alphaF", ")", "\n", "betaC", "=", "unsafe", ".", "Pointer", "(", "&", "betaF", ")", "\n", "case", "Double", ":", "var", "alphaF", ",", "betaF", "C", ".", "double", "\n", "alphaF", "=", "C", ".", "double", "(", "alpha", ")", "\n", "betaF", "=", "C", ".", "double", "(", "beta", ")", "\n", "alphaC", "=", "unsafe", ".", "Pointer", "(", "&", "alphaF", ")", "\n", "betaC", "=", "unsafe", ".", "Pointer", "(", "&", "betaF", ")", "\n", "default", ":", "return", "errors", ".", "Errorf", "(", "\"", "\"", ",", "xDesc", ".", "dataType", ")", "\n", "}", "\n", "// call cudnnBatchNormalizationForwardTraining", "return", "result", "(", "C", ".", "cudnnBatchNormalizationForwardTraining", "(", "co", ".", "internal", ",", "mode", ".", "C", "(", ")", ",", "alphaC", ",", "betaC", ",", "xDesc", ".", "internal", ",", "x", ".", "Pointer", "(", ")", ",", "yDesc", ".", "internal", ",", "y", ".", "Pointer", "(", ")", ",", "bnScaleBiasMeanVarDesc", ".", "internal", ",", "bnScale", ".", "Pointer", "(", ")", ",", "bnBias", ".", "Pointer", "(", ")", ",", "C", ".", "double", "(", "exponentialAverageFactor", ")", ",", "resultRunningMean", ".", "Pointer", "(", ")", ",", "resultRunningVariance", ".", "Pointer", "(", ")", ",", "C", ".", "double", "(", "epsilon", ")", ",", "resultSaveMean", ".", "Pointer", "(", ")", ",", "resultSaveInvVariance", ".", "Pointer", "(", ")", ")", ")", "\n", "}" ]
// BatchNormalizationForwardTraining performs the forward BatchNormalization layer computation for training phase.
[ "BatchNormalizationForwardTraining", "performs", "the", "forward", "BatchNormalization", "layer", "computation", "for", "training", "phase", "." ]
89152d7e441439045736bc7640ff607ec371c26c
https://github.com/gorgonia/cu/blob/89152d7e441439045736bc7640ff607ec371c26c/dnn/generated_API.go#L599-L620
5,458
gorgonia/cu
dnn/generated_API.go
BatchNormalizationBackward
func (co *Context) BatchNormalizationBackward(mode BatchNormMode, alphaDataDiff float64, betaDataDiff float64, alphaParamDiff float64, betaParamDiff float64, xDesc *TensorDescriptor, x Memory, dyDesc *TensorDescriptor, dy Memory, dxDesc *TensorDescriptor, dx Memory, dBnScaleBiasDesc *TensorDescriptor, bnScale Memory, dBnScaleResult Memory, dBnBiasResult Memory, epsilon float64, savedMean Memory, savedInvVariance Memory) error { var alphaDataDiffC, betaDataDiffC, alphaParamDiffC, betaParamDiffC unsafe.Pointer switch xDesc.dataType { case Float, Half: var alphaDataDiffF, betaDataDiffF, alphaParamDiffF, betaParamDiffF C.float alphaDataDiffF = C.float(float32(alphaDataDiff)) betaDataDiffF = C.float(float32(betaDataDiff)) alphaParamDiffF = C.float(float32(alphaParamDiff)) betaParamDiffF = C.float(float32(betaParamDiff)) alphaDataDiffC = unsafe.Pointer(&alphaDataDiffF) betaDataDiffC = unsafe.Pointer(&betaDataDiffF) alphaParamDiffC = unsafe.Pointer(&alphaParamDiffF) betaParamDiffC = unsafe.Pointer(&betaParamDiffF) case Double: var alphaDataDiffF, betaDataDiffF, alphaParamDiffF, betaParamDiffF C.double alphaDataDiffF = C.double(alphaDataDiff) betaDataDiffF = C.double(betaDataDiff) alphaParamDiffF = C.double(alphaParamDiff) betaParamDiffF = C.double(betaParamDiff) alphaDataDiffC = unsafe.Pointer(&alphaDataDiffF) betaDataDiffC = unsafe.Pointer(&betaDataDiffF) alphaParamDiffC = unsafe.Pointer(&alphaParamDiffF) betaParamDiffC = unsafe.Pointer(&betaParamDiffF) default: return errors.Errorf("Unsupported data type: %v", xDesc.dataType) } // call cudnnBatchNormalizationBackward return result(C.cudnnBatchNormalizationBackward(co.internal, mode.C(), alphaDataDiffC, betaDataDiffC, alphaParamDiffC, betaParamDiffC, xDesc.internal, x.Pointer(), dyDesc.internal, dy.Pointer(), dxDesc.internal, dx.Pointer(), dBnScaleBiasDesc.internal, bnScale.Pointer(), dBnScaleResult.Pointer(), dBnBiasResult.Pointer(), C.double(epsilon), savedMean.Pointer(), savedInvVariance.Pointer())) }
go
func (co *Context) BatchNormalizationBackward(mode BatchNormMode, alphaDataDiff float64, betaDataDiff float64, alphaParamDiff float64, betaParamDiff float64, xDesc *TensorDescriptor, x Memory, dyDesc *TensorDescriptor, dy Memory, dxDesc *TensorDescriptor, dx Memory, dBnScaleBiasDesc *TensorDescriptor, bnScale Memory, dBnScaleResult Memory, dBnBiasResult Memory, epsilon float64, savedMean Memory, savedInvVariance Memory) error { var alphaDataDiffC, betaDataDiffC, alphaParamDiffC, betaParamDiffC unsafe.Pointer switch xDesc.dataType { case Float, Half: var alphaDataDiffF, betaDataDiffF, alphaParamDiffF, betaParamDiffF C.float alphaDataDiffF = C.float(float32(alphaDataDiff)) betaDataDiffF = C.float(float32(betaDataDiff)) alphaParamDiffF = C.float(float32(alphaParamDiff)) betaParamDiffF = C.float(float32(betaParamDiff)) alphaDataDiffC = unsafe.Pointer(&alphaDataDiffF) betaDataDiffC = unsafe.Pointer(&betaDataDiffF) alphaParamDiffC = unsafe.Pointer(&alphaParamDiffF) betaParamDiffC = unsafe.Pointer(&betaParamDiffF) case Double: var alphaDataDiffF, betaDataDiffF, alphaParamDiffF, betaParamDiffF C.double alphaDataDiffF = C.double(alphaDataDiff) betaDataDiffF = C.double(betaDataDiff) alphaParamDiffF = C.double(alphaParamDiff) betaParamDiffF = C.double(betaParamDiff) alphaDataDiffC = unsafe.Pointer(&alphaDataDiffF) betaDataDiffC = unsafe.Pointer(&betaDataDiffF) alphaParamDiffC = unsafe.Pointer(&alphaParamDiffF) betaParamDiffC = unsafe.Pointer(&betaParamDiffF) default: return errors.Errorf("Unsupported data type: %v", xDesc.dataType) } // call cudnnBatchNormalizationBackward return result(C.cudnnBatchNormalizationBackward(co.internal, mode.C(), alphaDataDiffC, betaDataDiffC, alphaParamDiffC, betaParamDiffC, xDesc.internal, x.Pointer(), dyDesc.internal, dy.Pointer(), dxDesc.internal, dx.Pointer(), dBnScaleBiasDesc.internal, bnScale.Pointer(), dBnScaleResult.Pointer(), dBnBiasResult.Pointer(), C.double(epsilon), savedMean.Pointer(), savedInvVariance.Pointer())) }
[ "func", "(", "co", "*", "Context", ")", "BatchNormalizationBackward", "(", "mode", "BatchNormMode", ",", "alphaDataDiff", "float64", ",", "betaDataDiff", "float64", ",", "alphaParamDiff", "float64", ",", "betaParamDiff", "float64", ",", "xDesc", "*", "TensorDescriptor", ",", "x", "Memory", ",", "dyDesc", "*", "TensorDescriptor", ",", "dy", "Memory", ",", "dxDesc", "*", "TensorDescriptor", ",", "dx", "Memory", ",", "dBnScaleBiasDesc", "*", "TensorDescriptor", ",", "bnScale", "Memory", ",", "dBnScaleResult", "Memory", ",", "dBnBiasResult", "Memory", ",", "epsilon", "float64", ",", "savedMean", "Memory", ",", "savedInvVariance", "Memory", ")", "error", "{", "var", "alphaDataDiffC", ",", "betaDataDiffC", ",", "alphaParamDiffC", ",", "betaParamDiffC", "unsafe", ".", "Pointer", "\n", "switch", "xDesc", ".", "dataType", "{", "case", "Float", ",", "Half", ":", "var", "alphaDataDiffF", ",", "betaDataDiffF", ",", "alphaParamDiffF", ",", "betaParamDiffF", "C", ".", "float", "\n", "alphaDataDiffF", "=", "C", ".", "float", "(", "float32", "(", "alphaDataDiff", ")", ")", "\n", "betaDataDiffF", "=", "C", ".", "float", "(", "float32", "(", "betaDataDiff", ")", ")", "\n", "alphaParamDiffF", "=", "C", ".", "float", "(", "float32", "(", "alphaParamDiff", ")", ")", "\n", "betaParamDiffF", "=", "C", ".", "float", "(", "float32", "(", "betaParamDiff", ")", ")", "\n", "alphaDataDiffC", "=", "unsafe", ".", "Pointer", "(", "&", "alphaDataDiffF", ")", "\n", "betaDataDiffC", "=", "unsafe", ".", "Pointer", "(", "&", "betaDataDiffF", ")", "\n", "alphaParamDiffC", "=", "unsafe", ".", "Pointer", "(", "&", "alphaParamDiffF", ")", "\n", "betaParamDiffC", "=", "unsafe", ".", "Pointer", "(", "&", "betaParamDiffF", ")", "\n", "case", "Double", ":", "var", "alphaDataDiffF", ",", "betaDataDiffF", ",", "alphaParamDiffF", ",", "betaParamDiffF", "C", ".", "double", "\n", "alphaDataDiffF", "=", "C", ".", "double", "(", "alphaDataDiff", ")", "\n", "betaDataDiffF", "=", "C", ".", "double", "(", "betaDataDiff", ")", "\n", "alphaParamDiffF", "=", "C", ".", "double", "(", "alphaParamDiff", ")", "\n", "betaParamDiffF", "=", "C", ".", "double", "(", "betaParamDiff", ")", "\n", "alphaDataDiffC", "=", "unsafe", ".", "Pointer", "(", "&", "alphaDataDiffF", ")", "\n", "betaDataDiffC", "=", "unsafe", ".", "Pointer", "(", "&", "betaDataDiffF", ")", "\n", "alphaParamDiffC", "=", "unsafe", ".", "Pointer", "(", "&", "alphaParamDiffF", ")", "\n", "betaParamDiffC", "=", "unsafe", ".", "Pointer", "(", "&", "betaParamDiffF", ")", "\n", "default", ":", "return", "errors", ".", "Errorf", "(", "\"", "\"", ",", "xDesc", ".", "dataType", ")", "\n", "}", "\n", "// call cudnnBatchNormalizationBackward", "return", "result", "(", "C", ".", "cudnnBatchNormalizationBackward", "(", "co", ".", "internal", ",", "mode", ".", "C", "(", ")", ",", "alphaDataDiffC", ",", "betaDataDiffC", ",", "alphaParamDiffC", ",", "betaParamDiffC", ",", "xDesc", ".", "internal", ",", "x", ".", "Pointer", "(", ")", ",", "dyDesc", ".", "internal", ",", "dy", ".", "Pointer", "(", ")", ",", "dxDesc", ".", "internal", ",", "dx", ".", "Pointer", "(", ")", ",", "dBnScaleBiasDesc", ".", "internal", ",", "bnScale", ".", "Pointer", "(", ")", ",", "dBnScaleResult", ".", "Pointer", "(", ")", ",", "dBnBiasResult", ".", "Pointer", "(", ")", ",", "C", ".", "double", "(", "epsilon", ")", ",", "savedMean", ".", "Pointer", "(", ")", ",", "savedInvVariance", ".", "Pointer", "(", ")", ")", ")", "\n", "}" ]
// BatchNormalizationBackward performs the backward BatchNormalization layer computation.
[ "BatchNormalizationBackward", "performs", "the", "backward", "BatchNormalization", "layer", "computation", "." ]
89152d7e441439045736bc7640ff607ec371c26c
https://github.com/gorgonia/cu/blob/89152d7e441439045736bc7640ff607ec371c26c/dnn/generated_API.go#L646-L674
5,459
gorgonia/cu
dnn/generated_API.go
SpatialTfGridGeneratorForward
func (co *Context) SpatialTfGridGeneratorForward(stDesc *SpatialTransformer, theta Memory, grid Memory) error { // DOUBLECHECK: "cudnnSpatialTfGridGeneratorForward" returns Memory type in Parameter 3 // call cudnnSpatialTfGridGeneratorForward return result(C.cudnnSpatialTfGridGeneratorForward(co.internal, stDesc.internal, theta.Pointer(), grid.Pointer())) }
go
func (co *Context) SpatialTfGridGeneratorForward(stDesc *SpatialTransformer, theta Memory, grid Memory) error { // DOUBLECHECK: "cudnnSpatialTfGridGeneratorForward" returns Memory type in Parameter 3 // call cudnnSpatialTfGridGeneratorForward return result(C.cudnnSpatialTfGridGeneratorForward(co.internal, stDesc.internal, theta.Pointer(), grid.Pointer())) }
[ "func", "(", "co", "*", "Context", ")", "SpatialTfGridGeneratorForward", "(", "stDesc", "*", "SpatialTransformer", ",", "theta", "Memory", ",", "grid", "Memory", ")", "error", "{", "// DOUBLECHECK: \"cudnnSpatialTfGridGeneratorForward\" returns Memory type in Parameter 3", "// call cudnnSpatialTfGridGeneratorForward", "return", "result", "(", "C", ".", "cudnnSpatialTfGridGeneratorForward", "(", "co", ".", "internal", ",", "stDesc", ".", "internal", ",", "theta", ".", "Pointer", "(", ")", ",", "grid", ".", "Pointer", "(", ")", ")", ")", "\n", "}" ]
// SpatialTfGridGeneratorForward generates a grid of coordinates in the input tensor corresponding to each pixel from the output tensor.
[ "SpatialTfGridGeneratorForward", "generates", "a", "grid", "of", "coordinates", "in", "the", "input", "tensor", "corresponding", "to", "each", "pixel", "from", "the", "output", "tensor", "." ]
89152d7e441439045736bc7640ff607ec371c26c
https://github.com/gorgonia/cu/blob/89152d7e441439045736bc7640ff607ec371c26c/dnn/generated_API.go#L677-L681
5,460
gorgonia/cu
dnn/generated_API.go
SpatialTfGridGeneratorBackward
func (co *Context) SpatialTfGridGeneratorBackward(stDesc *SpatialTransformer, dgrid Memory, dtheta Memory) error { // DOUBLECHECK: "cudnnSpatialTfGridGeneratorBackward" returns Memory type in Parameter 3 // call cudnnSpatialTfGridGeneratorBackward return result(C.cudnnSpatialTfGridGeneratorBackward(co.internal, stDesc.internal, dgrid.Pointer(), dtheta.Pointer())) }
go
func (co *Context) SpatialTfGridGeneratorBackward(stDesc *SpatialTransformer, dgrid Memory, dtheta Memory) error { // DOUBLECHECK: "cudnnSpatialTfGridGeneratorBackward" returns Memory type in Parameter 3 // call cudnnSpatialTfGridGeneratorBackward return result(C.cudnnSpatialTfGridGeneratorBackward(co.internal, stDesc.internal, dgrid.Pointer(), dtheta.Pointer())) }
[ "func", "(", "co", "*", "Context", ")", "SpatialTfGridGeneratorBackward", "(", "stDesc", "*", "SpatialTransformer", ",", "dgrid", "Memory", ",", "dtheta", "Memory", ")", "error", "{", "// DOUBLECHECK: \"cudnnSpatialTfGridGeneratorBackward\" returns Memory type in Parameter 3", "// call cudnnSpatialTfGridGeneratorBackward", "return", "result", "(", "C", ".", "cudnnSpatialTfGridGeneratorBackward", "(", "co", ".", "internal", ",", "stDesc", ".", "internal", ",", "dgrid", ".", "Pointer", "(", ")", ",", "dtheta", ".", "Pointer", "(", ")", ")", ")", "\n", "}" ]
// SpatialTfGridGeneratorBackward computes the gradient of a grid generation operation.
[ "SpatialTfGridGeneratorBackward", "computes", "the", "gradient", "of", "a", "grid", "generation", "operation", "." ]
89152d7e441439045736bc7640ff607ec371c26c
https://github.com/gorgonia/cu/blob/89152d7e441439045736bc7640ff607ec371c26c/dnn/generated_API.go#L684-L688
5,461
gorgonia/cu
dnn/generated_API.go
SpatialTfSamplerForward
func (co *Context) SpatialTfSamplerForward(stDesc *SpatialTransformer, alpha float64, xDesc *TensorDescriptor, x Memory, grid Memory, beta float64, yDesc *TensorDescriptor, y Memory) error { // DOUBLECHECK: "cudnnSpatialTfSamplerForward" returns Memory type in Parameter 8 var alphaC, betaC unsafe.Pointer switch xDesc.dataType { case Float, Half: var alphaF, betaF C.float alphaF = C.float(float32(alpha)) betaF = C.float(float32(beta)) alphaC = unsafe.Pointer(&alphaF) betaC = unsafe.Pointer(&betaF) case Double: var alphaF, betaF C.double alphaF = C.double(alpha) betaF = C.double(beta) alphaC = unsafe.Pointer(&alphaF) betaC = unsafe.Pointer(&betaF) default: return errors.Errorf("Unsupported data type: %v", xDesc.dataType) } // call cudnnSpatialTfSamplerForward return result(C.cudnnSpatialTfSamplerForward(co.internal, stDesc.internal, alphaC, xDesc.internal, x.Pointer(), grid.Pointer(), betaC, yDesc.internal, y.Pointer())) }
go
func (co *Context) SpatialTfSamplerForward(stDesc *SpatialTransformer, alpha float64, xDesc *TensorDescriptor, x Memory, grid Memory, beta float64, yDesc *TensorDescriptor, y Memory) error { // DOUBLECHECK: "cudnnSpatialTfSamplerForward" returns Memory type in Parameter 8 var alphaC, betaC unsafe.Pointer switch xDesc.dataType { case Float, Half: var alphaF, betaF C.float alphaF = C.float(float32(alpha)) betaF = C.float(float32(beta)) alphaC = unsafe.Pointer(&alphaF) betaC = unsafe.Pointer(&betaF) case Double: var alphaF, betaF C.double alphaF = C.double(alpha) betaF = C.double(beta) alphaC = unsafe.Pointer(&alphaF) betaC = unsafe.Pointer(&betaF) default: return errors.Errorf("Unsupported data type: %v", xDesc.dataType) } // call cudnnSpatialTfSamplerForward return result(C.cudnnSpatialTfSamplerForward(co.internal, stDesc.internal, alphaC, xDesc.internal, x.Pointer(), grid.Pointer(), betaC, yDesc.internal, y.Pointer())) }
[ "func", "(", "co", "*", "Context", ")", "SpatialTfSamplerForward", "(", "stDesc", "*", "SpatialTransformer", ",", "alpha", "float64", ",", "xDesc", "*", "TensorDescriptor", ",", "x", "Memory", ",", "grid", "Memory", ",", "beta", "float64", ",", "yDesc", "*", "TensorDescriptor", ",", "y", "Memory", ")", "error", "{", "// DOUBLECHECK: \"cudnnSpatialTfSamplerForward\" returns Memory type in Parameter 8", "var", "alphaC", ",", "betaC", "unsafe", ".", "Pointer", "\n", "switch", "xDesc", ".", "dataType", "{", "case", "Float", ",", "Half", ":", "var", "alphaF", ",", "betaF", "C", ".", "float", "\n", "alphaF", "=", "C", ".", "float", "(", "float32", "(", "alpha", ")", ")", "\n", "betaF", "=", "C", ".", "float", "(", "float32", "(", "beta", ")", ")", "\n", "alphaC", "=", "unsafe", ".", "Pointer", "(", "&", "alphaF", ")", "\n", "betaC", "=", "unsafe", ".", "Pointer", "(", "&", "betaF", ")", "\n", "case", "Double", ":", "var", "alphaF", ",", "betaF", "C", ".", "double", "\n", "alphaF", "=", "C", ".", "double", "(", "alpha", ")", "\n", "betaF", "=", "C", ".", "double", "(", "beta", ")", "\n", "alphaC", "=", "unsafe", ".", "Pointer", "(", "&", "alphaF", ")", "\n", "betaC", "=", "unsafe", ".", "Pointer", "(", "&", "betaF", ")", "\n", "default", ":", "return", "errors", ".", "Errorf", "(", "\"", "\"", ",", "xDesc", ".", "dataType", ")", "\n", "}", "\n", "// call cudnnSpatialTfSamplerForward", "return", "result", "(", "C", ".", "cudnnSpatialTfSamplerForward", "(", "co", ".", "internal", ",", "stDesc", ".", "internal", ",", "alphaC", ",", "xDesc", ".", "internal", ",", "x", ".", "Pointer", "(", ")", ",", "grid", ".", "Pointer", "(", ")", ",", "betaC", ",", "yDesc", ".", "internal", ",", "y", ".", "Pointer", "(", ")", ")", ")", "\n", "}" ]
// SpatialTfSamplerForward performs a sampler operation and generates the output tensor using the grid given by the grid generator.
[ "SpatialTfSamplerForward", "performs", "a", "sampler", "operation", "and", "generates", "the", "output", "tensor", "using", "the", "grid", "given", "by", "the", "grid", "generator", "." ]
89152d7e441439045736bc7640ff607ec371c26c
https://github.com/gorgonia/cu/blob/89152d7e441439045736bc7640ff607ec371c26c/dnn/generated_API.go#L691-L712
5,462
gorgonia/cu
dnn/generated_API.go
SpatialTfSamplerBackward
func (co *Context) SpatialTfSamplerBackward(stDesc *SpatialTransformer, alpha float64, xDesc *TensorDescriptor, x Memory, beta float64, dxDesc *TensorDescriptor, dx Memory, alphaDgrid Memory, dyDesc *TensorDescriptor, dy Memory, grid Memory, betaDgrid Memory, dgrid Memory) error { // DOUBLECHECK: "cudnnSpatialTfSamplerBackward" returns Memory type in Parameter 13 var alphaC, betaC unsafe.Pointer switch xDesc.dataType { case Float, Half: var alphaF, betaF C.float alphaF = C.float(float32(alpha)) betaF = C.float(float32(beta)) alphaC = unsafe.Pointer(&alphaF) betaC = unsafe.Pointer(&betaF) case Double: var alphaF, betaF C.double alphaF = C.double(alpha) betaF = C.double(beta) alphaC = unsafe.Pointer(&alphaF) betaC = unsafe.Pointer(&betaF) default: return errors.Errorf("Unsupported data type: %v", xDesc.dataType) } // call cudnnSpatialTfSamplerBackward return result(C.cudnnSpatialTfSamplerBackward(co.internal, stDesc.internal, alphaC, xDesc.internal, x.Pointer(), betaC, dxDesc.internal, dx.Pointer(), alphaDgrid.Pointer(), dyDesc.internal, dy.Pointer(), grid.Pointer(), betaDgrid.Pointer(), dgrid.Pointer())) }
go
func (co *Context) SpatialTfSamplerBackward(stDesc *SpatialTransformer, alpha float64, xDesc *TensorDescriptor, x Memory, beta float64, dxDesc *TensorDescriptor, dx Memory, alphaDgrid Memory, dyDesc *TensorDescriptor, dy Memory, grid Memory, betaDgrid Memory, dgrid Memory) error { // DOUBLECHECK: "cudnnSpatialTfSamplerBackward" returns Memory type in Parameter 13 var alphaC, betaC unsafe.Pointer switch xDesc.dataType { case Float, Half: var alphaF, betaF C.float alphaF = C.float(float32(alpha)) betaF = C.float(float32(beta)) alphaC = unsafe.Pointer(&alphaF) betaC = unsafe.Pointer(&betaF) case Double: var alphaF, betaF C.double alphaF = C.double(alpha) betaF = C.double(beta) alphaC = unsafe.Pointer(&alphaF) betaC = unsafe.Pointer(&betaF) default: return errors.Errorf("Unsupported data type: %v", xDesc.dataType) } // call cudnnSpatialTfSamplerBackward return result(C.cudnnSpatialTfSamplerBackward(co.internal, stDesc.internal, alphaC, xDesc.internal, x.Pointer(), betaC, dxDesc.internal, dx.Pointer(), alphaDgrid.Pointer(), dyDesc.internal, dy.Pointer(), grid.Pointer(), betaDgrid.Pointer(), dgrid.Pointer())) }
[ "func", "(", "co", "*", "Context", ")", "SpatialTfSamplerBackward", "(", "stDesc", "*", "SpatialTransformer", ",", "alpha", "float64", ",", "xDesc", "*", "TensorDescriptor", ",", "x", "Memory", ",", "beta", "float64", ",", "dxDesc", "*", "TensorDescriptor", ",", "dx", "Memory", ",", "alphaDgrid", "Memory", ",", "dyDesc", "*", "TensorDescriptor", ",", "dy", "Memory", ",", "grid", "Memory", ",", "betaDgrid", "Memory", ",", "dgrid", "Memory", ")", "error", "{", "// DOUBLECHECK: \"cudnnSpatialTfSamplerBackward\" returns Memory type in Parameter 13", "var", "alphaC", ",", "betaC", "unsafe", ".", "Pointer", "\n", "switch", "xDesc", ".", "dataType", "{", "case", "Float", ",", "Half", ":", "var", "alphaF", ",", "betaF", "C", ".", "float", "\n", "alphaF", "=", "C", ".", "float", "(", "float32", "(", "alpha", ")", ")", "\n", "betaF", "=", "C", ".", "float", "(", "float32", "(", "beta", ")", ")", "\n", "alphaC", "=", "unsafe", ".", "Pointer", "(", "&", "alphaF", ")", "\n", "betaC", "=", "unsafe", ".", "Pointer", "(", "&", "betaF", ")", "\n", "case", "Double", ":", "var", "alphaF", ",", "betaF", "C", ".", "double", "\n", "alphaF", "=", "C", ".", "double", "(", "alpha", ")", "\n", "betaF", "=", "C", ".", "double", "(", "beta", ")", "\n", "alphaC", "=", "unsafe", ".", "Pointer", "(", "&", "alphaF", ")", "\n", "betaC", "=", "unsafe", ".", "Pointer", "(", "&", "betaF", ")", "\n", "default", ":", "return", "errors", ".", "Errorf", "(", "\"", "\"", ",", "xDesc", ".", "dataType", ")", "\n", "}", "\n", "// call cudnnSpatialTfSamplerBackward", "return", "result", "(", "C", ".", "cudnnSpatialTfSamplerBackward", "(", "co", ".", "internal", ",", "stDesc", ".", "internal", ",", "alphaC", ",", "xDesc", ".", "internal", ",", "x", ".", "Pointer", "(", ")", ",", "betaC", ",", "dxDesc", ".", "internal", ",", "dx", ".", "Pointer", "(", ")", ",", "alphaDgrid", ".", "Pointer", "(", ")", ",", "dyDesc", ".", "internal", ",", "dy", ".", "Pointer", "(", ")", ",", "grid", ".", "Pointer", "(", ")", ",", "betaDgrid", ".", "Pointer", "(", ")", ",", "dgrid", ".", "Pointer", "(", ")", ")", ")", "\n", "}" ]
// SpatialTfSamplerBackward computes the gradient of a sampling operation.
[ "SpatialTfSamplerBackward", "computes", "the", "gradient", "of", "a", "sampling", "operation", "." ]
89152d7e441439045736bc7640ff607ec371c26c
https://github.com/gorgonia/cu/blob/89152d7e441439045736bc7640ff607ec371c26c/dnn/generated_API.go#L715-L736
5,463
gorgonia/cu
dnn/generated_API.go
DropoutGetStatesSize
func (co *Context) DropoutGetStatesSize() (sizeInBytes uintptr, err error) { var sizeInBytesC C.size_t // call cudnnDropoutGetStatesSize err = result(C.cudnnDropoutGetStatesSize(co.internal, &sizeInBytesC)) sizeInBytes = uintptr(sizeInBytesC) return }
go
func (co *Context) DropoutGetStatesSize() (sizeInBytes uintptr, err error) { var sizeInBytesC C.size_t // call cudnnDropoutGetStatesSize err = result(C.cudnnDropoutGetStatesSize(co.internal, &sizeInBytesC)) sizeInBytes = uintptr(sizeInBytesC) return }
[ "func", "(", "co", "*", "Context", ")", "DropoutGetStatesSize", "(", ")", "(", "sizeInBytes", "uintptr", ",", "err", "error", ")", "{", "var", "sizeInBytesC", "C", ".", "size_t", "\n", "// call cudnnDropoutGetStatesSize", "err", "=", "result", "(", "C", ".", "cudnnDropoutGetStatesSize", "(", "co", ".", "internal", ",", "&", "sizeInBytesC", ")", ")", "\n", "sizeInBytes", "=", "uintptr", "(", "sizeInBytesC", ")", "\n", "return", "\n", "}" ]
// DropoutGetStatesSize is used to query the amount of space required to store the states of the random number generators used by cudnnDropoutForward function.
[ "DropoutGetStatesSize", "is", "used", "to", "query", "the", "amount", "of", "space", "required", "to", "store", "the", "states", "of", "the", "random", "number", "generators", "used", "by", "cudnnDropoutForward", "function", "." ]
89152d7e441439045736bc7640ff607ec371c26c
https://github.com/gorgonia/cu/blob/89152d7e441439045736bc7640ff607ec371c26c/dnn/generated_API.go#L739-L745
5,464
gorgonia/cu
dnn/generated_API.go
DropoutBackward
func (co *Context) DropoutBackward(dropoutDesc *Dropout, dydesc *TensorDescriptor, dy Memory, dxdesc *TensorDescriptor, dx Memory, reserveSpace Memory, reserveSpaceSizeInBytes uintptr) error { // DOUBLECHECK: "cudnnDropoutBackward" returns Memory type in Parameter 5 // call cudnnDropoutBackward return result(C.cudnnDropoutBackward(co.internal, dropoutDesc.internal, dydesc.internal, dy.Pointer(), dxdesc.internal, dx.Pointer(), reserveSpace.Pointer(), C.size_t(reserveSpaceSizeInBytes))) }
go
func (co *Context) DropoutBackward(dropoutDesc *Dropout, dydesc *TensorDescriptor, dy Memory, dxdesc *TensorDescriptor, dx Memory, reserveSpace Memory, reserveSpaceSizeInBytes uintptr) error { // DOUBLECHECK: "cudnnDropoutBackward" returns Memory type in Parameter 5 // call cudnnDropoutBackward return result(C.cudnnDropoutBackward(co.internal, dropoutDesc.internal, dydesc.internal, dy.Pointer(), dxdesc.internal, dx.Pointer(), reserveSpace.Pointer(), C.size_t(reserveSpaceSizeInBytes))) }
[ "func", "(", "co", "*", "Context", ")", "DropoutBackward", "(", "dropoutDesc", "*", "Dropout", ",", "dydesc", "*", "TensorDescriptor", ",", "dy", "Memory", ",", "dxdesc", "*", "TensorDescriptor", ",", "dx", "Memory", ",", "reserveSpace", "Memory", ",", "reserveSpaceSizeInBytes", "uintptr", ")", "error", "{", "// DOUBLECHECK: \"cudnnDropoutBackward\" returns Memory type in Parameter 5", "// call cudnnDropoutBackward", "return", "result", "(", "C", ".", "cudnnDropoutBackward", "(", "co", ".", "internal", ",", "dropoutDesc", ".", "internal", ",", "dydesc", ".", "internal", ",", "dy", ".", "Pointer", "(", ")", ",", "dxdesc", ".", "internal", ",", "dx", ".", "Pointer", "(", ")", ",", "reserveSpace", ".", "Pointer", "(", ")", ",", "C", ".", "size_t", "(", "reserveSpaceSizeInBytes", ")", ")", ")", "\n", "}" ]
// DropoutBackward performs backward dropout operation over dy returning results in dx. If during forward dropout operation value from x was propagated to y then during backward operation value from dy will be propagated to dx, otherwise, dx value will be set to 0.
[ "DropoutBackward", "performs", "backward", "dropout", "operation", "over", "dy", "returning", "results", "in", "dx", ".", "If", "during", "forward", "dropout", "operation", "value", "from", "x", "was", "propagated", "to", "y", "then", "during", "backward", "operation", "value", "from", "dy", "will", "be", "propagated", "to", "dx", "otherwise", "dx", "value", "will", "be", "set", "to", "0", "." ]
89152d7e441439045736bc7640ff607ec371c26c
https://github.com/gorgonia/cu/blob/89152d7e441439045736bc7640ff607ec371c26c/dnn/generated_API.go#L755-L759
5,465
gorgonia/cu
dnn/generated_API.go
GetRNNWorkspaceSize
func (co *Context) GetRNNWorkspaceSize(rnnDesc *RNN, seqLength int, xDesc []*TensorDescriptor) (sizeInBytes uintptr, err error) { var sizeInBytesC C.size_t if len(xDesc) != seqLength { return 0, errors.Errorf("Incorrect xDesc length. Want %d. Got %d", seqLength, len(xDesc)) } internals := make([]C.cudnnTensorDescriptor_t, len(xDesc)) for i := range xDesc { internals[i] = xDesc[i].internal } ptr := (*C.cudnnTensorDescriptor_t)(unsafe.Pointer(&internals[0])) // call cudnnGetRNNWorkspaceSize err = result(C.cudnnGetRNNWorkspaceSize(co.internal, rnnDesc.internal, C.int(seqLength), ptr, &sizeInBytesC)) sizeInBytes = uintptr(sizeInBytesC) return }
go
func (co *Context) GetRNNWorkspaceSize(rnnDesc *RNN, seqLength int, xDesc []*TensorDescriptor) (sizeInBytes uintptr, err error) { var sizeInBytesC C.size_t if len(xDesc) != seqLength { return 0, errors.Errorf("Incorrect xDesc length. Want %d. Got %d", seqLength, len(xDesc)) } internals := make([]C.cudnnTensorDescriptor_t, len(xDesc)) for i := range xDesc { internals[i] = xDesc[i].internal } ptr := (*C.cudnnTensorDescriptor_t)(unsafe.Pointer(&internals[0])) // call cudnnGetRNNWorkspaceSize err = result(C.cudnnGetRNNWorkspaceSize(co.internal, rnnDesc.internal, C.int(seqLength), ptr, &sizeInBytesC)) sizeInBytes = uintptr(sizeInBytesC) return }
[ "func", "(", "co", "*", "Context", ")", "GetRNNWorkspaceSize", "(", "rnnDesc", "*", "RNN", ",", "seqLength", "int", ",", "xDesc", "[", "]", "*", "TensorDescriptor", ")", "(", "sizeInBytes", "uintptr", ",", "err", "error", ")", "{", "var", "sizeInBytesC", "C", ".", "size_t", "\n", "if", "len", "(", "xDesc", ")", "!=", "seqLength", "{", "return", "0", ",", "errors", ".", "Errorf", "(", "\"", "\"", ",", "seqLength", ",", "len", "(", "xDesc", ")", ")", "\n", "}", "\n\n", "internals", ":=", "make", "(", "[", "]", "C", ".", "cudnnTensorDescriptor_t", ",", "len", "(", "xDesc", ")", ")", "\n", "for", "i", ":=", "range", "xDesc", "{", "internals", "[", "i", "]", "=", "xDesc", "[", "i", "]", ".", "internal", "\n", "}", "\n", "ptr", ":=", "(", "*", "C", ".", "cudnnTensorDescriptor_t", ")", "(", "unsafe", ".", "Pointer", "(", "&", "internals", "[", "0", "]", ")", ")", "\n\n", "// call cudnnGetRNNWorkspaceSize", "err", "=", "result", "(", "C", ".", "cudnnGetRNNWorkspaceSize", "(", "co", ".", "internal", ",", "rnnDesc", ".", "internal", ",", "C", ".", "int", "(", "seqLength", ")", ",", "ptr", ",", "&", "sizeInBytesC", ")", ")", "\n", "sizeInBytes", "=", "uintptr", "(", "sizeInBytesC", ")", "\n", "return", "\n", "}" ]
// GetRNNWorkspaceSize is used to query the amount of work space required to execute the RNN described by rnnDesc with inputs dimensions defined by xDesc.
[ "GetRNNWorkspaceSize", "is", "used", "to", "query", "the", "amount", "of", "work", "space", "required", "to", "execute", "the", "RNN", "described", "by", "rnnDesc", "with", "inputs", "dimensions", "defined", "by", "xDesc", "." ]
89152d7e441439045736bc7640ff607ec371c26c
https://github.com/gorgonia/cu/blob/89152d7e441439045736bc7640ff607ec371c26c/dnn/generated_API.go#L762-L778
5,466
gorgonia/cu
dnn/generated_API.go
GetRNNParamsSize
func (co *Context) GetRNNParamsSize(rnnDesc *RNN, xDesc *TensorDescriptor, dataType DataType) (sizeInBytes uintptr, err error) { var sizeInBytesC C.size_t // call cudnnGetRNNParamsSize err = result(C.cudnnGetRNNParamsSize(co.internal, rnnDesc.internal, xDesc.internal, &sizeInBytesC, dataType.C())) sizeInBytes = uintptr(sizeInBytesC) return }
go
func (co *Context) GetRNNParamsSize(rnnDesc *RNN, xDesc *TensorDescriptor, dataType DataType) (sizeInBytes uintptr, err error) { var sizeInBytesC C.size_t // call cudnnGetRNNParamsSize err = result(C.cudnnGetRNNParamsSize(co.internal, rnnDesc.internal, xDesc.internal, &sizeInBytesC, dataType.C())) sizeInBytes = uintptr(sizeInBytesC) return }
[ "func", "(", "co", "*", "Context", ")", "GetRNNParamsSize", "(", "rnnDesc", "*", "RNN", ",", "xDesc", "*", "TensorDescriptor", ",", "dataType", "DataType", ")", "(", "sizeInBytes", "uintptr", ",", "err", "error", ")", "{", "var", "sizeInBytesC", "C", ".", "size_t", "\n", "// call cudnnGetRNNParamsSize", "err", "=", "result", "(", "C", ".", "cudnnGetRNNParamsSize", "(", "co", ".", "internal", ",", "rnnDesc", ".", "internal", ",", "xDesc", ".", "internal", ",", "&", "sizeInBytesC", ",", "dataType", ".", "C", "(", ")", ")", ")", "\n", "sizeInBytes", "=", "uintptr", "(", "sizeInBytesC", ")", "\n", "return", "\n", "}" ]
// GetRNNParamsSize is used to query the amount of parameter space required to execute the RNN described by rnnDesc with inputs dimensions defined by xDesc.
[ "GetRNNParamsSize", "is", "used", "to", "query", "the", "amount", "of", "parameter", "space", "required", "to", "execute", "the", "RNN", "described", "by", "rnnDesc", "with", "inputs", "dimensions", "defined", "by", "xDesc", "." ]
89152d7e441439045736bc7640ff607ec371c26c
https://github.com/gorgonia/cu/blob/89152d7e441439045736bc7640ff607ec371c26c/dnn/generated_API.go#L800-L806
5,467
gorgonia/cu
dnn/generated_API.go
RNNBackwardData
func (co *Context) RNNBackwardData(rnnDesc *RNN, seqLength int, yDesc []*TensorDescriptor, y Memory, dyDesc []*TensorDescriptor, dy Memory, dhyDesc *TensorDescriptor, dhy Memory, dcyDesc *TensorDescriptor, dcy Memory, wDesc *Filter, w Memory, hxDesc *TensorDescriptor, hx Memory, cxDesc *TensorDescriptor, cx Memory, dxDesc []*TensorDescriptor, dx Memory, dhxDesc *TensorDescriptor, dhx Memory, dcxDesc *TensorDescriptor, dcx Memory, workspace Memory, workSpaceSizeInBytes uintptr, reserveSpace Memory, reserveSpaceSizeInBytes uintptr) error { // DOUBLECHECK: "cudnnRNNBackwardData" returns Memory type in Parameter 22 internals := make([]C.cudnnTensorDescriptor_t, len(yDesc)) for i := range yDesc { internals[i] = yDesc[i].internal } ptr := (*C.cudnnTensorDescriptor_t)(unsafe.Pointer(&internals[0])) dyInternals := make([]C.cudnnTensorDescriptor_t, len(dyDesc)) for i := range dyDesc { dyInternals[i] = dyDesc[i].internal } dyPtr := (*C.cudnnTensorDescriptor_t)(unsafe.Pointer(&dyInternals[0])) dxInternals := make([]C.cudnnTensorDescriptor_t, len(dxDesc)) for i := range dyDesc { dxInternals[i] = dxDesc[i].internal } dxPtr := (*C.cudnnTensorDescriptor_t)(unsafe.Pointer(&dxInternals[0])) // call cudnnRNNBackwardData return result(C.cudnnRNNBackwardData(co.internal, rnnDesc.internal, C.int(seqLength), ptr, y.Pointer(), dyPtr, dy.Pointer(), dhyDesc.internal, dhy.Pointer(), dcyDesc.internal, dcy.Pointer(), wDesc.internal, w.Pointer(), hxDesc.internal, hx.Pointer(), cxDesc.internal, cx.Pointer(), dxPtr, dx.Pointer(), dhxDesc.internal, dhx.Pointer(), dcxDesc.internal, dcx.Pointer(), workspace.Pointer(), C.size_t(workSpaceSizeInBytes), reserveSpace.Pointer(), C.size_t(reserveSpaceSizeInBytes))) }
go
func (co *Context) RNNBackwardData(rnnDesc *RNN, seqLength int, yDesc []*TensorDescriptor, y Memory, dyDesc []*TensorDescriptor, dy Memory, dhyDesc *TensorDescriptor, dhy Memory, dcyDesc *TensorDescriptor, dcy Memory, wDesc *Filter, w Memory, hxDesc *TensorDescriptor, hx Memory, cxDesc *TensorDescriptor, cx Memory, dxDesc []*TensorDescriptor, dx Memory, dhxDesc *TensorDescriptor, dhx Memory, dcxDesc *TensorDescriptor, dcx Memory, workspace Memory, workSpaceSizeInBytes uintptr, reserveSpace Memory, reserveSpaceSizeInBytes uintptr) error { // DOUBLECHECK: "cudnnRNNBackwardData" returns Memory type in Parameter 22 internals := make([]C.cudnnTensorDescriptor_t, len(yDesc)) for i := range yDesc { internals[i] = yDesc[i].internal } ptr := (*C.cudnnTensorDescriptor_t)(unsafe.Pointer(&internals[0])) dyInternals := make([]C.cudnnTensorDescriptor_t, len(dyDesc)) for i := range dyDesc { dyInternals[i] = dyDesc[i].internal } dyPtr := (*C.cudnnTensorDescriptor_t)(unsafe.Pointer(&dyInternals[0])) dxInternals := make([]C.cudnnTensorDescriptor_t, len(dxDesc)) for i := range dyDesc { dxInternals[i] = dxDesc[i].internal } dxPtr := (*C.cudnnTensorDescriptor_t)(unsafe.Pointer(&dxInternals[0])) // call cudnnRNNBackwardData return result(C.cudnnRNNBackwardData(co.internal, rnnDesc.internal, C.int(seqLength), ptr, y.Pointer(), dyPtr, dy.Pointer(), dhyDesc.internal, dhy.Pointer(), dcyDesc.internal, dcy.Pointer(), wDesc.internal, w.Pointer(), hxDesc.internal, hx.Pointer(), cxDesc.internal, cx.Pointer(), dxPtr, dx.Pointer(), dhxDesc.internal, dhx.Pointer(), dcxDesc.internal, dcx.Pointer(), workspace.Pointer(), C.size_t(workSpaceSizeInBytes), reserveSpace.Pointer(), C.size_t(reserveSpaceSizeInBytes))) }
[ "func", "(", "co", "*", "Context", ")", "RNNBackwardData", "(", "rnnDesc", "*", "RNN", ",", "seqLength", "int", ",", "yDesc", "[", "]", "*", "TensorDescriptor", ",", "y", "Memory", ",", "dyDesc", "[", "]", "*", "TensorDescriptor", ",", "dy", "Memory", ",", "dhyDesc", "*", "TensorDescriptor", ",", "dhy", "Memory", ",", "dcyDesc", "*", "TensorDescriptor", ",", "dcy", "Memory", ",", "wDesc", "*", "Filter", ",", "w", "Memory", ",", "hxDesc", "*", "TensorDescriptor", ",", "hx", "Memory", ",", "cxDesc", "*", "TensorDescriptor", ",", "cx", "Memory", ",", "dxDesc", "[", "]", "*", "TensorDescriptor", ",", "dx", "Memory", ",", "dhxDesc", "*", "TensorDescriptor", ",", "dhx", "Memory", ",", "dcxDesc", "*", "TensorDescriptor", ",", "dcx", "Memory", ",", "workspace", "Memory", ",", "workSpaceSizeInBytes", "uintptr", ",", "reserveSpace", "Memory", ",", "reserveSpaceSizeInBytes", "uintptr", ")", "error", "{", "// DOUBLECHECK: \"cudnnRNNBackwardData\" returns Memory type in Parameter 22", "internals", ":=", "make", "(", "[", "]", "C", ".", "cudnnTensorDescriptor_t", ",", "len", "(", "yDesc", ")", ")", "\n", "for", "i", ":=", "range", "yDesc", "{", "internals", "[", "i", "]", "=", "yDesc", "[", "i", "]", ".", "internal", "\n", "}", "\n", "ptr", ":=", "(", "*", "C", ".", "cudnnTensorDescriptor_t", ")", "(", "unsafe", ".", "Pointer", "(", "&", "internals", "[", "0", "]", ")", ")", "\n\n", "dyInternals", ":=", "make", "(", "[", "]", "C", ".", "cudnnTensorDescriptor_t", ",", "len", "(", "dyDesc", ")", ")", "\n", "for", "i", ":=", "range", "dyDesc", "{", "dyInternals", "[", "i", "]", "=", "dyDesc", "[", "i", "]", ".", "internal", "\n", "}", "\n", "dyPtr", ":=", "(", "*", "C", ".", "cudnnTensorDescriptor_t", ")", "(", "unsafe", ".", "Pointer", "(", "&", "dyInternals", "[", "0", "]", ")", ")", "\n\n", "dxInternals", ":=", "make", "(", "[", "]", "C", ".", "cudnnTensorDescriptor_t", ",", "len", "(", "dxDesc", ")", ")", "\n", "for", "i", ":=", "range", "dyDesc", "{", "dxInternals", "[", "i", "]", "=", "dxDesc", "[", "i", "]", ".", "internal", "\n", "}", "\n", "dxPtr", ":=", "(", "*", "C", ".", "cudnnTensorDescriptor_t", ")", "(", "unsafe", ".", "Pointer", "(", "&", "dxInternals", "[", "0", "]", ")", ")", "\n\n", "// call cudnnRNNBackwardData", "return", "result", "(", "C", ".", "cudnnRNNBackwardData", "(", "co", ".", "internal", ",", "rnnDesc", ".", "internal", ",", "C", ".", "int", "(", "seqLength", ")", ",", "ptr", ",", "y", ".", "Pointer", "(", ")", ",", "dyPtr", ",", "dy", ".", "Pointer", "(", ")", ",", "dhyDesc", ".", "internal", ",", "dhy", ".", "Pointer", "(", ")", ",", "dcyDesc", ".", "internal", ",", "dcy", ".", "Pointer", "(", ")", ",", "wDesc", ".", "internal", ",", "w", ".", "Pointer", "(", ")", ",", "hxDesc", ".", "internal", ",", "hx", ".", "Pointer", "(", ")", ",", "cxDesc", ".", "internal", ",", "cx", ".", "Pointer", "(", ")", ",", "dxPtr", ",", "dx", ".", "Pointer", "(", ")", ",", "dhxDesc", ".", "internal", ",", "dhx", ".", "Pointer", "(", ")", ",", "dcxDesc", ".", "internal", ",", "dcx", ".", "Pointer", "(", ")", ",", "workspace", ".", "Pointer", "(", ")", ",", "C", ".", "size_t", "(", "workSpaceSizeInBytes", ")", ",", "reserveSpace", ".", "Pointer", "(", ")", ",", "C", ".", "size_t", "(", "reserveSpaceSizeInBytes", ")", ")", ")", "\n", "}" ]
// RNNBackwardData executes the recurrent neural network described by rnnDesc with output gradients dy, dhy, dhc, weights w and input gradients dx, dhx, dcx. workspace is required for intermediate storage. The data in reserveSpace must have previously been generated by cudnnRNNForwardTraining. The same reserveSpace data must be used for future calls to cudnnRNNBackwardWeights if they execute on the same input data. // reserveSpace is both an input and output
[ "RNNBackwardData", "executes", "the", "recurrent", "neural", "network", "described", "by", "rnnDesc", "with", "output", "gradients", "dy", "dhy", "dhc", "weights", "w", "and", "input", "gradients", "dx", "dhx", "dcx", ".", "workspace", "is", "required", "for", "intermediate", "storage", ".", "The", "data", "in", "reserveSpace", "must", "have", "previously", "been", "generated", "by", "cudnnRNNForwardTraining", ".", "The", "same", "reserveSpace", "data", "must", "be", "used", "for", "future", "calls", "to", "cudnnRNNBackwardWeights", "if", "they", "execute", "on", "the", "same", "input", "data", ".", "reserveSpace", "is", "both", "an", "input", "and", "output" ]
89152d7e441439045736bc7640ff607ec371c26c
https://github.com/gorgonia/cu/blob/89152d7e441439045736bc7640ff607ec371c26c/dnn/generated_API.go#L870-L892
5,468
gorgonia/cu
dnn/generated_API.go
RNNBackwardWeights
func (co *Context) RNNBackwardWeights(rnnDesc *RNN, seqLength int, xDesc []*TensorDescriptor, x Memory, hxDesc *TensorDescriptor, hx Memory, yDesc []*TensorDescriptor, y Memory, workspace Memory, workSpaceSizeInBytes uintptr, dwDesc *Filter, dw Memory, reserveSpace Memory, reserveSpaceSizeInBytes uintptr) error { internals := make([]C.cudnnTensorDescriptor_t, len(xDesc)) for i := range xDesc { internals[i] = xDesc[i].internal } ptr := (*C.cudnnTensorDescriptor_t)(unsafe.Pointer(&internals[0])) yDescInternals := make([]C.cudnnTensorDescriptor_t, len(xDesc)) for i := range yDesc { yDescInternals[i] = yDesc[i].internal } yDescPtr := (*C.cudnnTensorDescriptor_t)(unsafe.Pointer(&yDescInternals[0])) // call cudnnRNNBackwardWeights return result(C.cudnnRNNBackwardWeights(co.internal, rnnDesc.internal, C.int(seqLength), ptr, x.Pointer(), hxDesc.internal, hx.Pointer(), yDescPtr, y.Pointer(), workspace.Pointer(), C.size_t(workSpaceSizeInBytes), dwDesc.internal, dw.Pointer(), reserveSpace.Pointer(), C.size_t(reserveSpaceSizeInBytes))) }
go
func (co *Context) RNNBackwardWeights(rnnDesc *RNN, seqLength int, xDesc []*TensorDescriptor, x Memory, hxDesc *TensorDescriptor, hx Memory, yDesc []*TensorDescriptor, y Memory, workspace Memory, workSpaceSizeInBytes uintptr, dwDesc *Filter, dw Memory, reserveSpace Memory, reserveSpaceSizeInBytes uintptr) error { internals := make([]C.cudnnTensorDescriptor_t, len(xDesc)) for i := range xDesc { internals[i] = xDesc[i].internal } ptr := (*C.cudnnTensorDescriptor_t)(unsafe.Pointer(&internals[0])) yDescInternals := make([]C.cudnnTensorDescriptor_t, len(xDesc)) for i := range yDesc { yDescInternals[i] = yDesc[i].internal } yDescPtr := (*C.cudnnTensorDescriptor_t)(unsafe.Pointer(&yDescInternals[0])) // call cudnnRNNBackwardWeights return result(C.cudnnRNNBackwardWeights(co.internal, rnnDesc.internal, C.int(seqLength), ptr, x.Pointer(), hxDesc.internal, hx.Pointer(), yDescPtr, y.Pointer(), workspace.Pointer(), C.size_t(workSpaceSizeInBytes), dwDesc.internal, dw.Pointer(), reserveSpace.Pointer(), C.size_t(reserveSpaceSizeInBytes))) }
[ "func", "(", "co", "*", "Context", ")", "RNNBackwardWeights", "(", "rnnDesc", "*", "RNN", ",", "seqLength", "int", ",", "xDesc", "[", "]", "*", "TensorDescriptor", ",", "x", "Memory", ",", "hxDesc", "*", "TensorDescriptor", ",", "hx", "Memory", ",", "yDesc", "[", "]", "*", "TensorDescriptor", ",", "y", "Memory", ",", "workspace", "Memory", ",", "workSpaceSizeInBytes", "uintptr", ",", "dwDesc", "*", "Filter", ",", "dw", "Memory", ",", "reserveSpace", "Memory", ",", "reserveSpaceSizeInBytes", "uintptr", ")", "error", "{", "internals", ":=", "make", "(", "[", "]", "C", ".", "cudnnTensorDescriptor_t", ",", "len", "(", "xDesc", ")", ")", "\n", "for", "i", ":=", "range", "xDesc", "{", "internals", "[", "i", "]", "=", "xDesc", "[", "i", "]", ".", "internal", "\n", "}", "\n", "ptr", ":=", "(", "*", "C", ".", "cudnnTensorDescriptor_t", ")", "(", "unsafe", ".", "Pointer", "(", "&", "internals", "[", "0", "]", ")", ")", "\n\n", "yDescInternals", ":=", "make", "(", "[", "]", "C", ".", "cudnnTensorDescriptor_t", ",", "len", "(", "xDesc", ")", ")", "\n", "for", "i", ":=", "range", "yDesc", "{", "yDescInternals", "[", "i", "]", "=", "yDesc", "[", "i", "]", ".", "internal", "\n", "}", "\n", "yDescPtr", ":=", "(", "*", "C", ".", "cudnnTensorDescriptor_t", ")", "(", "unsafe", ".", "Pointer", "(", "&", "yDescInternals", "[", "0", "]", ")", ")", "\n\n", "// call cudnnRNNBackwardWeights", "return", "result", "(", "C", ".", "cudnnRNNBackwardWeights", "(", "co", ".", "internal", ",", "rnnDesc", ".", "internal", ",", "C", ".", "int", "(", "seqLength", ")", ",", "ptr", ",", "x", ".", "Pointer", "(", ")", ",", "hxDesc", ".", "internal", ",", "hx", ".", "Pointer", "(", ")", ",", "yDescPtr", ",", "y", ".", "Pointer", "(", ")", ",", "workspace", ".", "Pointer", "(", ")", ",", "C", ".", "size_t", "(", "workSpaceSizeInBytes", ")", ",", "dwDesc", ".", "internal", ",", "dw", ".", "Pointer", "(", ")", ",", "reserveSpace", ".", "Pointer", "(", ")", ",", "C", ".", "size_t", "(", "reserveSpaceSizeInBytes", ")", ")", ")", "\n", "}" ]
// RNNBackwardWeights accumulates weight gradients dw from the recurrent neural network described by rnnDesc with inputs x, hx, and outputs y. The mode of operation in this case is additive, the weight gradients calculated will be added to those already existing in dw. workspace is required for intermediate storage. The data in reserveSpace must have previously been generated by cudnnRNNBackwardData. // dw is both an input and output
[ "RNNBackwardWeights", "accumulates", "weight", "gradients", "dw", "from", "the", "recurrent", "neural", "network", "described", "by", "rnnDesc", "with", "inputs", "x", "hx", "and", "outputs", "y", ".", "The", "mode", "of", "operation", "in", "this", "case", "is", "additive", "the", "weight", "gradients", "calculated", "will", "be", "added", "to", "those", "already", "existing", "in", "dw", ".", "workspace", "is", "required", "for", "intermediate", "storage", ".", "The", "data", "in", "reserveSpace", "must", "have", "previously", "been", "generated", "by", "cudnnRNNBackwardData", ".", "dw", "is", "both", "an", "input", "and", "output" ]
89152d7e441439045736bc7640ff607ec371c26c
https://github.com/gorgonia/cu/blob/89152d7e441439045736bc7640ff607ec371c26c/dnn/generated_API.go#L896-L911
5,469
gorgonia/cu
dnn/generated_API.go
CTCLoss
func (co *Context) CTCLoss(probsDesc *TensorDescriptor, probs Memory, labels []int, labelLengths []int, inputLengths []int, costs Memory, gradientsDesc *TensorDescriptor, gradients Memory, algo CTCLossAlgo, ctcLossDesc *CTCLoss, workspace Memory, workSpaceSizeInBytes uintptr) error { // DOUBLECHECK: "cudnnCTCLoss" returns Memory type in Parameter 8 labelsPtr, labelsPtrManaged := ints2CIntPtr(labels) defer returnManaged(labelsPtrManaged) labelLengthsPtr, labelLengthsPtrManaged := ints2CIntPtr(labelLengths) defer returnManaged(labelLengthsPtrManaged) inputLengthsPtr, inputLengthsPtrManaged := ints2CIntPtr(inputLengths) defer returnManaged(inputLengthsPtrManaged) // call cudnnCTCLoss return result(C.cudnnCTCLoss(co.internal, probsDesc.internal, probs.Pointer(), labelsPtr, labelLengthsPtr, inputLengthsPtr, costs.Pointer(), gradientsDesc.internal, gradients.Pointer(), algo.C(), ctcLossDesc.internal, workspace.Pointer(), C.size_t(workSpaceSizeInBytes))) }
go
func (co *Context) CTCLoss(probsDesc *TensorDescriptor, probs Memory, labels []int, labelLengths []int, inputLengths []int, costs Memory, gradientsDesc *TensorDescriptor, gradients Memory, algo CTCLossAlgo, ctcLossDesc *CTCLoss, workspace Memory, workSpaceSizeInBytes uintptr) error { // DOUBLECHECK: "cudnnCTCLoss" returns Memory type in Parameter 8 labelsPtr, labelsPtrManaged := ints2CIntPtr(labels) defer returnManaged(labelsPtrManaged) labelLengthsPtr, labelLengthsPtrManaged := ints2CIntPtr(labelLengths) defer returnManaged(labelLengthsPtrManaged) inputLengthsPtr, inputLengthsPtrManaged := ints2CIntPtr(inputLengths) defer returnManaged(inputLengthsPtrManaged) // call cudnnCTCLoss return result(C.cudnnCTCLoss(co.internal, probsDesc.internal, probs.Pointer(), labelsPtr, labelLengthsPtr, inputLengthsPtr, costs.Pointer(), gradientsDesc.internal, gradients.Pointer(), algo.C(), ctcLossDesc.internal, workspace.Pointer(), C.size_t(workSpaceSizeInBytes))) }
[ "func", "(", "co", "*", "Context", ")", "CTCLoss", "(", "probsDesc", "*", "TensorDescriptor", ",", "probs", "Memory", ",", "labels", "[", "]", "int", ",", "labelLengths", "[", "]", "int", ",", "inputLengths", "[", "]", "int", ",", "costs", "Memory", ",", "gradientsDesc", "*", "TensorDescriptor", ",", "gradients", "Memory", ",", "algo", "CTCLossAlgo", ",", "ctcLossDesc", "*", "CTCLoss", ",", "workspace", "Memory", ",", "workSpaceSizeInBytes", "uintptr", ")", "error", "{", "// DOUBLECHECK: \"cudnnCTCLoss\" returns Memory type in Parameter 8", "labelsPtr", ",", "labelsPtrManaged", ":=", "ints2CIntPtr", "(", "labels", ")", "\n", "defer", "returnManaged", "(", "labelsPtrManaged", ")", "\n", "labelLengthsPtr", ",", "labelLengthsPtrManaged", ":=", "ints2CIntPtr", "(", "labelLengths", ")", "\n", "defer", "returnManaged", "(", "labelLengthsPtrManaged", ")", "\n", "inputLengthsPtr", ",", "inputLengthsPtrManaged", ":=", "ints2CIntPtr", "(", "inputLengths", ")", "\n", "defer", "returnManaged", "(", "inputLengthsPtrManaged", ")", "\n\n", "// call cudnnCTCLoss", "return", "result", "(", "C", ".", "cudnnCTCLoss", "(", "co", ".", "internal", ",", "probsDesc", ".", "internal", ",", "probs", ".", "Pointer", "(", ")", ",", "labelsPtr", ",", "labelLengthsPtr", ",", "inputLengthsPtr", ",", "costs", ".", "Pointer", "(", ")", ",", "gradientsDesc", ".", "internal", ",", "gradients", ".", "Pointer", "(", ")", ",", "algo", ".", "C", "(", ")", ",", "ctcLossDesc", ".", "internal", ",", "workspace", ".", "Pointer", "(", ")", ",", "C", ".", "size_t", "(", "workSpaceSizeInBytes", ")", ")", ")", "\n", "}" ]
// CTCLoss returns the ctc costs and gradients, given the probabilities and labels.
[ "CTCLoss", "returns", "the", "ctc", "costs", "and", "gradients", "given", "the", "probabilities", "and", "labels", "." ]
89152d7e441439045736bc7640ff607ec371c26c
https://github.com/gorgonia/cu/blob/89152d7e441439045736bc7640ff607ec371c26c/dnn/generated_API.go#L914-L925
5,470
gorgonia/cu
batchedPatterns.go
LaunchAndSync
func (fn Function) LaunchAndSync(gridDimX, gridDimY, gridDimZ, blockDimX, blockDimY, blockDimZ, sharedMemBytes int, stream Stream, kernelParams []unsafe.Pointer) error { argv := C.malloc(C.size_t(len(kernelParams) * pointerSize)) argp := C.malloc(C.size_t(len(kernelParams) * pointerSize)) defer C.free(argv) defer C.free(argp) for i := range kernelParams { *((*unsafe.Pointer)(offset(argp, i))) = offset(argv, i) // argp[i] = &argv[i] *((*uint64)(offset(argv, i))) = *((*uint64)(kernelParams[i])) // argv[i] = *kernelParams[i] } err := result(C.cuLaunchAndSync( fn.fn, C.uint(gridDimX), C.uint(gridDimY), C.uint(gridDimZ), C.uint(blockDimX), C.uint(blockDimY), C.uint(blockDimZ), C.uint(sharedMemBytes), stream.c(), (*unsafe.Pointer)(argp), (*unsafe.Pointer)(nil))) return err }
go
func (fn Function) LaunchAndSync(gridDimX, gridDimY, gridDimZ, blockDimX, blockDimY, blockDimZ, sharedMemBytes int, stream Stream, kernelParams []unsafe.Pointer) error { argv := C.malloc(C.size_t(len(kernelParams) * pointerSize)) argp := C.malloc(C.size_t(len(kernelParams) * pointerSize)) defer C.free(argv) defer C.free(argp) for i := range kernelParams { *((*unsafe.Pointer)(offset(argp, i))) = offset(argv, i) // argp[i] = &argv[i] *((*uint64)(offset(argv, i))) = *((*uint64)(kernelParams[i])) // argv[i] = *kernelParams[i] } err := result(C.cuLaunchAndSync( fn.fn, C.uint(gridDimX), C.uint(gridDimY), C.uint(gridDimZ), C.uint(blockDimX), C.uint(blockDimY), C.uint(blockDimZ), C.uint(sharedMemBytes), stream.c(), (*unsafe.Pointer)(argp), (*unsafe.Pointer)(nil))) return err }
[ "func", "(", "fn", "Function", ")", "LaunchAndSync", "(", "gridDimX", ",", "gridDimY", ",", "gridDimZ", ",", "blockDimX", ",", "blockDimY", ",", "blockDimZ", ",", "sharedMemBytes", "int", ",", "stream", "Stream", ",", "kernelParams", "[", "]", "unsafe", ".", "Pointer", ")", "error", "{", "argv", ":=", "C", ".", "malloc", "(", "C", ".", "size_t", "(", "len", "(", "kernelParams", ")", "*", "pointerSize", ")", ")", "\n", "argp", ":=", "C", ".", "malloc", "(", "C", ".", "size_t", "(", "len", "(", "kernelParams", ")", "*", "pointerSize", ")", ")", "\n", "defer", "C", ".", "free", "(", "argv", ")", "\n", "defer", "C", ".", "free", "(", "argp", ")", "\n", "for", "i", ":=", "range", "kernelParams", "{", "*", "(", "(", "*", "unsafe", ".", "Pointer", ")", "(", "offset", "(", "argp", ",", "i", ")", ")", ")", "=", "offset", "(", "argv", ",", "i", ")", "// argp[i] = &argv[i]", "\n", "*", "(", "(", "*", "uint64", ")", "(", "offset", "(", "argv", ",", "i", ")", ")", ")", "=", "*", "(", "(", "*", "uint64", ")", "(", "kernelParams", "[", "i", "]", ")", ")", "// argv[i] = *kernelParams[i]", "\n", "}", "\n\n", "err", ":=", "result", "(", "C", ".", "cuLaunchAndSync", "(", "fn", ".", "fn", ",", "C", ".", "uint", "(", "gridDimX", ")", ",", "C", ".", "uint", "(", "gridDimY", ")", ",", "C", ".", "uint", "(", "gridDimZ", ")", ",", "C", ".", "uint", "(", "blockDimX", ")", ",", "C", ".", "uint", "(", "blockDimY", ")", ",", "C", ".", "uint", "(", "blockDimZ", ")", ",", "C", ".", "uint", "(", "sharedMemBytes", ")", ",", "stream", ".", "c", "(", ")", ",", "(", "*", "unsafe", ".", "Pointer", ")", "(", "argp", ")", ",", "(", "*", "unsafe", ".", "Pointer", ")", "(", "nil", ")", ")", ")", "\n", "return", "err", "\n", "}" ]
// LaunchAndSync launches the kernel and synchronizes the context
[ "LaunchAndSync", "launches", "the", "kernel", "and", "synchronizes", "the", "context" ]
89152d7e441439045736bc7640ff607ec371c26c
https://github.com/gorgonia/cu/blob/89152d7e441439045736bc7640ff607ec371c26c/batchedPatterns.go#L37-L60
5,471
gorgonia/cu
batchedPatterns.go
AllocAndCopy
func AllocAndCopy(p unsafe.Pointer, bytesize int64) (DevicePtr, error) { if bytesize == 0 { return 0, errors.Wrapf(InvalidValue, "Cannot allocate memory with size 0") } var d C.CUdeviceptr if err := result(C.cuAllocAndCopy(&d, p, C.size_t(bytesize))); err != nil { return 0, errors.Wrapf(err, "AllocAndCopy") } return DevicePtr(d), nil }
go
func AllocAndCopy(p unsafe.Pointer, bytesize int64) (DevicePtr, error) { if bytesize == 0 { return 0, errors.Wrapf(InvalidValue, "Cannot allocate memory with size 0") } var d C.CUdeviceptr if err := result(C.cuAllocAndCopy(&d, p, C.size_t(bytesize))); err != nil { return 0, errors.Wrapf(err, "AllocAndCopy") } return DevicePtr(d), nil }
[ "func", "AllocAndCopy", "(", "p", "unsafe", ".", "Pointer", ",", "bytesize", "int64", ")", "(", "DevicePtr", ",", "error", ")", "{", "if", "bytesize", "==", "0", "{", "return", "0", ",", "errors", ".", "Wrapf", "(", "InvalidValue", ",", "\"", "\"", ")", "\n", "}", "\n\n", "var", "d", "C", ".", "CUdeviceptr", "\n", "if", "err", ":=", "result", "(", "C", ".", "cuAllocAndCopy", "(", "&", "d", ",", "p", ",", "C", ".", "size_t", "(", "bytesize", ")", ")", ")", ";", "err", "!=", "nil", "{", "return", "0", ",", "errors", ".", "Wrapf", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n", "return", "DevicePtr", "(", "d", ")", ",", "nil", "\n", "}" ]
// AllocAndCopy abstracts away the common pattern of allocating and then copying a Go slice to the GPU
[ "AllocAndCopy", "abstracts", "away", "the", "common", "pattern", "of", "allocating", "and", "then", "copying", "a", "Go", "slice", "to", "the", "GPU" ]
89152d7e441439045736bc7640ff607ec371c26c
https://github.com/gorgonia/cu/blob/89152d7e441439045736bc7640ff607ec371c26c/batchedPatterns.go#L63-L73
5,472
gorgonia/cu
batch.go
NewBatchedContext
func NewBatchedContext(c Context, d Device) *BatchedContext { return &BatchedContext{ Context: c, Device: d, workAvailable: make(chan struct{}, 1), work: make(chan call, workBufLen), queue: make([]call, 0, workBufLen), fns: make([]C.uintptr_t, 0, workBufLen), results: make([]C.CUresult, workBufLen), frees: make([]unsafe.Pointer, 0, 2*workBufLen), retVal: make(chan DevicePtr), initialized: true, } }
go
func NewBatchedContext(c Context, d Device) *BatchedContext { return &BatchedContext{ Context: c, Device: d, workAvailable: make(chan struct{}, 1), work: make(chan call, workBufLen), queue: make([]call, 0, workBufLen), fns: make([]C.uintptr_t, 0, workBufLen), results: make([]C.CUresult, workBufLen), frees: make([]unsafe.Pointer, 0, 2*workBufLen), retVal: make(chan DevicePtr), initialized: true, } }
[ "func", "NewBatchedContext", "(", "c", "Context", ",", "d", "Device", ")", "*", "BatchedContext", "{", "return", "&", "BatchedContext", "{", "Context", ":", "c", ",", "Device", ":", "d", ",", "workAvailable", ":", "make", "(", "chan", "struct", "{", "}", ",", "1", ")", ",", "work", ":", "make", "(", "chan", "call", ",", "workBufLen", ")", ",", "queue", ":", "make", "(", "[", "]", "call", ",", "0", ",", "workBufLen", ")", ",", "fns", ":", "make", "(", "[", "]", "C", ".", "uintptr_t", ",", "0", ",", "workBufLen", ")", ",", "results", ":", "make", "(", "[", "]", "C", ".", "CUresult", ",", "workBufLen", ")", ",", "frees", ":", "make", "(", "[", "]", "unsafe", ".", "Pointer", ",", "0", ",", "2", "*", "workBufLen", ")", ",", "retVal", ":", "make", "(", "chan", "DevicePtr", ")", ",", "initialized", ":", "true", ",", "}", "\n", "}" ]
// NewBatchedContext creates a batched CUDA context.
[ "NewBatchedContext", "creates", "a", "batched", "CUDA", "context", "." ]
89152d7e441439045736bc7640ff607ec371c26c
https://github.com/gorgonia/cu/blob/89152d7e441439045736bc7640ff607ec371c26c/batch.go#L154-L168
5,473
gorgonia/cu
batch.go
Run
func (ctx *BatchedContext) Run(errChan chan error) error { runtime.LockOSThread() defer runtime.UnlockOSThread() for { select { case <-ctx.workAvailable: ctx.DoWork() if err := ctx.Errors(); err != nil { if errChan == nil { return err } errChan <- err } case w := <-ctx.Work(): ctx.ErrChan() <- w() } } }
go
func (ctx *BatchedContext) Run(errChan chan error) error { runtime.LockOSThread() defer runtime.UnlockOSThread() for { select { case <-ctx.workAvailable: ctx.DoWork() if err := ctx.Errors(); err != nil { if errChan == nil { return err } errChan <- err } case w := <-ctx.Work(): ctx.ErrChan() <- w() } } }
[ "func", "(", "ctx", "*", "BatchedContext", ")", "Run", "(", "errChan", "chan", "error", ")", "error", "{", "runtime", ".", "LockOSThread", "(", ")", "\n", "defer", "runtime", ".", "UnlockOSThread", "(", ")", "\n", "for", "{", "select", "{", "case", "<-", "ctx", ".", "workAvailable", ":", "ctx", ".", "DoWork", "(", ")", "\n", "if", "err", ":=", "ctx", ".", "Errors", "(", ")", ";", "err", "!=", "nil", "{", "if", "errChan", "==", "nil", "{", "return", "err", "\n", "}", "\n", "errChan", "<-", "err", "\n\n", "}", "\n", "case", "w", ":=", "<-", "ctx", ".", "Work", "(", ")", ":", "ctx", ".", "ErrChan", "(", ")", "<-", "w", "(", ")", "\n", "}", "\n", "}", "\n", "}" ]
// Run manages the running of the BatchedContext. Because it's expected to run in a goroutine, an error channel is to be passed in
[ "Run", "manages", "the", "running", "of", "the", "BatchedContext", ".", "Because", "it", "s", "expected", "to", "run", "in", "a", "goroutine", "an", "error", "channel", "is", "to", "be", "passed", "in" ]
89152d7e441439045736bc7640ff607ec371c26c
https://github.com/gorgonia/cu/blob/89152d7e441439045736bc7640ff607ec371c26c/batch.go#L272-L290
5,474
gorgonia/cu
batch.go
Cleanup
func (ctx *BatchedContext) Cleanup() { for i, f := range ctx.frees { C.free(f) ctx.frees[i] = nil } ctx.frees = ctx.frees[:0] }
go
func (ctx *BatchedContext) Cleanup() { for i, f := range ctx.frees { C.free(f) ctx.frees[i] = nil } ctx.frees = ctx.frees[:0] }
[ "func", "(", "ctx", "*", "BatchedContext", ")", "Cleanup", "(", ")", "{", "for", "i", ",", "f", ":=", "range", "ctx", ".", "frees", "{", "C", ".", "free", "(", "f", ")", "\n", "ctx", ".", "frees", "[", "i", "]", "=", "nil", "\n", "}", "\n", "ctx", ".", "frees", "=", "ctx", ".", "frees", "[", ":", "0", "]", "\n", "}" ]
// Cleanup is the cleanup function. It cleans up all the ancilliary allocations that has happened for all the batched calls. // This method should be called when the context is done with - otherwise there'd be a lot of leaked memory. // // The main reason why this method exists is because there is no way to reliably free memory without causing weird issues in the CUDA calls.
[ "Cleanup", "is", "the", "cleanup", "function", ".", "It", "cleans", "up", "all", "the", "ancilliary", "allocations", "that", "has", "happened", "for", "all", "the", "batched", "calls", ".", "This", "method", "should", "be", "called", "when", "the", "context", "is", "done", "with", "-", "otherwise", "there", "d", "be", "a", "lot", "of", "leaked", "memory", ".", "The", "main", "reason", "why", "this", "method", "exists", "is", "because", "there", "is", "no", "way", "to", "reliably", "free", "memory", "without", "causing", "weird", "issues", "in", "the", "CUDA", "calls", "." ]
89152d7e441439045736bc7640ff607ec371c26c
https://github.com/gorgonia/cu/blob/89152d7e441439045736bc7640ff607ec371c26c/batch.go#L296-L302
5,475
gorgonia/cu
batch.go
Close
func (ctx *BatchedContext) Close() error { ctx.initialized = false return ctx.Context.Close() }
go
func (ctx *BatchedContext) Close() error { ctx.initialized = false return ctx.Context.Close() }
[ "func", "(", "ctx", "*", "BatchedContext", ")", "Close", "(", ")", "error", "{", "ctx", ".", "initialized", "=", "false", "\n", "return", "ctx", ".", "Context", ".", "Close", "(", ")", "\n", "}" ]
// Close closes the batched context
[ "Close", "closes", "the", "batched", "context" ]
89152d7e441439045736bc7640ff607ec371c26c
https://github.com/gorgonia/cu/blob/89152d7e441439045736bc7640ff607ec371c26c/batch.go#L305-L308
5,476
gorgonia/cu
batch.go
FirstError
func (ctx *BatchedContext) FirstError() error { for i, v := range ctx.results { if cuResult(v) != Success { return result(v) } ctx.results[i] = C.CUDA_SUCCESS } return nil }
go
func (ctx *BatchedContext) FirstError() error { for i, v := range ctx.results { if cuResult(v) != Success { return result(v) } ctx.results[i] = C.CUDA_SUCCESS } return nil }
[ "func", "(", "ctx", "*", "BatchedContext", ")", "FirstError", "(", ")", "error", "{", "for", "i", ",", "v", ":=", "range", "ctx", ".", "results", "{", "if", "cuResult", "(", "v", ")", "!=", "Success", "{", "return", "result", "(", "v", ")", "\n", "}", "\n", "ctx", ".", "results", "[", "i", "]", "=", "C", ".", "CUDA_SUCCESS", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// FirstError returns the first error if there was any
[ "FirstError", "returns", "the", "first", "error", "if", "there", "was", "any" ]
89152d7e441439045736bc7640ff607ec371c26c
https://github.com/gorgonia/cu/blob/89152d7e441439045736bc7640ff607ec371c26c/batch.go#L314-L322
5,477
gorgonia/cu
batch.go
SetCurrent
func (ctx *BatchedContext) SetCurrent() { fn := &fnargs{ fn: C.fn_setCurrent, ctx: ctx.CUDAContext().ctx, } c := call{fn, false} ctx.enqueue(c) }
go
func (ctx *BatchedContext) SetCurrent() { fn := &fnargs{ fn: C.fn_setCurrent, ctx: ctx.CUDAContext().ctx, } c := call{fn, false} ctx.enqueue(c) }
[ "func", "(", "ctx", "*", "BatchedContext", ")", "SetCurrent", "(", ")", "{", "fn", ":=", "&", "fnargs", "{", "fn", ":", "C", ".", "fn_setCurrent", ",", "ctx", ":", "ctx", ".", "CUDAContext", "(", ")", ".", "ctx", ",", "}", "\n", "c", ":=", "call", "{", "fn", ",", "false", "}", "\n", "ctx", ".", "enqueue", "(", "c", ")", "\n", "}" ]
// SetCurrent sets the current context. This is usually unnecessary because SetCurrent will be called before batch processing the calls.
[ "SetCurrent", "sets", "the", "current", "context", ".", "This", "is", "usually", "unnecessary", "because", "SetCurrent", "will", "be", "called", "before", "batch", "processing", "the", "calls", "." ]
89152d7e441439045736bc7640ff607ec371c26c
https://github.com/gorgonia/cu/blob/89152d7e441439045736bc7640ff607ec371c26c/batch.go#L325-L332
5,478
gorgonia/cu
batch.go
MemAlloc
func (ctx *BatchedContext) MemAlloc(bytesize int64) (retVal DevicePtr, err error) { fn := &fnargs{ fn: C.fn_mallocD, size: C.size_t(bytesize), } c := call{fn, true} return ctx.enqueue(c) }
go
func (ctx *BatchedContext) MemAlloc(bytesize int64) (retVal DevicePtr, err error) { fn := &fnargs{ fn: C.fn_mallocD, size: C.size_t(bytesize), } c := call{fn, true} return ctx.enqueue(c) }
[ "func", "(", "ctx", "*", "BatchedContext", ")", "MemAlloc", "(", "bytesize", "int64", ")", "(", "retVal", "DevicePtr", ",", "err", "error", ")", "{", "fn", ":=", "&", "fnargs", "{", "fn", ":", "C", ".", "fn_mallocD", ",", "size", ":", "C", ".", "size_t", "(", "bytesize", ")", ",", "}", "\n", "c", ":=", "call", "{", "fn", ",", "true", "}", "\n", "return", "ctx", ".", "enqueue", "(", "c", ")", "\n", "}" ]
// MemAlloc allocates memory. It is a blocking call.
[ "MemAlloc", "allocates", "memory", ".", "It", "is", "a", "blocking", "call", "." ]
89152d7e441439045736bc7640ff607ec371c26c
https://github.com/gorgonia/cu/blob/89152d7e441439045736bc7640ff607ec371c26c/batch.go#L335-L342
5,479
gorgonia/cu
batch.go
errors
func (ctx *BatchedContext) errors() error { if !ctx.checkResults() { return nil } err := make(errorSlice, len(ctx.results)) for i, res := range ctx.results { err[i] = result(res) } return err }
go
func (ctx *BatchedContext) errors() error { if !ctx.checkResults() { return nil } err := make(errorSlice, len(ctx.results)) for i, res := range ctx.results { err[i] = result(res) } return err }
[ "func", "(", "ctx", "*", "BatchedContext", ")", "errors", "(", ")", "error", "{", "if", "!", "ctx", ".", "checkResults", "(", ")", "{", "return", "nil", "\n", "}", "\n", "err", ":=", "make", "(", "errorSlice", ",", "len", "(", "ctx", ".", "results", ")", ")", "\n", "for", "i", ",", "res", ":=", "range", "ctx", ".", "results", "{", "err", "[", "i", "]", "=", "result", "(", "res", ")", "\n", "}", "\n", "return", "err", "\n", "}" ]
// errors convert ctx.results into errors
[ "errors", "convert", "ctx", ".", "results", "into", "errors" ]
89152d7e441439045736bc7640ff607ec371c26c
https://github.com/gorgonia/cu/blob/89152d7e441439045736bc7640ff607ec371c26c/batch.go#L470-L479
5,480
gorgonia/cu
batch.go
introspect
func (ctx *BatchedContext) introspect() string { var buf bytes.Buffer fmt.Fprintf(&buf, "Queue: %d", len(ctx.queue)) for _, v := range ctx.queue { fmt.Fprintf(&buf, "\n\t[QUEUE] %s", v.fnargs) } return buf.String() }
go
func (ctx *BatchedContext) introspect() string { var buf bytes.Buffer fmt.Fprintf(&buf, "Queue: %d", len(ctx.queue)) for _, v := range ctx.queue { fmt.Fprintf(&buf, "\n\t[QUEUE] %s", v.fnargs) } return buf.String() }
[ "func", "(", "ctx", "*", "BatchedContext", ")", "introspect", "(", ")", "string", "{", "var", "buf", "bytes", ".", "Buffer", "\n", "fmt", ".", "Fprintf", "(", "&", "buf", ",", "\"", "\"", ",", "len", "(", "ctx", ".", "queue", ")", ")", "\n", "for", "_", ",", "v", ":=", "range", "ctx", ".", "queue", "{", "fmt", ".", "Fprintf", "(", "&", "buf", ",", "\"", "\\n", "\\t", "\"", ",", "v", ".", "fnargs", ")", "\n", "}", "\n", "return", "buf", ".", "String", "(", ")", "\n", "}" ]
// introspect is useful for finding out what calls are going to be made in the batched call
[ "introspect", "is", "useful", "for", "finding", "out", "what", "calls", "are", "going", "to", "be", "made", "in", "the", "batched", "call" ]
89152d7e441439045736bc7640ff607ec371c26c
https://github.com/gorgonia/cu/blob/89152d7e441439045736bc7640ff607ec371c26c/batch.go#L482-L489
5,481
gorgonia/cu
dnn/generated_lrn.go
NewLRN
func NewLRN(lrnN uint, lrnAlpha float64, lrnBeta float64, lrnK float64) (retVal *LRN, err error) { var internal C.cudnnLRNDescriptor_t if err := result(C.cudnnCreateLRNDescriptor(&internal)); err != nil { return nil, err } if err := result(C.cudnnSetLRNDescriptor(internal, C.uint(lrnN), C.double(lrnAlpha), C.double(lrnBeta), C.double(lrnK))); err != nil { return nil, err } retVal = &LRN{ internal: internal, lrnN: lrnN, lrnAlpha: lrnAlpha, lrnBeta: lrnBeta, lrnK: lrnK, } runtime.SetFinalizer(retVal, destroyLRN) return retVal, nil }
go
func NewLRN(lrnN uint, lrnAlpha float64, lrnBeta float64, lrnK float64) (retVal *LRN, err error) { var internal C.cudnnLRNDescriptor_t if err := result(C.cudnnCreateLRNDescriptor(&internal)); err != nil { return nil, err } if err := result(C.cudnnSetLRNDescriptor(internal, C.uint(lrnN), C.double(lrnAlpha), C.double(lrnBeta), C.double(lrnK))); err != nil { return nil, err } retVal = &LRN{ internal: internal, lrnN: lrnN, lrnAlpha: lrnAlpha, lrnBeta: lrnBeta, lrnK: lrnK, } runtime.SetFinalizer(retVal, destroyLRN) return retVal, nil }
[ "func", "NewLRN", "(", "lrnN", "uint", ",", "lrnAlpha", "float64", ",", "lrnBeta", "float64", ",", "lrnK", "float64", ")", "(", "retVal", "*", "LRN", ",", "err", "error", ")", "{", "var", "internal", "C", ".", "cudnnLRNDescriptor_t", "\n", "if", "err", ":=", "result", "(", "C", ".", "cudnnCreateLRNDescriptor", "(", "&", "internal", ")", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "if", "err", ":=", "result", "(", "C", ".", "cudnnSetLRNDescriptor", "(", "internal", ",", "C", ".", "uint", "(", "lrnN", ")", ",", "C", ".", "double", "(", "lrnAlpha", ")", ",", "C", ".", "double", "(", "lrnBeta", ")", ",", "C", ".", "double", "(", "lrnK", ")", ")", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "retVal", "=", "&", "LRN", "{", "internal", ":", "internal", ",", "lrnN", ":", "lrnN", ",", "lrnAlpha", ":", "lrnAlpha", ",", "lrnBeta", ":", "lrnBeta", ",", "lrnK", ":", "lrnK", ",", "}", "\n", "runtime", ".", "SetFinalizer", "(", "retVal", ",", "destroyLRN", ")", "\n", "return", "retVal", ",", "nil", "\n", "}" ]
// NewLRN creates a new LRN.
[ "NewLRN", "creates", "a", "new", "LRN", "." ]
89152d7e441439045736bc7640ff607ec371c26c
https://github.com/gorgonia/cu/blob/89152d7e441439045736bc7640ff607ec371c26c/dnn/generated_lrn.go#L20-L39
5,482
gorgonia/cu
addressing.go
PtrAttribute
func (d DevicePtr) PtrAttribute(attr PointerAttribute) (unsafe.Pointer, error) { var p unsafe.Pointer devPtr := C.CUdeviceptr(d) a := C.CUpointer_attribute(attr) if err := result(C.cuPointerGetAttribute(p, a, devPtr)); err != nil { return nil, err } return p, nil }
go
func (d DevicePtr) PtrAttribute(attr PointerAttribute) (unsafe.Pointer, error) { var p unsafe.Pointer devPtr := C.CUdeviceptr(d) a := C.CUpointer_attribute(attr) if err := result(C.cuPointerGetAttribute(p, a, devPtr)); err != nil { return nil, err } return p, nil }
[ "func", "(", "d", "DevicePtr", ")", "PtrAttribute", "(", "attr", "PointerAttribute", ")", "(", "unsafe", ".", "Pointer", ",", "error", ")", "{", "var", "p", "unsafe", ".", "Pointer", "\n", "devPtr", ":=", "C", ".", "CUdeviceptr", "(", "d", ")", "\n", "a", ":=", "C", ".", "CUpointer_attribute", "(", "attr", ")", "\n", "if", "err", ":=", "result", "(", "C", ".", "cuPointerGetAttribute", "(", "p", ",", "a", ",", "devPtr", ")", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "return", "p", ",", "nil", "\n", "}" ]
// PtrAttribute returns information about a pointer.
[ "PtrAttribute", "returns", "information", "about", "a", "pointer", "." ]
89152d7e441439045736bc7640ff607ec371c26c
https://github.com/gorgonia/cu/blob/89152d7e441439045736bc7640ff607ec371c26c/addressing.go#L90-L98
5,483
gorgonia/cu
instrumentation.go
AverageQueueLength
func AverageQueueLength() int { ql.Lock() var s int for _, l := range q { s += l } avg := s / len(q) // yes, it's an integer division ql.Unlock() return avg }
go
func AverageQueueLength() int { ql.Lock() var s int for _, l := range q { s += l } avg := s / len(q) // yes, it's an integer division ql.Unlock() return avg }
[ "func", "AverageQueueLength", "(", ")", "int", "{", "ql", ".", "Lock", "(", ")", "\n", "var", "s", "int", "\n", "for", "_", ",", "l", ":=", "range", "q", "{", "s", "+=", "l", "\n", "}", "\n", "avg", ":=", "s", "/", "len", "(", "q", ")", "// yes, it's an integer division", "\n", "ql", ".", "Unlock", "(", ")", "\n", "return", "avg", "\n", "}" ]
// AverageQueueLength returns the average queue length recorded. This allows for optimizations.
[ "AverageQueueLength", "returns", "the", "average", "queue", "length", "recorded", ".", "This", "allows", "for", "optimizations", "." ]
89152d7e441439045736bc7640ff607ec371c26c
https://github.com/gorgonia/cu/blob/89152d7e441439045736bc7640ff607ec371c26c/instrumentation.go#L47-L56
5,484
gorgonia/cu
dnn/generated_ctcloss.go
NewCTCLoss
func NewCTCLoss(compType DataType) (retVal *CTCLoss, err error) { var internal C.cudnnCTCLossDescriptor_t if err := result(C.cudnnCreateCTCLossDescriptor(&internal)); err != nil { return nil, err } if err := result(C.cudnnSetCTCLossDescriptor(internal, compType.C())); err != nil { return nil, err } retVal = &CTCLoss{ internal: internal, compType: compType, } runtime.SetFinalizer(retVal, destroyCTCLoss) return retVal, nil }
go
func NewCTCLoss(compType DataType) (retVal *CTCLoss, err error) { var internal C.cudnnCTCLossDescriptor_t if err := result(C.cudnnCreateCTCLossDescriptor(&internal)); err != nil { return nil, err } if err := result(C.cudnnSetCTCLossDescriptor(internal, compType.C())); err != nil { return nil, err } retVal = &CTCLoss{ internal: internal, compType: compType, } runtime.SetFinalizer(retVal, destroyCTCLoss) return retVal, nil }
[ "func", "NewCTCLoss", "(", "compType", "DataType", ")", "(", "retVal", "*", "CTCLoss", ",", "err", "error", ")", "{", "var", "internal", "C", ".", "cudnnCTCLossDescriptor_t", "\n", "if", "err", ":=", "result", "(", "C", ".", "cudnnCreateCTCLossDescriptor", "(", "&", "internal", ")", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "if", "err", ":=", "result", "(", "C", ".", "cudnnSetCTCLossDescriptor", "(", "internal", ",", "compType", ".", "C", "(", ")", ")", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "retVal", "=", "&", "CTCLoss", "{", "internal", ":", "internal", ",", "compType", ":", "compType", ",", "}", "\n", "runtime", ".", "SetFinalizer", "(", "retVal", ",", "destroyCTCLoss", ")", "\n", "return", "retVal", ",", "nil", "\n", "}" ]
// NewCTCLoss creates a new CTCLoss.
[ "NewCTCLoss", "creates", "a", "new", "CTCLoss", "." ]
89152d7e441439045736bc7640ff607ec371c26c
https://github.com/gorgonia/cu/blob/89152d7e441439045736bc7640ff607ec371c26c/dnn/generated_ctcloss.go#L17-L33
5,485
gorgonia/cu
ctx_debug.go
NewContext
func NewContext(d Device, flags ContextFlags) *Ctx { var cctx C.CUcontext err := result(C.cuCtxCreate(&cctx, C.uint(flags), C.CUdevice(d))) if err != nil { panic(err) } ctx := newContext(makeContext(cctx)) ctx.device = d ctx.flags = flags errChan := make(chan error) go ctx.Run(errChan) if err := <-errChan; err != nil { panic(err) } return ctx }
go
func NewContext(d Device, flags ContextFlags) *Ctx { var cctx C.CUcontext err := result(C.cuCtxCreate(&cctx, C.uint(flags), C.CUdevice(d))) if err != nil { panic(err) } ctx := newContext(makeContext(cctx)) ctx.device = d ctx.flags = flags errChan := make(chan error) go ctx.Run(errChan) if err := <-errChan; err != nil { panic(err) } return ctx }
[ "func", "NewContext", "(", "d", "Device", ",", "flags", "ContextFlags", ")", "*", "Ctx", "{", "var", "cctx", "C", ".", "CUcontext", "\n", "err", ":=", "result", "(", "C", ".", "cuCtxCreate", "(", "&", "cctx", ",", "C", ".", "uint", "(", "flags", ")", ",", "C", ".", "CUdevice", "(", "d", ")", ")", ")", "\n", "if", "err", "!=", "nil", "{", "panic", "(", "err", ")", "\n", "}", "\n", "ctx", ":=", "newContext", "(", "makeContext", "(", "cctx", ")", ")", "\n", "ctx", ".", "device", "=", "d", "\n", "ctx", ".", "flags", "=", "flags", "\n\n", "errChan", ":=", "make", "(", "chan", "error", ")", "\n", "go", "ctx", ".", "Run", "(", "errChan", ")", "\n", "if", "err", ":=", "<-", "errChan", ";", "err", "!=", "nil", "{", "panic", "(", "err", ")", "\n", "}", "\n\n", "return", "ctx", "\n", "}" ]
// NewContext creates a new context, and runs a listener locked to an OSThread. All work is piped through that goroutine
[ "NewContext", "creates", "a", "new", "context", "and", "runs", "a", "listener", "locked", "to", "an", "OSThread", ".", "All", "work", "is", "piped", "through", "that", "goroutine" ]
89152d7e441439045736bc7640ff607ec371c26c
https://github.com/gorgonia/cu/blob/89152d7e441439045736bc7640ff607ec371c26c/ctx_debug.go#L25-L42
5,486
gorgonia/cu
module.go
LoadData
func LoadData(image string) (Module, error) { var mod Module cstr := C.CString(image) defer C.free(unsafe.Pointer(cstr)) err := result(C.cuModuleLoadData(&mod.mod, unsafe.Pointer(cstr))) return mod, err }
go
func LoadData(image string) (Module, error) { var mod Module cstr := C.CString(image) defer C.free(unsafe.Pointer(cstr)) err := result(C.cuModuleLoadData(&mod.mod, unsafe.Pointer(cstr))) return mod, err }
[ "func", "LoadData", "(", "image", "string", ")", "(", "Module", ",", "error", ")", "{", "var", "mod", "Module", "\n", "cstr", ":=", "C", ".", "CString", "(", "image", ")", "\n", "defer", "C", ".", "free", "(", "unsafe", ".", "Pointer", "(", "cstr", ")", ")", "\n", "err", ":=", "result", "(", "C", ".", "cuModuleLoadData", "(", "&", "mod", ".", "mod", ",", "unsafe", ".", "Pointer", "(", "cstr", ")", ")", ")", "\n", "return", "mod", ",", "err", "\n", "}" ]
// LoadData loads a module from a input string.
[ "LoadData", "loads", "a", "module", "from", "a", "input", "string", "." ]
89152d7e441439045736bc7640ff607ec371c26c
https://github.com/gorgonia/cu/blob/89152d7e441439045736bc7640ff607ec371c26c/module.go#L32-L38
5,487
gorgonia/cu
module.go
LoadDataEx
func LoadDataEx(image string, options ...JITOption) (Module, error) { var mod Module cstr := C.CString(image) defer C.free(unsafe.Pointer(cstr)) argcount, args, argvals := encodeArguments(options) err := result(C.cuModuleLoadDataEx(&mod.mod, unsafe.Pointer(cstr), argcount, args, argvals)) return mod, err }
go
func LoadDataEx(image string, options ...JITOption) (Module, error) { var mod Module cstr := C.CString(image) defer C.free(unsafe.Pointer(cstr)) argcount, args, argvals := encodeArguments(options) err := result(C.cuModuleLoadDataEx(&mod.mod, unsafe.Pointer(cstr), argcount, args, argvals)) return mod, err }
[ "func", "LoadDataEx", "(", "image", "string", ",", "options", "...", "JITOption", ")", "(", "Module", ",", "error", ")", "{", "var", "mod", "Module", "\n", "cstr", ":=", "C", ".", "CString", "(", "image", ")", "\n", "defer", "C", ".", "free", "(", "unsafe", ".", "Pointer", "(", "cstr", ")", ")", "\n\n", "argcount", ",", "args", ",", "argvals", ":=", "encodeArguments", "(", "options", ")", "\n", "err", ":=", "result", "(", "C", ".", "cuModuleLoadDataEx", "(", "&", "mod", ".", "mod", ",", "unsafe", ".", "Pointer", "(", "cstr", ")", ",", "argcount", ",", "args", ",", "argvals", ")", ")", "\n", "return", "mod", ",", "err", "\n", "}" ]
// LoadDataEx loads a module from a input string.
[ "LoadDataEx", "loads", "a", "module", "from", "a", "input", "string", "." ]
89152d7e441439045736bc7640ff607ec371c26c
https://github.com/gorgonia/cu/blob/89152d7e441439045736bc7640ff607ec371c26c/module.go#L41-L49
5,488
gorgonia/cu
module.go
LoadFatBinary
func LoadFatBinary(image string) (Module, error) { var mod Module cstr := C.CString(image) defer C.free(unsafe.Pointer(cstr)) err := result(C.cuModuleLoadFatBinary(&mod.mod, unsafe.Pointer(cstr))) return mod, err }
go
func LoadFatBinary(image string) (Module, error) { var mod Module cstr := C.CString(image) defer C.free(unsafe.Pointer(cstr)) err := result(C.cuModuleLoadFatBinary(&mod.mod, unsafe.Pointer(cstr))) return mod, err }
[ "func", "LoadFatBinary", "(", "image", "string", ")", "(", "Module", ",", "error", ")", "{", "var", "mod", "Module", "\n", "cstr", ":=", "C", ".", "CString", "(", "image", ")", "\n", "defer", "C", ".", "free", "(", "unsafe", ".", "Pointer", "(", "cstr", ")", ")", "\n", "err", ":=", "result", "(", "C", ".", "cuModuleLoadFatBinary", "(", "&", "mod", ".", "mod", ",", "unsafe", ".", "Pointer", "(", "cstr", ")", ")", ")", "\n", "return", "mod", ",", "err", "\n", "}" ]
// LoadFatBinary loads a module from a input string.
[ "LoadFatBinary", "loads", "a", "module", "from", "a", "input", "string", "." ]
89152d7e441439045736bc7640ff607ec371c26c
https://github.com/gorgonia/cu/blob/89152d7e441439045736bc7640ff607ec371c26c/module.go#L52-L58
5,489
gorgonia/cu
module.go
Function
func (m Module) Function(name string) (Function, error) { var fn Function cstr := C.CString(name) defer C.free(unsafe.Pointer(cstr)) err := result(C.cuModuleGetFunction(&fn.fn, m.mod, cstr)) return fn, err }
go
func (m Module) Function(name string) (Function, error) { var fn Function cstr := C.CString(name) defer C.free(unsafe.Pointer(cstr)) err := result(C.cuModuleGetFunction(&fn.fn, m.mod, cstr)) return fn, err }
[ "func", "(", "m", "Module", ")", "Function", "(", "name", "string", ")", "(", "Function", ",", "error", ")", "{", "var", "fn", "Function", "\n", "cstr", ":=", "C", ".", "CString", "(", "name", ")", "\n", "defer", "C", ".", "free", "(", "unsafe", ".", "Pointer", "(", "cstr", ")", ")", "\n", "err", ":=", "result", "(", "C", ".", "cuModuleGetFunction", "(", "&", "fn", ".", "fn", ",", "m", ".", "mod", ",", "cstr", ")", ")", "\n", "return", "fn", ",", "err", "\n", "}" ]
// Function returns a pointer to the function in the module by the name. If it's not found, the error NotFound is returned
[ "Function", "returns", "a", "pointer", "to", "the", "function", "in", "the", "module", "by", "the", "name", ".", "If", "it", "s", "not", "found", "the", "error", "NotFound", "is", "returned" ]
89152d7e441439045736bc7640ff607ec371c26c
https://github.com/gorgonia/cu/blob/89152d7e441439045736bc7640ff607ec371c26c/module.go#L61-L67
5,490
gorgonia/cu
module.go
Global
func (m Module) Global(name string) (DevicePtr, int64, error) { var d C.CUdeviceptr var size C.size_t cstr := C.CString(name) defer C.free(unsafe.Pointer(cstr)) if err := result(C.cuModuleGetGlobal(&d, &size, m.mod, cstr)); err != nil { return 0, 0, err } return DevicePtr(d), int64(size), nil }
go
func (m Module) Global(name string) (DevicePtr, int64, error) { var d C.CUdeviceptr var size C.size_t cstr := C.CString(name) defer C.free(unsafe.Pointer(cstr)) if err := result(C.cuModuleGetGlobal(&d, &size, m.mod, cstr)); err != nil { return 0, 0, err } return DevicePtr(d), int64(size), nil }
[ "func", "(", "m", "Module", ")", "Global", "(", "name", "string", ")", "(", "DevicePtr", ",", "int64", ",", "error", ")", "{", "var", "d", "C", ".", "CUdeviceptr", "\n", "var", "size", "C", ".", "size_t", "\n", "cstr", ":=", "C", ".", "CString", "(", "name", ")", "\n", "defer", "C", ".", "free", "(", "unsafe", ".", "Pointer", "(", "cstr", ")", ")", "\n", "if", "err", ":=", "result", "(", "C", ".", "cuModuleGetGlobal", "(", "&", "d", ",", "&", "size", ",", "m", ".", "mod", ",", "cstr", ")", ")", ";", "err", "!=", "nil", "{", "return", "0", ",", "0", ",", "err", "\n", "}", "\n", "return", "DevicePtr", "(", "d", ")", ",", "int64", "(", "size", ")", ",", "nil", "\n", "}" ]
// Global returns a global pointer as defined in a module. It returns a pointer to the memory in the device.
[ "Global", "returns", "a", "global", "pointer", "as", "defined", "in", "a", "module", ".", "It", "returns", "a", "pointer", "to", "the", "memory", "in", "the", "device", "." ]
89152d7e441439045736bc7640ff607ec371c26c
https://github.com/gorgonia/cu/blob/89152d7e441439045736bc7640ff607ec371c26c/module.go#L70-L79
5,491
gorgonia/cu
jit.go
NewLink
func NewLink(options ...JITOption) (*LinkState, error) { link := &LinkState{} argcount, args, argvals := link.encodeArguments(options) err := result(C.cuLinkCreate(argcount, args, argvals, &link.state)) return link, err }
go
func NewLink(options ...JITOption) (*LinkState, error) { link := &LinkState{} argcount, args, argvals := link.encodeArguments(options) err := result(C.cuLinkCreate(argcount, args, argvals, &link.state)) return link, err }
[ "func", "NewLink", "(", "options", "...", "JITOption", ")", "(", "*", "LinkState", ",", "error", ")", "{", "link", ":=", "&", "LinkState", "{", "}", "\n\n", "argcount", ",", "args", ",", "argvals", ":=", "link", ".", "encodeArguments", "(", "options", ")", "\n", "err", ":=", "result", "(", "C", ".", "cuLinkCreate", "(", "argcount", ",", "args", ",", "argvals", ",", "&", "link", ".", "state", ")", ")", "\n", "return", "link", ",", "err", "\n", "}" ]
// Creates a pending JIT linker invocation.
[ "Creates", "a", "pending", "JIT", "linker", "invocation", "." ]
89152d7e441439045736bc7640ff607ec371c26c
https://github.com/gorgonia/cu/blob/89152d7e441439045736bc7640ff607ec371c26c/jit.go#L190-L196
5,492
gorgonia/cu
jit.go
AddData
func (link *LinkState) AddData(input JITInputType, data string, name string, options ...JITOption) error { argcount, args, argvals := link.encodeArguments(options) cname := C.CString(name) bytes := []byte(data) err := result(C.cuLinkAddData( link.state, C.CUjitInputType(input), unsafe.Pointer(&bytes[0]), C.size_t(len(bytes)), cname, argcount, args, argvals, )) C.free(unsafe.Pointer(cname)) return err }
go
func (link *LinkState) AddData(input JITInputType, data string, name string, options ...JITOption) error { argcount, args, argvals := link.encodeArguments(options) cname := C.CString(name) bytes := []byte(data) err := result(C.cuLinkAddData( link.state, C.CUjitInputType(input), unsafe.Pointer(&bytes[0]), C.size_t(len(bytes)), cname, argcount, args, argvals, )) C.free(unsafe.Pointer(cname)) return err }
[ "func", "(", "link", "*", "LinkState", ")", "AddData", "(", "input", "JITInputType", ",", "data", "string", ",", "name", "string", ",", "options", "...", "JITOption", ")", "error", "{", "argcount", ",", "args", ",", "argvals", ":=", "link", ".", "encodeArguments", "(", "options", ")", "\n\n", "cname", ":=", "C", ".", "CString", "(", "name", ")", "\n", "bytes", ":=", "[", "]", "byte", "(", "data", ")", "\n", "err", ":=", "result", "(", "C", ".", "cuLinkAddData", "(", "link", ".", "state", ",", "C", ".", "CUjitInputType", "(", "input", ")", ",", "unsafe", ".", "Pointer", "(", "&", "bytes", "[", "0", "]", ")", ",", "C", ".", "size_t", "(", "len", "(", "bytes", ")", ")", ",", "cname", ",", "argcount", ",", "args", ",", "argvals", ",", ")", ")", "\n", "C", ".", "free", "(", "unsafe", ".", "Pointer", "(", "cname", ")", ")", "\n", "return", "err", "\n", "}" ]
// Add an input to a pending linker invocation
[ "Add", "an", "input", "to", "a", "pending", "linker", "invocation" ]
89152d7e441439045736bc7640ff607ec371c26c
https://github.com/gorgonia/cu/blob/89152d7e441439045736bc7640ff607ec371c26c/jit.go#L223-L236
5,493
gorgonia/cu
jit.go
AddFile
func (link *LinkState) AddFile(input JITInputType, path string, options ...JITOption) error { argcount, args, argvals := link.encodeArguments(options) cpath := C.CString(path) err := result(C.cuLinkAddFile( link.state, C.CUjitInputType(input), cpath, argcount, args, argvals, )) C.free(unsafe.Pointer(cpath)) return err }
go
func (link *LinkState) AddFile(input JITInputType, path string, options ...JITOption) error { argcount, args, argvals := link.encodeArguments(options) cpath := C.CString(path) err := result(C.cuLinkAddFile( link.state, C.CUjitInputType(input), cpath, argcount, args, argvals, )) C.free(unsafe.Pointer(cpath)) return err }
[ "func", "(", "link", "*", "LinkState", ")", "AddFile", "(", "input", "JITInputType", ",", "path", "string", ",", "options", "...", "JITOption", ")", "error", "{", "argcount", ",", "args", ",", "argvals", ":=", "link", ".", "encodeArguments", "(", "options", ")", "\n\n", "cpath", ":=", "C", ".", "CString", "(", "path", ")", "\n", "err", ":=", "result", "(", "C", ".", "cuLinkAddFile", "(", "link", ".", "state", ",", "C", ".", "CUjitInputType", "(", "input", ")", ",", "cpath", ",", "argcount", ",", "args", ",", "argvals", ",", ")", ")", "\n", "C", ".", "free", "(", "unsafe", ".", "Pointer", "(", "cpath", ")", ")", "\n", "return", "err", "\n", "}" ]
// Add a file input to a pending linker invocation
[ "Add", "a", "file", "input", "to", "a", "pending", "linker", "invocation" ]
89152d7e441439045736bc7640ff607ec371c26c
https://github.com/gorgonia/cu/blob/89152d7e441439045736bc7640ff607ec371c26c/jit.go#L239-L250
5,494
gorgonia/cu
jit.go
Complete
func (link *LinkState) Complete() (string, error) { var data unsafe.Pointer var datasize C.size_t err := result(C.cuLinkComplete(link.state, &data, &datasize)) if err != nil { return "", err } size := int(datasize) buffer := make([]byte, size) copy(buffer, (*[20 << 30]byte)(data)[:size]) return string(buffer), nil }
go
func (link *LinkState) Complete() (string, error) { var data unsafe.Pointer var datasize C.size_t err := result(C.cuLinkComplete(link.state, &data, &datasize)) if err != nil { return "", err } size := int(datasize) buffer := make([]byte, size) copy(buffer, (*[20 << 30]byte)(data)[:size]) return string(buffer), nil }
[ "func", "(", "link", "*", "LinkState", ")", "Complete", "(", ")", "(", "string", ",", "error", ")", "{", "var", "data", "unsafe", ".", "Pointer", "\n", "var", "datasize", "C", ".", "size_t", "\n\n", "err", ":=", "result", "(", "C", ".", "cuLinkComplete", "(", "link", ".", "state", ",", "&", "data", ",", "&", "datasize", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "err", "\n", "}", "\n\n", "size", ":=", "int", "(", "datasize", ")", "\n", "buffer", ":=", "make", "(", "[", "]", "byte", ",", "size", ")", "\n", "copy", "(", "buffer", ",", "(", "*", "[", "20", "<<", "30", "]", "byte", ")", "(", "data", ")", "[", ":", "size", "]", ")", "\n\n", "return", "string", "(", "buffer", ")", ",", "nil", "\n", "}" ]
// Complete a pending linker invocation
[ "Complete", "a", "pending", "linker", "invocation" ]
89152d7e441439045736bc7640ff607ec371c26c
https://github.com/gorgonia/cu/blob/89152d7e441439045736bc7640ff607ec371c26c/jit.go#L253-L267
5,495
gorgonia/cu
cmd/gencudnn/parse.go
functions
func functions(decl *cc.Declarator) bool { if !strings.HasPrefix(bindgen.NameOf(decl), "cudnn") { return false } if decl.Type.Kind() == cc.Function { return true } return false }
go
func functions(decl *cc.Declarator) bool { if !strings.HasPrefix(bindgen.NameOf(decl), "cudnn") { return false } if decl.Type.Kind() == cc.Function { return true } return false }
[ "func", "functions", "(", "decl", "*", "cc", ".", "Declarator", ")", "bool", "{", "if", "!", "strings", ".", "HasPrefix", "(", "bindgen", ".", "NameOf", "(", "decl", ")", ",", "\"", "\"", ")", "{", "return", "false", "\n", "}", "\n", "if", "decl", ".", "Type", ".", "Kind", "(", ")", "==", "cc", ".", "Function", "{", "return", "true", "\n", "}", "\n", "return", "false", "\n\n", "}" ]
// Functions returns the C function declarations in the givel set of file paths.
[ "Functions", "returns", "the", "C", "function", "declarations", "in", "the", "givel", "set", "of", "file", "paths", "." ]
89152d7e441439045736bc7640ff607ec371c26c
https://github.com/gorgonia/cu/blob/89152d7e441439045736bc7640ff607ec371c26c/cmd/gencudnn/parse.go#L12-L21
5,496
gorgonia/cu
cmd/gencudnn/parse.go
goNameOfStr
func goNameOfStr(n string) (retVal string) { var ok bool defer func() { retVal = reqPtr(retVal) }() if retVal, ok = ctypes2GoTypes[n]; ok { return retVal } if retVal, ok = enumMappings[n]; ok { return retVal } if retVal, ok = builtins[n]; ok { return retVal } if retVal, ok = nonPrimitives[n]; ok { return retVal } return "" }
go
func goNameOfStr(n string) (retVal string) { var ok bool defer func() { retVal = reqPtr(retVal) }() if retVal, ok = ctypes2GoTypes[n]; ok { return retVal } if retVal, ok = enumMappings[n]; ok { return retVal } if retVal, ok = builtins[n]; ok { return retVal } if retVal, ok = nonPrimitives[n]; ok { return retVal } return "" }
[ "func", "goNameOfStr", "(", "n", "string", ")", "(", "retVal", "string", ")", "{", "var", "ok", "bool", "\n", "defer", "func", "(", ")", "{", "retVal", "=", "reqPtr", "(", "retVal", ")", "\n", "}", "(", ")", "\n", "if", "retVal", ",", "ok", "=", "ctypes2GoTypes", "[", "n", "]", ";", "ok", "{", "return", "retVal", "\n", "}", "\n", "if", "retVal", ",", "ok", "=", "enumMappings", "[", "n", "]", ";", "ok", "{", "return", "retVal", "\n", "}", "\n", "if", "retVal", ",", "ok", "=", "builtins", "[", "n", "]", ";", "ok", "{", "return", "retVal", "\n", "}", "\n", "if", "retVal", ",", "ok", "=", "nonPrimitives", "[", "n", "]", ";", "ok", "{", "return", "retVal", "\n", "}", "\n\n", "return", "\"", "\"", "\n", "}" ]
// same as above, but given a c name type in string
[ "same", "as", "above", "but", "given", "a", "c", "name", "type", "in", "string" ]
89152d7e441439045736bc7640ff607ec371c26c
https://github.com/gorgonia/cu/blob/89152d7e441439045736bc7640ff607ec371c26c/cmd/gencudnn/parse.go#L190-L209
5,497
gorgonia/cu
dnn/rnn.go
NewRNN
func (handle *Context) NewRNN(hiddenSize int, numLayers int, dropout *Dropout, inputMode RNNInputMode, direction DirectionMode, mode RNNMode, algo RNNAlgo, dataType DataType) (retVal *RNN, err error) { var internal C.cudnnRNNDescriptor_t if err := result(C.cudnnCreateRNNDescriptor(&internal)); err != nil { return nil, err } if err := result(C.cudnnSetRNNDescriptor(handle.internal, internal, C.int(hiddenSize), C.int(numLayers), dropout.internal, inputMode.C(), direction.C(), mode.C(), algo.C(), dataType.C())); err != nil { return nil, err } retVal = &RNN{ internal: internal, hiddenSize: hiddenSize, layers: numLayers, dropoutDescriptor: dropout, inputMode: inputMode, directionMode: direction, mode: mode, algo: algo, dataType: dataType, matrixMathType: DefaultMath, } runtime.SetFinalizer(retVal, destroyRNN) return retVal, nil }
go
func (handle *Context) NewRNN(hiddenSize int, numLayers int, dropout *Dropout, inputMode RNNInputMode, direction DirectionMode, mode RNNMode, algo RNNAlgo, dataType DataType) (retVal *RNN, err error) { var internal C.cudnnRNNDescriptor_t if err := result(C.cudnnCreateRNNDescriptor(&internal)); err != nil { return nil, err } if err := result(C.cudnnSetRNNDescriptor(handle.internal, internal, C.int(hiddenSize), C.int(numLayers), dropout.internal, inputMode.C(), direction.C(), mode.C(), algo.C(), dataType.C())); err != nil { return nil, err } retVal = &RNN{ internal: internal, hiddenSize: hiddenSize, layers: numLayers, dropoutDescriptor: dropout, inputMode: inputMode, directionMode: direction, mode: mode, algo: algo, dataType: dataType, matrixMathType: DefaultMath, } runtime.SetFinalizer(retVal, destroyRNN) return retVal, nil }
[ "func", "(", "handle", "*", "Context", ")", "NewRNN", "(", "hiddenSize", "int", ",", "numLayers", "int", ",", "dropout", "*", "Dropout", ",", "inputMode", "RNNInputMode", ",", "direction", "DirectionMode", ",", "mode", "RNNMode", ",", "algo", "RNNAlgo", ",", "dataType", "DataType", ")", "(", "retVal", "*", "RNN", ",", "err", "error", ")", "{", "var", "internal", "C", ".", "cudnnRNNDescriptor_t", "\n", "if", "err", ":=", "result", "(", "C", ".", "cudnnCreateRNNDescriptor", "(", "&", "internal", ")", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "if", "err", ":=", "result", "(", "C", ".", "cudnnSetRNNDescriptor", "(", "handle", ".", "internal", ",", "internal", ",", "C", ".", "int", "(", "hiddenSize", ")", ",", "C", ".", "int", "(", "numLayers", ")", ",", "dropout", ".", "internal", ",", "inputMode", ".", "C", "(", ")", ",", "direction", ".", "C", "(", ")", ",", "mode", ".", "C", "(", ")", ",", "algo", ".", "C", "(", ")", ",", "dataType", ".", "C", "(", ")", ")", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "retVal", "=", "&", "RNN", "{", "internal", ":", "internal", ",", "hiddenSize", ":", "hiddenSize", ",", "layers", ":", "numLayers", ",", "dropoutDescriptor", ":", "dropout", ",", "inputMode", ":", "inputMode", ",", "directionMode", ":", "direction", ",", "mode", ":", "mode", ",", "algo", ":", "algo", ",", "dataType", ":", "dataType", ",", "matrixMathType", ":", "DefaultMath", ",", "}", "\n", "runtime", ".", "SetFinalizer", "(", "retVal", ",", "destroyRNN", ")", "\n", "return", "retVal", ",", "nil", "\n", "}" ]
// NewRNN creates a new RNN.
[ "NewRNN", "creates", "a", "new", "RNN", "." ]
89152d7e441439045736bc7640ff607ec371c26c
https://github.com/gorgonia/cu/blob/89152d7e441439045736bc7640ff607ec371c26c/dnn/rnn.go#L61-L86
5,498
gorgonia/cu
dnn/dropout.go
NewDropout
func NewDropout(dropout float64) (retVal *Dropout, err error) { var internal C.cudnnDropoutDescriptor_t if err := result(C.cudnnCreateDropoutDescriptor(&internal)); err != nil { return nil, err } retVal = &Dropout{ internal: internal, dropout: float32(dropout), } runtime.SetFinalizer(retVal, destroyDropout) return retVal, nil }
go
func NewDropout(dropout float64) (retVal *Dropout, err error) { var internal C.cudnnDropoutDescriptor_t if err := result(C.cudnnCreateDropoutDescriptor(&internal)); err != nil { return nil, err } retVal = &Dropout{ internal: internal, dropout: float32(dropout), } runtime.SetFinalizer(retVal, destroyDropout) return retVal, nil }
[ "func", "NewDropout", "(", "dropout", "float64", ")", "(", "retVal", "*", "Dropout", ",", "err", "error", ")", "{", "var", "internal", "C", ".", "cudnnDropoutDescriptor_t", "\n", "if", "err", ":=", "result", "(", "C", ".", "cudnnCreateDropoutDescriptor", "(", "&", "internal", ")", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "retVal", "=", "&", "Dropout", "{", "internal", ":", "internal", ",", "dropout", ":", "float32", "(", "dropout", ")", ",", "}", "\n", "runtime", ".", "SetFinalizer", "(", "retVal", ",", "destroyDropout", ")", "\n", "return", "retVal", ",", "nil", "\n", "}" ]
// NewDropout creates a Dropout descriptor. It is not usable by default because some additional stateful information needs to be passed in
[ "NewDropout", "creates", "a", "Dropout", "descriptor", ".", "It", "is", "not", "usable", "by", "default", "because", "some", "additional", "stateful", "information", "needs", "to", "be", "passed", "in" ]
89152d7e441439045736bc7640ff607ec371c26c
https://github.com/gorgonia/cu/blob/89152d7e441439045736bc7640ff607ec371c26c/dnn/dropout.go#L35-L46
5,499
gorgonia/cu
dnn/dropout.go
Use
func (d *Dropout) Use(ctx *Context, states Memory, stateSizeInBytes uintptr, seed uint64) error { d.handle = ctx d.states = states d.stateSizeInBytes = stateSizeInBytes d.seed = seed return result(C.cudnnSetDropoutDescriptor(d.internal, d.handle.internal, C.float(d.dropout), unsafe.Pointer(d.states.Uintptr()), C.size_t(d.stateSizeInBytes), C.ulonglong(d.seed))) }
go
func (d *Dropout) Use(ctx *Context, states Memory, stateSizeInBytes uintptr, seed uint64) error { d.handle = ctx d.states = states d.stateSizeInBytes = stateSizeInBytes d.seed = seed return result(C.cudnnSetDropoutDescriptor(d.internal, d.handle.internal, C.float(d.dropout), unsafe.Pointer(d.states.Uintptr()), C.size_t(d.stateSizeInBytes), C.ulonglong(d.seed))) }
[ "func", "(", "d", "*", "Dropout", ")", "Use", "(", "ctx", "*", "Context", ",", "states", "Memory", ",", "stateSizeInBytes", "uintptr", ",", "seed", "uint64", ")", "error", "{", "d", ".", "handle", "=", "ctx", "\n", "d", ".", "states", "=", "states", "\n", "d", ".", "stateSizeInBytes", "=", "stateSizeInBytes", "\n", "d", ".", "seed", "=", "seed", "\n\n", "return", "result", "(", "C", ".", "cudnnSetDropoutDescriptor", "(", "d", ".", "internal", ",", "d", ".", "handle", ".", "internal", ",", "C", ".", "float", "(", "d", ".", "dropout", ")", ",", "unsafe", ".", "Pointer", "(", "d", ".", "states", ".", "Uintptr", "(", ")", ")", ",", "C", ".", "size_t", "(", "d", ".", "stateSizeInBytes", ")", ",", "C", ".", "ulonglong", "(", "d", ".", "seed", ")", ")", ")", "\n", "}" ]
// Use is the second stage of the two-stage API.
[ "Use", "is", "the", "second", "stage", "of", "the", "two", "-", "stage", "API", "." ]
89152d7e441439045736bc7640ff607ec371c26c
https://github.com/gorgonia/cu/blob/89152d7e441439045736bc7640ff607ec371c26c/dnn/dropout.go#L58-L65