Add hypergraph templates to tig-algorithms.

This commit is contained in:
FiveMovesAhead 2025-05-06 21:26:32 +01:00
parent e306f8f97e
commit c4ed10deed
6 changed files with 2136 additions and 3 deletions

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,45 @@
/*!
Copyright [year copyright work created] [name of copyright owner]
Identity of Submitter [name of person or entity that submits the Work to TIG]
UAI [UAI (if applicable)]
Licensed under the TIG Inbound Game License v2.0 or (at your option) any later
version (the "License"); you may not use this file except in compliance with the
License. You may obtain a copy of the License at
https://github.com/tig-foundation/tig-monorepo/tree/main/docs/licenses
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.
*/
// REMOVE BELOW SECTION IF UNUSED
/*
REFERENCES AND ACKNOWLEDGMENTS
This implementation is based on or inspired by existing work. Citations and
acknowledgments below:
1. Academic Papers:
- [Author(s), "Paper Title", DOI (if available)]
2. Code References:
- [Author(s), URL]
3. Other:
- [Author(s), Details]
*/
// License must be the same as the rust code
// You can import any libraries available in nvidia/cuda:12.6.3-cudnn-devel-ubuntu24.04
#include <curand_kernel.h>
#include <stdint.h>
#include <math.h>
#include <float.h>
// Any functions available in the <challenge>.cu file will be available here

View File

@ -0,0 +1,79 @@
/*!
Copyright [year copyright work created] [name of copyright owner]
Identity of Submitter [name of person or entity that submits the Work to TIG]
UAI [UAI (if applicable)]
Licensed under the TIG Inbound Game License v2.0 or (at your option) any later
version (the "License"); you may not use this file except in compliance with the
License. You may obtain a copy of the License at
https://github.com/tig-foundation/tig-monorepo/tree/main/docs/licenses
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.
*/
// REMOVE BELOW SECTION IF UNUSED
/*
REFERENCES AND ACKNOWLEDGMENTS
This implementation is based on or inspired by existing work. Citations and
acknowledgments below:
1. Academic Papers:
- [Author(s), "Paper Title", DOI (if available)]
2. Code References:
- [Author(s), URL]
3. Other:
- [Author(s), Details]
*/
// TIG's UI uses the pattern `tig_challenges::<challenge_name>` to automatically detect your algorithm's challenge
use anyhow::{anyhow, Result};
use cudarc::{
driver::{safe::LaunchConfig, CudaModule, CudaStream, PushKernelArg},
runtime::sys::cudaDeviceProp,
};
use std::sync::Arc;
use tig_challenges::hypergraph::*;
pub fn solve_challenge(
challenge: &Challenge,
module: Arc<CudaModule>,
stream: Arc<CudaStream>,
prop: &cudaDeviceProp,
) -> anyhow::Result<Option<Solution>> {
// Boiler plate for looping through and solving sub-instances
// You can modify this function if you want
let mut solution = Solution {
sub_solutions: Vec::new(),
};
for sub_instance in &challenge.sub_instances {
match solve_sub_instance(sub_instance, module.clone(), stream.clone(), prop)? {
Some(sub_solution) => solution.sub_solutions.push(sub_solution),
None => return Ok(None),
}
}
Ok(Some(solution))
}
pub fn solve_sub_instance(
instance: &SubInstance,
module: Arc<CudaModule>,
stream: Arc<CudaStream>,
prop: &cudaDeviceProp,
) -> anyhow::Result<Option<SubSolution>> {
// return Err(<msg>) if your algorithm encounters an error
// return Ok(None) if your algorithm finds no solution or needs to exit early
// return Ok(SubSolution { .. }) if your algorithm finds a solution
Err(anyhow!("Not implemented"))
}
// Important! Do not include any tests in this file, it will result in your submission being rejected

View File

@ -71,7 +71,7 @@ pub struct SubInstance {
pub const NUM_SUB_INSTANCES: usize = 16;
impl Challenge {
pub fn generate_instance(seed: [u8; 32], difficulty: &Difficulty) -> Result<Challenge> {
pub fn generate_instance(seed: &[u8; 32], difficulty: &Difficulty) -> Result<Challenge> {
let mut rng = StdRng::from_seed(seed.clone());
let mut sub_instances = Vec::new();
for _ in 0..NUM_SUB_INSTANCES {

View File

@ -231,7 +231,13 @@ pub fn compute_solution(
}
}};
}
dispatch_challenges!((c001, cpu), (c002, cpu), (c003, cpu), (c004, gpu));
dispatch_challenges!(
(c001, cpu),
(c002, cpu),
(c003, cpu),
(c004, gpu),
(c005, gpu)
);
fuel_consumed += max_fuel - unsafe { **library.get::<*const u64>(b"__fuel_remaining")? };
if fuel_consumed > max_fuel {

View File

@ -163,7 +163,13 @@ pub fn verify_solution(
}};
}
dispatch_challenges!((c001, cpu), (c002, cpu), (c003, cpu), (c004, gpu));
dispatch_challenges!(
(c001, cpu),
(c002, cpu),
(c003, cpu),
(c004, gpu),
(c005, gpu)
);
if let Some(err_msg) = err_msg {
eprintln!("Verification error: {}", err_msg);