void Context::Init(int device_id) { device_id_ = device_id; SwitchDevice(); #if defined(USE_CUDA) if (blas_handle_ == nullptr) { CUBLAS_CHECK(cublasCreate((cublasHandle_t*)&blas_handle_)); CHECK_NOTNULL(blas_handle_); } #endif #if defined(USE_CUDNN) if (cudnn_handle_ == nullptr) { CUDNN_CHECK(cudnnCreate((cudnnHandle_t*)&cudnn_handle_)); CHECK_NOTNULL(cudnn_handle_); } #endif #if defined(USE_NNPACK) if (nnpack_handle_ == nullptr) { CHECK_EQ(nnp_initialize(), nnp_status_success); nnpack_handle_ = pthreadpool_create(0); CHECK_NOTNULL(nnpack_handle_); } #endif }
virtual void ActorDestroy(ActorDestroyReason aWhy) override { // NB: you *must* unconditionally unregister your observer here, // if it *may* be registered below. hal::UnregisterBatteryObserver(this); hal::UnregisterNetworkObserver(this); hal::UnregisterScreenConfigurationObserver(this); for (int32_t sensor = SENSOR_UNKNOWN + 1; sensor < NUM_SENSOR_TYPE; ++sensor) { hal::UnregisterSensorObserver(SensorType(sensor), this); } hal::UnregisterWakeLockObserver(this); for (int32_t switchDevice = SWITCH_DEVICE_UNKNOWN + 1; switchDevice < NUM_SWITCH_DEVICE; ++switchDevice) { hal::UnregisterSwitchObserver(SwitchDevice(switchDevice), this); } }