Disposing the default worker in Alea CUDA - f#

Is it required to dispose Worker.Default or CUBLAS.Default?
My CUDA code runs correctly but I get the following exception when the program exits:
Got CUDA error CUDA_ERROR_INVALID_VALUE
at System.Environment.GetStackTrace(Exception e, Boolean needFileInfo)
at System.Environment.get_StackTrace()
at Alea.CUDA.CUDAInterop.cuSafeCall(cudaError_enum result)
at <StartupCode$Alea-CUDA>.$Engine.f#1-46[T](WorkerContext this, FSharpFunc`2
f, Unit _arg6)
at Alea.CUDA.WorkerContext.eval[T](FSharpFunc`2 f)
at Alea.CUDA.Program.Dispose(Boolean disposing)
Got CUDA error CUDA_ERROR_INVALID_VALUE
at System.Environment.GetStackTrace(Exception e, Boolean needFileInfo)
at System.Environment.get_StackTrace()
at Alea.CUDA.CUDAInterop.cuSafeCall(cudaError_enum result)
at <StartupCode$Alea-CUDA>.$Engine.f#1-46[T](WorkerContext this, FSharpFunc`2
f, Unit _arg6)
at Alea.CUDA.WorkerContext.eval[T](FSharpFunc`2 f)
at Alea.CUDA.Program.Dispose(Boolean disposing)
Can I use Worker.Default and CUBLAS.Default in multiple classes or should I create one and pass this to anyone who needs a worker?
Thanks
Johan

Although worker can be disposed, but it is not suggested that you dispose it. Worker represents a CUDA context, and should be long lived. The default worker and default cublas object are built on your default GPU device.

Related

Retry after OOME fail when Neo4j procedure called from Neo4j browser but not from cypher-shell

I have Java method deployed into dockerized Neo4j as standard stored procedure in plugin. The method sets new property to all nodes of some label. It fails with OutOfMemoryError since the JVM heap is not appropriately sized for committing everything in single transaction.
public class Foo {
#Context
public Transaction tx;
#Procedure(value = "foo", mode = Mode.WRITE)
public void foo() {
System.out.println("ENTER");
for (Node node : (Iterable<Node>) () -> tx.findNodes(Labels.label("Hoo"))) {
node.setProperty("SOME_PROPERTY", new long[] {100L,200L});
}
System.out.println("EXIT");
}
}
Let's call the method:
CALL foo();
When the method is called from Neo4j Browser on localhost:7474, the method exits but then it is called again:
ENTER
EXIT
Exception: java.lang.OutOfMemoryError thrown from the UncaughtExceptionHandler in thread "neo4j.StorageMaintenance-3"
Exception: java.lang.OutOfMemoryError thrown from the UncaughtExceptionHandler in thread "neo4j.StorageMaintenance-2"
Exception: java.lang.OutOfMemoryError thrown from the UncaughtExceptionHandler in thread "qtp1566104673-43"
Exception in thread "neo4j.VmPauseMonitor-1" Exception in thread "neo4j.Scheduler-1" java.lang.OutOfMemoryError: Java heap space
java.lang.OutOfMemoryError: Java heap space
2021-07-03 09:42:16.438+0000 WARN
java.lang.OutOfMemoryError: Java heap space
Exception in thread "qtp1566104673-40" java.lang.OutOfMemoryError: Java heap space
ENTER
EXIT
When I docker exec into Neo4j container and call the method from cypher-shell, the method fails with OOME too, but there is no repeated call.
Why is the method called twice from Neo4j Browser? Is there some documentation or link to source code to support reasoning of such behavior?
(Please note the question is not how to fix OOME, currently it is successfully fixed to bulk processing in similar manner to apoc.periodic package.)

reactjs.net - 'potential stack overflow detected' error

Since I've decided to switch to server-side rendering from client-side react, I began to create my components and use them in the app.
However I came across this error:
Unknown error (RangeError); potential stack overflow detected
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: Microsoft.ClearScript.ScriptEngineException: Unknown error (RangeError); potential stack overflow detected
And this is a part from the stack-trace
[ScriptEngineException: Unknown error (RangeError); potential stack overflow detected]
V8Exception.ThrowScriptEngineException(V8Exception* ) +169
Microsoft.ClearScript.V8.V8ContextProxyImpl.Execute(String gcDocumentName, String gcCode, Boolean evaluate, Boolean discard) +462
Microsoft.ClearScript.V8.<>c__DisplayClass1b.<Execute>b__19() +197
Microsoft.ClearScript.ScriptEngine.ScriptInvoke(Func`1 func) +70
Microsoft.ClearScript.V8.V8ScriptEngine.BaseScriptInvoke(Func`1 func) +49
Microsoft.ClearScript.V8.<>c__DisplayClass25`1.<ScriptInvoke>b__24() +45
Microsoft.ClearScript.V8.?A0x792c8756.LockCallback(Void* pvArg) +9
Microsoft.ClearScript.V8.V8ContextProxyImpl.InvokeWithLock(Action gcAction) +176
Microsoft.ClearScript.V8.V8ScriptEngine.ScriptInvoke(Func`1 func) +118
Microsoft.ClearScript.V8.V8ScriptEngine.Execute(String documentName, String code, Boolean evaluate, Boolean discard) +118
JavaScriptEngineSwitcher.V8.V8JsEngine.InnerEvaluate(String expression) +89
So I don't know what causes this error but I think it is some code that goes in a loop or something similar. Furthermore if I refresh the page this error goes away and if I continue to refresh intensively it shows up again which is very frustrating.
I was getting the same error (web app in azure) and after some investigation and tests, setting SetAllowMsieEngine to true did in fact fixed the issue also to me.
As Luke McGregor said, this seems to be an issue with V8ScriptEngine and using SetAllowMsieEngine does the job, however this method is latest version of react.net is deprecated and is recommended to "managed in the JavaScriptEngineSwitcher configuration".
So the solution I found so far is to switch js engine switcher by setting it directly in code:
JsEngineSwitcher engineSwitcher = JsEngineSwitcher.Instance;
engineSwitcher.EngineFactories
.AddChakraCore()
.AddMsie( new MsieSettings() { EngineMode = JsEngineMode.Auto } );
engineSwitcher.DefaultEngineName = ChakraCoreJsEngine.EngineName;
Like this I'm using ChakraCore engine rather than default V8 which was causing the error.
So far, during our performance tests with around 250 concurrent requests, we do not have this error anymore when previously in the same conditions for sure this error would have occurred.
This is a known issue, see https://github.com/reactjs/React.NET/issues/190
The work around is to not use V8 to do the render ie:
app.UseReact(config =>
{
config
// ..other configuration settings
.SetAllowMsieEngine(true);
});

ODP.net managed driver throws ORA-12570: Network Session: Unexpected packet read error

In one of our products we retrieve data from the Oracle database using stored procedures using the ODP.net managed driver.
Every now and then (roughly every 1000 queries) we get the following exception:
(ORA-12570: Network Session: Unexpected packet read error)
---> Oracle.ManagedDataAccess.Client.OracleException: ORA-12570: Network Session: Unexpected packet read error
---> OracleInternal.Network.NetworkException: ORA-12570: Network Session: Unexpected packet read error
---> System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values.
Parameter name: size
at System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags, SocketError& errorCode)
at OracleInternal.Network.ReaderStream.ReadIt(OraBuf OB, Int32 len)
--- End of inner exception stack trace ---
at OracleInternal.Network.ReaderStream.ReadIt(OraBuf OB, Int32 len)
at OracleInternal.Network.ReaderStream.WaitForReset()
at OracleInternal.Network.OracleCommunication.Reset()
at OracleInternal.TTC.TTCExecuteSql.ReceiveExecuteResponse(Accessor[]& defineAccessors, Accessor[] bindAccessors, Boolean bHasReturningParams, SQLMetaData& sqlMetaData, SqlStatementType statementType, Int64 noOfRowsFetchedLastTime, Int32 noOfRowsToFetch, Int32& noOfRowsFetched, Int64& queryId, Int32 longFetchSize, Int32 initialLOBFetchSize, Int64[] scnFromExecution, Boolean& bAllPureInputBinds, DataUnmarshaller& dataUnmarshaller, MarshalBindParameterValueHelper& marshalBindParamsHelper, Boolean bDefineDone, Boolean& bMoreThanOneRowAffectedByDmlWithRetClause)
--- End of inner exception stack trace ---
at Oracle.ManagedDataAccess.Client.OracleException.HandleError(OracleTraceLevel level, OracleTraceTag tag, Exception ex)
at OracleInternal.TTC.TTCExecuteSql.ReceiveExecuteResponse(Accessor[]& defineAccessors, Accessor[] bindAccessors, Boolean bHasReturningParams, SQLMetaData& sqlMetaData, SqlStatementType statementType, Int64 noOfRowsFetchedLastTime, Int32 noOfRowsToFetch, Int32& noOfRowsFetched, Int64& queryId, Int32 longFetchSize, Int32 initialLOBFetchSize, Int64[] scnFromExecution, Boolean& bAllPureInputBinds, DataUnmarshaller& dataUnmarshaller, MarshalBindParameterValueHelper& marshalBindParamsHelper, Boolean bDefineDone, Boolean& bMoreThanOneRowAffectedByDmlWithRetClause)
at OracleInternal.ServiceObjects.OracleCommandImpl.ExecuteNonQuery(String commandText, OracleParameterCollection paramColl, CommandType commandType, OracleConnectionImpl connectionImpl, Int32 longFetchSize, Int32 lobPrefetchSize, OracleDependencyImpl orclDependencyImpl, Int64[]& scnFromExecution, OracleParameterCollection& bindByPositionParamColl, Boolean& bBindParamPresent, Boolean isFromEF)
at Oracle.ManagedDataAccess.Client.OracleCommand.ExecuteNonQuery()
It seems like ODP.net is calling System.Net.Sockets.Socket.Receive with an invalid size parameter (<=0 or greater than the length of buffer minus the value of the offset parameter).
The exception cannot be reproduced manually and is never raised while executing different procedures with different parameters (ie it's random).
Configuration:
ODP.net managed driver version: 4.121.1.0
.net framework 4.5
Oracle server version: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 (Linux)
Has anyone already experienced this issue? Are there any fixes available?
Thanks in advance!
After opening a ticket with the Oracle support, they sent an unofficial updated version of the managed ODP.net library which seems to fix the issue.
Hopefully the fix should be part of the next ODAC release (the latest available today is from Oct 2015).
If you see this error in your application, it's probably due to the same bug in the managed ODP.net library, not the way you use it.
Another thing to consider is if something in the network infrastructure could interrupt idle tcp/ip connections during the execution of long requests as described in this SO answer.
After reading through a similar question at ODP.NET Oracle.ManagedDataAcess random ORA-12570 errors, it seems like it's actually a pooling problem. Apparently the answer is to either set Pooling=false in the Connection String, or to find out just how many threads can be opened and how long the connection can be open before it becomes too much for Oracle to handle. This was the answer the author of that question posted:
To find the best configuration with pooling enabled I created a test application to start 50 threads (each one doing 1 test each 50ms), and decreased the default pool values until the error stoped. This way I was able to get an optimal configuration, stable, without any errors.
Obviously it does not applies to every server, but this is my final connection string configuration:
Pooling=true;Min Pool Size=1;Connection Lifetime=180;Max Pool Size=50;Incr Pool Size=5

protobuf-net transcoder for EnyimMemcached problems

Is the transcoder from protobuf-net to enyim cache deprecated? distributed caching with protobuff-net
Setting my Enyim config just like this app.config causes an error when I try to start the MemcachedClient()
The same for using
transcoder type="ProtoBuf.Caching.Enyim.NetTranscoder"/
System.TypeInitializationException was unhandled by user code
HResult=-2146233036
Message=The type initializer for 'Enyim.Caching.MemcachedClient' threw an exception.
Source=Enyim.Caching
TypeName=Enyim.Caching.MemcachedClient
StackTrace:
at Enyim.Caching.MemcachedClient..ctor()
at Global.asax.cs:line 31
InnerException: System.Configuration.ConfigurationErrorsException
HResult=-2146232062
Message=The value of the property 'transcoder' cannot be parsed. The error is: Object reference not set to an instance of an object. (\web.config line 207)
Source=System.Configuration
BareMessage=The value of the property 'transcoder' cannot be parsed. The error is: Object reference not set to an instance of an object.
StackTrace:
at System.Configuration.BaseConfigurationRecord.EvaluateOne(String[] keys, SectionInput input, Boolean isTrusted, FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentResult)
at System.Configuration.BaseConfigurationRecord.Evaluate(FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentResult, Boolean getLkg, Boolean getRuntimeObject, Object& result, Object& resultRuntimeObject)
at System.Configuration.BaseConfigurationRecord.GetSectionRecursive(String configKey, Boolean getLkg, Boolean checkPermission, Boolean getRuntimeObject, Boolean requestIsHere, Object& result, Object& resultRuntimeObject)
at System.Configuration.BaseConfigurationRecord.GetSection(String configKey)
at System.Web.HttpContext.GetSection(String sectionName)
at System.Web.Configuration.HttpConfigurationSystem.GetSection(String sectionName)
at System.Web.Configuration.HttpConfigurationSystem.System.Configuration.Internal.IInternalConfigSystem.GetSection(String configKey)
at System.Configuration.ConfigurationManager.GetSection(String sectionName)
at Enyim.Caching.MemcachedClient..cctor() in MemcachedClient.cs:line 25
InnerException:
Both installed via nuget and using the latest version available.
Yes (cough), of course that's there! Just see "protobuf-net.Enyim", i.e.
PM> Install-Package protobuf-net.Enyim
(or use the GUI client)
To initialize, you need to configure the transcoder to be an instance of ProtoBuf.Caching.Enyim.NetTranscoder (as per the original instructions). If you are doing this via configuration, note that the assembly for this type is now protobuf-net.Enyim. If I assume the configuration file uses standard notation, then that means you would need to specify (in the config):
<transcoder type="ProtoBuf.Caching.Enyim.NetTranscoder,protobuf-net.Enyim" />
Original answer:
The enyim transcoder is not currently in nuget; however - I will right now take it upon myself to resurrect that, by adding a separate NuGet package (reference EnyimMemcached and protobuf-net) that adds this back in.
Random question... any chance you can point me at a binary memcached download for testing?
One reason this has lagged is that when I first wrote the enyim transcoder, memcached was a simple "run this" - but last time I looked it had gone all "enterprisey", and I couldn't track down a simple package that just had the memcached server. If you can show me where that is now, I'll get it working this weekend.

Ninject.Web.Common throwing ActivationException trying to inject dependencies into HttpApplicationInitializationHttpModule

I'm not sure where to even begin solving this, but I'm getting an exception when trying to run my ASP.NET MVC app.
Here is the error I'm getting:
[ActivationException: Error activating IntPtr
No matching bindings are available, and the type is not self-bindable.
Activation path:
Injection of dependency IntPtr into parameter method of constructor of type Func{IKernel}
Injection of dependency Func{IKernel} into parameter lazyKernel of constructor of type HttpApplicationInitializationHttpModule
Request for IHttpModule
Suggestions:
Ensure that you have defined a binding for IntPtr.
If the binding was defined in a module, ensure that the module has been loaded into the kernel.
Ensure you have not accidentally created more than one kernel.
If you are using constructor arguments, ensure that the parameter name matches the constructors parameter name.
If you are using automatic module loading, ensure the search path and filters are correct.
The stack trace is as follows:
at Ninject.KernelBase.Resolve(IRequest request) in c:\Projects\Ninject\ninject\src\Ninject\KernelBase.cs:line 359
at Ninject.Planning.Targets.Target`1.GetValue(Type service, IContext parent) in c:\Projects\Ninject\ninject\src\Ninject\Planning\Targets\Target.cs:line 197
at Ninject.Planning.Targets.Target`1.ResolveWithin(IContext parent) in c:\Projects\Ninject\ninject\src\Ninject\Planning\Targets\Target.cs:line 165
at Ninject.Activation.Providers.StandardProvider.GetValue(IContext context, ITarget target) in c:\Projects\Ninject\ninject\src\Ninject\Activation\Providers\StandardProvider.cs:line 114
at Ninject.Activation.Providers.StandardProvider.<>c__DisplayClass4.<Create>b__2(ITarget target) in c:\Projects\Ninject\ninject\src\Ninject\Activation\Providers\StandardProvider.cs:line 96
at System.Linq.Enumerable.WhereSelectArrayIterator`2.MoveNext()
at System.Linq.Buffer`1..ctor(IEnumerable`1 source)
at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
at Ninject.Activation.Providers.StandardProvider.Create(IContext context) in c:\Projects\Ninject\ninject\src\Ninject\Activation\Providers\StandardProvider.cs:line 96
at Ninject.Activation.Context.Resolve() in c:\Projects\Ninject\ninject\src\Ninject\Activation\Context.cs:line 157
at Ninject.KernelBase.<>c__DisplayClass10.<Resolve>b__c(IBinding binding) in c:\Projects\Ninject\ninject\src\Ninject\KernelBase.cs:line 386
at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
at System.Linq.Enumerable.SingleOrDefault[TSource](IEnumerable`1 source)
at Ninject.Planning.Targets.Target`1.GetValue(Type service, IContext parent) in c:\Projects\Ninject\ninject\src\Ninject\Planning\Targets\Target.cs:line 197
at Ninject.Planning.Targets.Target`1.ResolveWithin(IContext parent) in c:\Projects\Ninject\ninject\src\Ninject\Planning\Targets\Target.cs:line 165
at Ninject.Activation.Providers.StandardProvider.GetValue(IContext context, ITarget target) in c:\Projects\Ninject\ninject\src\Ninject\Activation\Providers\StandardProvider.cs:line 114
at Ninject.Activation.Providers.StandardProvider.<>c__DisplayClass4.<Create>b__2(ITarget target) in c:\Projects\Ninject\ninject\src\Ninject\Activation\Providers\StandardProvider.cs:line 96
at System.Linq.Enumerable.WhereSelectArrayIterator`2.MoveNext()
at System.Linq.Buffer`1..ctor(IEnumerable`1 source)
at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
at Ninject.Activation.Providers.StandardProvider.Create(IContext context) in c:\Projects\Ninject\ninject\src\Ninject\Activation\Providers\StandardProvider.cs:line 96
at Ninject.Activation.Context.Resolve() in c:\Projects\Ninject\ninject\src\Ninject\Activation\Context.cs:line 157
at Ninject.KernelBase.<>c__DisplayClass10.<Resolve>b__c(IBinding binding) in c:\Projects\Ninject\ninject\src\Ninject\KernelBase.cs:line 386
at System.Linq.Enumerable.WhereSelectListIterator`2.MoveNext()
at System.Linq.Enumerable.<CastIterator>d__b1`1.MoveNext()
at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
at Ninject.Web.Common.NinjectHttpModule.Init(HttpApplication context) in c:\Projects\Ninject\Ninject.Web.Common\src\Ninject.Web.Common\NinjectHttpModule.cs:line 41
at System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers)
at System.Web.HttpApplication.InitSpecial(HttpApplicationState state, MethodInfo[] handlers, IntPtr appContext, HttpContext context)
at System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context)
at System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext)
This doesn't seem to be an error everyone is getting (at least, my Google searches haven't turned up anything usefuL), so I assume I'm doing something odd, but I have no idea where to begin debugging this.
I should mention that I'm using several Ninject libraries (Ninject, Ninject.Web.Common, Ninject.MVC3, and Ninject.FluentValidation), all of which are version 3.0.00-RC3. I realize that all bets are off if I use pre-release libraries, but I have a feeling I'm doing something wrong because others don't seem to be getting the same error.
Any thoughts on what the problem could be or where I should start looking?
You can fix this by adding these two bindings to the kernel:
kernel.Bind<Func<IKernel>>().ToMethod(ctx => () => new Bootstrapper().Kernel);
kernel.Bind<IHttpModule>().To<HttpApplicationInitializationHttpModule>();
I decided to delete my App_Start\NinjectWebCommon.cs file (which was created when I installed Ninject.MVC 3.0.0-rc2) and reinstall the Nuget package (rc3). The newly created NinjectWebCommon.cs file was slightly different. Problem solved!
I faced the same problem with a WebApi project, debuging I noticed that the CreateKernel in App_Start/NinjectWebCommon.cs was called twice, and the second time it crashes, I fixed removing 2 lines at the very top of that file
[assembly: WebActivatorEx.PreApplicationStartMethod(typeof(RetailStore.App_Start.NinjectWebCommon), "Start")]
[assembly: WebActivatorEx.ApplicationShutdownMethodAttribute(typeof(RetailStore.App_Start.NinjectWebCommon), "Stop")]
And then the method was called once and the bug vanished.
I got the exact same error message, even though the code hadn't changed from the night before.
I was working through the example code from http://www.asp.net/web-api/videos/getting-started/authorization
I lost well over an hour over something silly. I had decorated my controller to [Authorize], but the next day when I started work and was testing the api, my session was no longer valid, so I assumed it was something subtle in the code that had changed.
Hope this helps someone else who is as new to Ninject as I am...
What appeared in my browser was:
XML Parsing Error: no element found
Location: server-name/api/Cities/
Line Number 1, Column 1:

Resources