chore: import upstream snapshot with attribution
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
/* ******************************************************************************
|
||||
*
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Apache License, Version 2.0 which is available at
|
||||
* https://www.apache.org/licenses/LICENSE-2.0.
|
||||
*
|
||||
* See the NOTICE file distributed with this work for additional
|
||||
* information regarding copyright ownership.
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
******************************************************************************/
|
||||
|
||||
//
|
||||
// @author raver119@gmail.com
|
||||
//
|
||||
#include <exceptions/allocation_exception.h>
|
||||
#include <helpers/StringUtils.h>
|
||||
|
||||
namespace sd {
|
||||
allocation_exception::allocation_exception(std::string message) : std::runtime_error(message) {
|
||||
//
|
||||
}
|
||||
|
||||
allocation_exception allocation_exception::build(std::string message, LongType numBytes) {
|
||||
auto bytes = StringUtils::valueToString<LongType>(numBytes);
|
||||
message += "; Requested bytes: [" + bytes + "]";
|
||||
return allocation_exception(message);
|
||||
}
|
||||
|
||||
allocation_exception allocation_exception::build(std::string message, LongType limit, LongType numBytes) {
|
||||
auto bytes = StringUtils::valueToString<LongType>(numBytes);
|
||||
auto lim = StringUtils::valueToString<LongType>(limit);
|
||||
message += "; Limit bytes: [" + lim + "]; Requested bytes: [" + bytes + "]";
|
||||
return allocation_exception(message);
|
||||
}
|
||||
} // namespace sd
|
||||
@@ -0,0 +1,71 @@
|
||||
/* ******************************************************************************
|
||||
*
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Apache License, Version 2.0 which is available at
|
||||
* https://www.apache.org/licenses/LICENSE-2.0.
|
||||
*
|
||||
* See the NOTICE file distributed with this work for additional
|
||||
* information regarding copyright ownership.
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
******************************************************************************/
|
||||
|
||||
//
|
||||
// Created by raver on 11/26/2018.
|
||||
//
|
||||
#include <exceptions/cuda_exception.h>
|
||||
#include <helpers/StringUtils.h>
|
||||
#if defined(SD_GCC_FUNCTRACE)
|
||||
#include <exceptions/backward.hpp>
|
||||
using namespace backward;
|
||||
#endif
|
||||
namespace sd {
|
||||
|
||||
#if defined(SD_GCC_FUNCTRACE)
|
||||
cuda_exception::cuda_exception(std::string message) : std::runtime_error(message) {
|
||||
StackTrace st;
|
||||
st.load_here();
|
||||
Printer p;
|
||||
p.object = true;
|
||||
p.color_mode = ColorMode::always;
|
||||
p.address = true;
|
||||
p.print(st, stderr);
|
||||
|
||||
}
|
||||
#else
|
||||
cuda_exception::cuda_exception(std::string message) : std::runtime_error(message) {
|
||||
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#if defined(SD_GCC_FUNCTRACE)
|
||||
|
||||
cuda_exception cuda_exception::build(std::string message, int errorCode) {
|
||||
StackTrace st;
|
||||
st.load_here();
|
||||
Printer p;
|
||||
p.object = true;
|
||||
p.color_mode = ColorMode::always;
|
||||
p.address = true;
|
||||
p.print(st, stderr);
|
||||
auto ec = StringUtils::valueToString<int>(errorCode);
|
||||
message += "; Error code: [" + ec + "]";
|
||||
return cuda_exception(message);
|
||||
}
|
||||
#else
|
||||
cuda_exception cuda_exception::build(std::string message, int errorCode) {
|
||||
auto ec = StringUtils::valueToString<int>(errorCode);
|
||||
message += "; Error code: [" + ec + "]";
|
||||
return cuda_exception(message);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
} // namespace sd
|
||||
@@ -0,0 +1,51 @@
|
||||
/* ******************************************************************************
|
||||
*
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Apache License, Version 2.0 which is available at
|
||||
* https://www.apache.org/licenses/LICENSE-2.0.
|
||||
*
|
||||
* See the NOTICE file distributed with this work for additional
|
||||
* information regarding copyright ownership.
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
******************************************************************************/
|
||||
|
||||
//
|
||||
// Created by raver on 11/26/2018.
|
||||
//
|
||||
#include <array/DataTypeUtils.h>
|
||||
#include <exceptions/datatype_exception.h>
|
||||
|
||||
namespace sd {
|
||||
datatype_exception::datatype_exception(std::string message) : std::runtime_error(message) {
|
||||
//
|
||||
}
|
||||
|
||||
datatype_exception datatype_exception::build(std::string message, DataType expected, DataType actual) {
|
||||
auto exp = DataTypeUtils::asString(expected);
|
||||
auto act = DataTypeUtils::asString(actual);
|
||||
message += "; Expected: [" + exp + "]; Actual: [" + act + "]";
|
||||
return datatype_exception(message);
|
||||
}
|
||||
|
||||
datatype_exception datatype_exception::build(std::string message, DataType expected, DataType actualX,
|
||||
DataType actualY) {
|
||||
auto exp = DataTypeUtils::asString(expected);
|
||||
auto actX = DataTypeUtils::asString(actualX);
|
||||
auto actY = DataTypeUtils::asString(actualY);
|
||||
message += "; Expected: [" + exp + "]; Actual: [" + actX + ", " + actY + "]";
|
||||
return datatype_exception(message);
|
||||
}
|
||||
|
||||
datatype_exception datatype_exception::build(std::string message, DataType actual) {
|
||||
auto act = DataTypeUtils::asString(actual);
|
||||
message += "; Actual: [" + act + "]";
|
||||
return datatype_exception(message);
|
||||
}
|
||||
} // namespace sd
|
||||
@@ -0,0 +1,49 @@
|
||||
/* ******************************************************************************
|
||||
*
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Apache License, Version 2.0 which is available at
|
||||
* https://www.apache.org/licenses/LICENSE-2.0.
|
||||
*
|
||||
* See the NOTICE file distributed with this work for additional
|
||||
* information regarding copyright ownership.
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
******************************************************************************/
|
||||
|
||||
//
|
||||
// Created by raver on 9/1/2018.
|
||||
//
|
||||
#include <exceptions/graph_exception.h>
|
||||
|
||||
namespace sd {
|
||||
graph_exception::graph_exception(std::string message, LongType graphId) : std::runtime_error(message) {
|
||||
this->_message = message;
|
||||
this->_graphId = graphId;
|
||||
}
|
||||
|
||||
graph_exception::graph_exception(std::string message, std::string description, LongType graphId)
|
||||
: std::runtime_error(message) {
|
||||
this->_message = message;
|
||||
this->_description = description;
|
||||
this->_graphId = graphId;
|
||||
}
|
||||
|
||||
graph_exception::graph_exception(std::string message, const char* description, LongType graphId)
|
||||
: std::runtime_error(message) {
|
||||
this->_message = message;
|
||||
this->_description = description;
|
||||
this->_graphId = graphId;
|
||||
}
|
||||
|
||||
LongType graph_exception::graphId() { return _graphId; }
|
||||
|
||||
const char* graph_exception::message() { return _message.c_str(); }
|
||||
|
||||
const char* graph_exception::description() { return _description.c_str(); }
|
||||
} // namespace sd
|
||||
@@ -0,0 +1,31 @@
|
||||
/* ******************************************************************************
|
||||
*
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Apache License, Version 2.0 which is available at
|
||||
* https://www.apache.org/licenses/LICENSE-2.0.
|
||||
*
|
||||
* See the NOTICE file distributed with this work for additional
|
||||
* information regarding copyright ownership.
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
******************************************************************************/
|
||||
|
||||
//
|
||||
// Created by raver on 8/31/2018.
|
||||
//
|
||||
#include <exceptions/graph_execution_exception.h>
|
||||
#include <helpers/StringUtils.h>
|
||||
|
||||
namespace sd {
|
||||
graph_execution_exception::graph_execution_exception(LongType graphId)
|
||||
: graph_exception(StringUtils::buildGraphErrorMessage("Caught exception during graph execution", graphId),
|
||||
graphId) {
|
||||
_graphId = graphId;
|
||||
}
|
||||
} // namespace sd
|
||||
@@ -0,0 +1,30 @@
|
||||
/* ******************************************************************************
|
||||
*
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Apache License, Version 2.0 which is available at
|
||||
* https://www.apache.org/licenses/LICENSE-2.0.
|
||||
*
|
||||
* See the NOTICE file distributed with this work for additional
|
||||
* information regarding copyright ownership.
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
******************************************************************************/
|
||||
|
||||
//
|
||||
// Created by raver on 8/31/2018.
|
||||
//
|
||||
#include <exceptions/graph_exists_exception.h>
|
||||
#include <helpers/StringUtils.h>
|
||||
|
||||
namespace sd {
|
||||
graph_exists_exception::graph_exists_exception(LongType graphId)
|
||||
: graph_exception(StringUtils::buildGraphErrorMessage("Graph with given ID already exists", graphId), graphId) {
|
||||
_graphId = graphId;
|
||||
}
|
||||
} // namespace sd
|
||||
@@ -0,0 +1,30 @@
|
||||
/* ******************************************************************************
|
||||
*
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Apache License, Version 2.0 which is available at
|
||||
* https://www.apache.org/licenses/LICENSE-2.0.
|
||||
*
|
||||
* See the NOTICE file distributed with this work for additional
|
||||
* information regarding copyright ownership.
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
******************************************************************************/
|
||||
|
||||
//
|
||||
// Created by raver on 8/31/2018.
|
||||
//
|
||||
#include <exceptions/no_results_exception.h>
|
||||
#include <helpers/StringUtils.h>
|
||||
|
||||
namespace sd {
|
||||
no_results_exception::no_results_exception(LongType graphId)
|
||||
: graph_exception(StringUtils::buildGraphErrorMessage("Got no results after graph execution", graphId), graphId) {
|
||||
_graphId = graphId;
|
||||
}
|
||||
} // namespace sd
|
||||
@@ -0,0 +1,113 @@
|
||||
//
|
||||
// Created by agibsonccc on 5/11/23.
|
||||
//
|
||||
#include <system/op_boilerplate.h>
|
||||
#include <execution/LaunchContext.h>
|
||||
#include <exceptions/backward.hpp>
|
||||
|
||||
using namespace backward;
|
||||
|
||||
// Helper function to safely check if LaunchContext is initialized
|
||||
// Returns true if it's safe to use LaunchContext, false otherwise
|
||||
static bool isLaunchContextReady() {
|
||||
// During early initialization (e.g., static initializers, before main()),
|
||||
// LaunchContext may not be initialized yet. Attempting to use it can cause
|
||||
// crashes. This function provides a safe check.
|
||||
|
||||
// DON'T try to call LaunchContext::defaultContext() here!
|
||||
// Even calling it can trigger crashes during early initialization.
|
||||
// The safer approach is to just return false during exception handling
|
||||
// and let fprintf write to stderr instead.
|
||||
|
||||
// We can't safely determine if LaunchContext is ready without potentially
|
||||
// triggering the same initialization issues we're trying to avoid.
|
||||
// So we conservatively return false and use fprintf for error reporting.
|
||||
return false;
|
||||
}
|
||||
|
||||
// Safe helper function for setting error context in exception handlers
|
||||
// This should be used in ALL catch blocks in JNI code instead of directly
|
||||
// calling LaunchContext::defaultContext()->errorReference()
|
||||
void safeSetErrorContext(int errorCode, const char* errorMessage) {
|
||||
if (isLaunchContextReady()) {
|
||||
#ifdef __cpp_exceptions
|
||||
try {
|
||||
sd::LaunchContext::defaultContext()->errorReference()->setErrorCode(errorCode);
|
||||
sd::LaunchContext::defaultContext()->errorReference()->setErrorMessage(errorMessage);
|
||||
} catch (...) {
|
||||
// If setting error context fails, just log to stderr
|
||||
// Don't let this cause another exception
|
||||
fprintf(stderr, "Warning: Failed to set error context (code=%d): %s\n", errorCode, errorMessage);
|
||||
}
|
||||
#else
|
||||
// Exceptions disabled - direct call without try/catch
|
||||
sd::LaunchContext::defaultContext()->errorReference()->setErrorCode(errorCode);
|
||||
sd::LaunchContext::defaultContext()->errorReference()->setErrorMessage(errorMessage);
|
||||
#endif
|
||||
} else {
|
||||
// LaunchContext not ready - just log to stderr
|
||||
// This is normal during early JVM initialization
|
||||
fprintf(stderr, "Error (code=%d) during early initialization: %s\n", errorCode, errorMessage);
|
||||
}
|
||||
}
|
||||
|
||||
#if defined(SD_GCC_FUNCTRACE)
|
||||
void throwException(const char* exceptionMessage) {
|
||||
#ifndef __CUDA_CC__
|
||||
// Diagnostic: verify this code path executes
|
||||
fprintf(stderr, "\n[throwException] SD_GCC_FUNCTRACE build - capturing stack trace\n");
|
||||
fflush(stderr);
|
||||
|
||||
// Print exception message first
|
||||
fprintf(stderr, "=== EXCEPTION: %s ===\n", exceptionMessage);
|
||||
fflush(stderr);
|
||||
|
||||
// Capture and print stack trace
|
||||
StackTrace st;
|
||||
st.load_here(64);
|
||||
|
||||
if (st.size() > 0) {
|
||||
fprintf(stderr, "Stack trace (%zu frames):\n", st.size());
|
||||
fflush(stderr);
|
||||
Printer p;
|
||||
p.snippet = false;
|
||||
p.color_mode = ColorMode::never;
|
||||
p.address = true;
|
||||
p.object = true;
|
||||
p.print(st, stderr);
|
||||
fflush(stderr);
|
||||
} else {
|
||||
fprintf(stderr, "Stack trace: Unable to capture (0 frames captured)\n");
|
||||
fprintf(stderr, "This may indicate missing unwind tables or debug info\n");
|
||||
fflush(stderr);
|
||||
}
|
||||
fprintf(stderr, "=== END STACK TRACE ===\n\n");
|
||||
fflush(stderr);
|
||||
#endif
|
||||
|
||||
// Set error context for Java to retrieve using safe wrapper
|
||||
// CRITICAL: Don't directly call LaunchContext during exception handling
|
||||
// to avoid static initialization/destruction order issues
|
||||
safeSetErrorContext(1, exceptionMessage);
|
||||
|
||||
#ifdef __cpp_exceptions
|
||||
throw std::runtime_error(exceptionMessage);
|
||||
#endif
|
||||
}
|
||||
#else
|
||||
void throwException(const char* exceptionMessage) {
|
||||
// Diagnostic: verify this code path executes
|
||||
fprintf(stderr, "\n[throwException] Non-functrace build - no stack trace available\n");
|
||||
fprintf(stderr, "Exception: %s\n", exceptionMessage);
|
||||
fflush(stderr);
|
||||
|
||||
// Set error context for Java to retrieve using safe wrapper
|
||||
// CRITICAL: Don't directly call LaunchContext during exception handling
|
||||
// to avoid static initialization/destruction order issues
|
||||
safeSetErrorContext(1, exceptionMessage);
|
||||
|
||||
#ifdef __cpp_exceptions
|
||||
throw std::runtime_error(exceptionMessage);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,30 @@
|
||||
/* ******************************************************************************
|
||||
*
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Apache License, Version 2.0 which is available at
|
||||
* https://www.apache.org/licenses/LICENSE-2.0.
|
||||
*
|
||||
* See the NOTICE file distributed with this work for additional
|
||||
* information regarding copyright ownership.
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
******************************************************************************/
|
||||
|
||||
//
|
||||
// Created by raver on 8/31/2018.
|
||||
//
|
||||
#include <exceptions/unknown_graph_exception.h>
|
||||
#include <helpers/StringUtils.h>
|
||||
|
||||
namespace sd {
|
||||
unknown_graph_exception::unknown_graph_exception(LongType graphId)
|
||||
: graph_exception(StringUtils::buildGraphErrorMessage("Unknown graph", graphId), graphId) {
|
||||
_graphId = graphId;
|
||||
}
|
||||
} // namespace sd
|
||||
Reference in New Issue
Block a user