mirror of
https://github.com/tig-pool-nk/tig-monorepo.git
synced 2026-03-05 18:57:21 +08:00
50 lines
1.5 KiB
Rust
50 lines
1.5 KiB
Rust
use anyhow::{anyhow, Result};
|
|
use serde_json::{Map, Value};
|
|
use std::panic::{catch_unwind, AssertUnwindSafe};
|
|
use tig_algorithms::{CHALLENGE}::{ALGORITHM};
|
|
use tig_challenges::{CHALLENGE}::*;
|
|
|
|
#[cfg(feature = "cuda")]
|
|
use cudarc::{
|
|
driver::{CudaModule, CudaStream},
|
|
runtime::sys::cudaDeviceProp,
|
|
};
|
|
#[cfg(feature = "cuda")]
|
|
use std::sync::Arc;
|
|
|
|
|
|
#[cfg(not(feature = "cuda"))]
|
|
#[unsafe(no_mangle)]
|
|
pub fn entry_point(
|
|
challenge: &Challenge,
|
|
save_solution: &dyn Fn(&Solution) -> Result<()>,
|
|
hyperparameters: Option<String>,
|
|
) -> Result<()>
|
|
{
|
|
catch_unwind(AssertUnwindSafe(|| {
|
|
let hyperparameters = hyperparameters.map(|x| serde_json::from_str::<Map<String, Value>>(&x).unwrap());
|
|
{ALGORITHM}::solve_challenge(challenge, save_solution, &hyperparameters)
|
|
})).unwrap_or_else(|_| {
|
|
Err(anyhow!("Panic occurred calling solve_challenge"))
|
|
})
|
|
}
|
|
|
|
|
|
#[cfg(feature = "cuda")]
|
|
#[unsafe(no_mangle)]
|
|
pub fn entry_point(
|
|
challenge: &Challenge,
|
|
save_solution: &dyn Fn(&Solution) -> Result<()>,
|
|
hyperparameters: Option<String>,
|
|
module: Arc<CudaModule>,
|
|
stream: Arc<CudaStream>,
|
|
prop: &cudaDeviceProp,
|
|
) -> Result<()>
|
|
{
|
|
catch_unwind(AssertUnwindSafe(|| {
|
|
let hyperparameters = hyperparameters.map(|x| serde_json::from_str::<Map<String, Value>>(&x).unwrap());
|
|
{ALGORITHM}::solve_challenge(challenge, save_solution, &hyperparameters, module, stream, prop)
|
|
})).unwrap_or_else(|_| {
|
|
Err(anyhow!("Panic occurred calling solve_challenge"))
|
|
})
|
|
} |